From e7ba7e5a7b92ccb61d1e80c6aa80f55bc0a53611 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 22 Aug 2022 02:23:52 +0200 Subject: [PATCH] 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 --- .config/nvim/lua/my/functions.lua | 5 +++-- .config/nvim/lua/my/tools.lua | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.config/nvim/lua/my/functions.lua b/.config/nvim/lua/my/functions.lua index 461bb1a..be35e62 100644 --- a/.config/nvim/lua/my/functions.lua +++ b/.config/nvim/lua/my/functions.lua @@ -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 diff --git a/.config/nvim/lua/my/tools.lua b/.config/nvim/lua/my/tools.lua index e6bde44..c22d39d 100644 --- a/.config/nvim/lua/my/tools.lua +++ b/.config/nvim/lua/my/tools.lua @@ -23,7 +23,8 @@ local t_builtin = require('telescope.builtin') local my = require('my.functions') map('n', 'tb', t_builtin.buffers, 'Buffers') map('n', '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', 'tF', t_builtin.find_files, 'Files in cw') map('n', 'to', t_builtin.oldfiles, 'Recently opened files')