CD to git root user cmd

This commit is contained in:
Imbus 2024-11-10 23:53:36 +01:00
parent 41ddadca83
commit 3555e9dc0a

View file

@ -25,4 +25,17 @@ vim.api.nvim_create_autocmd('TextYankPost', {
end, end,
}) })
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()
if git_root == '' then
print 'Not in a Git repository'
else
vim.cmd('cd ' .. git_root)
print('Changed directory to Git root: ' .. git_root)
end
end, { desc = 'Change directory to the current Git repository root' })
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et