CD to git root user cmd
This commit is contained in:
parent
41ddadca83
commit
3555e9dc0a
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue