nvim: improve cwd handling
- remove .clang-format as root marker because it is in ${HOME} - don't return ${HOME} as project root in get_project_root() - fall back to current dir in telescope find_files
This commit is contained in:
parent
18ee6bedc0
commit
e7ba7e5a7b
|
@ -67,7 +67,7 @@ vim.api.nvim_create_user_command('ModelineInsert', M.insert_modeline, {})
|
|||
-- Files that could indicate the project's root directory
|
||||
M.project_root_markers = {
|
||||
'.git', '.hg', '.svn', '.bzr', '_darcs',
|
||||
'.projectile', '.clang-format', '.luarc.json', '.editorconfig'
|
||||
'.projectile', '.luarc.json', '.editorconfig'
|
||||
}
|
||||
|
||||
function M.get_project_root()
|
||||
|
@ -77,11 +77,12 @@ function M.get_project_root()
|
|||
repeat
|
||||
path = path:gsub(string.format('%s[^%s]*$', sep, sep), '')
|
||||
for _, marker in ipairs(M.project_root_markers) do
|
||||
if io.open(path .. sep .. marker) then
|
||||
if path ~= os.getenv('HOME') and io.open(path .. sep .. marker) then
|
||||
return path
|
||||
end
|
||||
end
|
||||
until path == ''
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ local t_builtin = require('telescope.builtin')
|
|||
local my = require('my.functions')
|
||||
map('n', '<Leader>tb', t_builtin.buffers, 'Buffers')
|
||||
map('n', '<Leader>tf', function()
|
||||
t_builtin.find_files({ cwd = my.get_project_root() })
|
||||
t_builtin.find_files({ cwd = my.get_project_root() or
|
||||
vim.fn.expand("%:p:h", true) }) -- fall back to current dir
|
||||
end, 'Files')
|
||||
map('n', '<Leader>tF', t_builtin.find_files, 'Files in cw')
|
||||
map('n', '<Leader>to', t_builtin.oldfiles, 'Recently opened files')
|
||||
|
|
Loading…
Reference in New Issue
Block a user