[mini.pick] git worktree picker #1131
                  
                    
                      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
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
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
DirChangedPreevent andmini.sessionsto save my current session and load the session to the new working dir (usingoil.nvimas a fallback in case I don't have a previous session).Usage:
The picker accepts an optional
cwdparameter in case you want to search a repository in another path.:Pick git_worktreesorPick 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 worktreesusinggit -C $cwd worktree listand then the cli stdout is parsed usingstring.matchto build a table array that has three fields:text,branchandpath(you can customize the prompt by changing the content oftext). So, when the user select an item thewt_switchprocedure is called, changing the working dir toitem.path.Code:
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions