From 5fd59cd446ccd170fd6051b98aede488f69dae73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 9 Apr 2024 13:50:09 +0200 Subject: nvim/telescope: fix open with nonexistent or no file --- config/nvim/lua/mytelescopefiles.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'config/nvim/lua/mytelescopefiles.lua') diff --git a/config/nvim/lua/mytelescopefiles.lua b/config/nvim/lua/mytelescopefiles.lua index 733a1d8..2a98505 100644 --- a/config/nvim/lua/mytelescopefiles.lua +++ b/config/nvim/lua/mytelescopefiles.lua @@ -2,10 +2,15 @@ local ts = require("telescope.builtin") local utils = require("telescope.utils") return function() - local root, ret = utils.get_os_command_output({ "git", "rev-parse", "--show-toplevel" }, vim.fn.expand("%:h")) + local dir = vim.fn.expand("%:h") + if dir == "" or not vim.fn.exists(dir) then + dir = vim.fn.getcwd() + end + local root, ret = utils.get_os_command_output({ "git", "rev-parse", "--show-toplevel" }, dir) + root = root[1] if ret == 0 then ts.git_files({ - cwd = root[1], + cwd = root, git_command = { "sh", "-c", -- cgit v1.2.3