[mini.pick] git worktree picker #1131
Closed
felpafel
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
Thanks for sharing! I've wanted to try to learn more about Git worktrees for quite a while in order to incorporate them into my workflow. Yet, never really got to it :( I like the usage of |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
git_worktrees.mp4
Hello, I've created this picker around 3 months ago, and decided to share it here.
This picker list all available worktrees and change neovim working directory (
cwd
) to the selected tree. screenshotI choose to only change the directory so it's simple to anyone to implement their own automation. In my case, I use
DirChangedPre
event andmini.sessions
to save my current session and load the session to the new working dir (usingoil.nvim
as a fallback in case I don't have a previous session).Usage:
The picker accepts an optional
cwd
parameter in case you want to search a repository in another path.:Pick git_worktrees
orPick git_worktrees cwd='my/git/repo/path'
;vim.keymap.set('n', '<leader>fw', '<cmd>Pick git_worktrees<cr>')
Implementation:
Basically, this picker queries all available
git worktrees
usinggit -C $cwd worktree list
and then the cli stdout is parsed usingstring.match
to build a table array that has three fields:text
,branch
andpath
(you can customize the prompt by changing the content oftext
). So, when the user select an item thewt_switch
procedure is called, changing the working dir toitem.path
.Code:
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions