diff --git a/lua/autocmd.lua b/lua/autocmd.lua index 802b83f..fd250a4 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -27,8 +27,12 @@ vim.api.nvim_create_autocmd('TextYankPost', { vim.api.nvim_create_user_command('CDToGitRoot', function() local handle = io.popen 'git rev-parse --show-toplevel 2>/dev/null' - local git_root = handle:read('*a'):gsub('\n', '') - handle:close() + local git_root + + if handle then + git_root = handle:read('*a'):gsub('\n', '') + handle:close() + end if git_root == '' then print 'Not in a Git repository'