Sync worktrees with vim session files
My usual work flow consist of several repo clones and one neovim session in each. To mimick this and allow for switching between work tasks more seamlessly it would be interesting to save and load vim sessions when switching worktrees.
That is to keep:
-
worktree:feature/<some set of buffers> -
worktree:review/<some other set of buffers>
For a "review" it is not as interesting to keep a memory for opened buffers, but for the "feature" worktree there is - to be able to quickly go back to the previous working position.
I have not forgot about you! Still getting all the other bugs kinked out.
I have a solution with auto-session. It has compromises and feels hacky. Maybe I'll make a PR to git-worktree to generalize some behavior. But this works for now.
In the setup for git-worktree, make sure you set update_on_change to false. You could also set clear_jumps_on_change to false since auto-session can handle that. In the on_tree_change callback for Worktree.Operations.Switch, you must call RestoreSession. If you use nvim-tree, you probably want to set sync_root_with_cwd to true.
The compromises with this approach are:
- update_on_change is set to false, yet we are still performing some update. Ideally we could configure some update function instead of hacking the callback.
- Worktrees without a previously saved session aren't handled elegantly. In my opinion this is outside the scope of git-worktree. But it is worth noting.
My config files: - https://github.com/KirkEasterson/.dotfiles/blob/d888ed997e1a9696500fa2d98e3d1fe56f8f942a/.config/nvim/lua/kirk/git/git-worktree.lua - https://github.com/KirkEasterson/.dotfiles/blob/d888ed997e1a9696500fa2d98e3d1fe56f8f942a/.config/nvim/lua/kirk/auto_session.lua
ok, i did forget about this. I haven't been keeping up with this one :(
i just... you know... its hard maintaining these things. If I can try to muster the courage i'll get to this shortly.
ok, i did forget about this. I haven't been keeping up with this one :(
i just... you know... its hard maintaining these things. If I can try to muster the courage i'll get to this shortly.
It's okay prime. Because of this, you've inspired me to make my first PR to a neovim plugin!