Closed olimorris closed 2 years ago
Git branching
Enabling of an option called
use_git_branch
to enable session files to be created for the cwd and the current git branch. The main change has been the addition of a function calledget_branch()
which determines the current one. I opted to run a vim command for this as it is cleaner than some of the pure lua alternatives I saw.If enabled, then session files will be saved like:
%Users%Oli%Code%Projects%persistence_feature%add-git-branch-to-session.vim
where
_feature%add-git-branch-to-session
is the branchfeature\add-git-branch-to-session
.If
use_git_branch
is enabled and the cwd is not a git enabled repo, then_HEAD.vim
is appended to the session filename. I detect this by looking for a.git
folder within the cwd.
I want to ask a question. Is this change enable us to have different vim session for different git branch?
I want to ask a question. Is this change enable us to have different vim session for different git branch?
Yes. Exactly that.
@folke - what are you thoughts on merging this into main
?
When merging the prior updates from the base branch, the git branching functionality got chopped. Horrific miss on my part.
Did this get merged elsewhere or did this never land? Branch-based sessions would be a welcome addition.
I don't believe so. I ended up forking this repo and making my own session plugin instead.
Firstly, thank you for writing such a beautifully simple Lua based session management plugin. I had previously used Vim-Obsession coupled with Vim-Prosession. Your plugin did nearly everything I needed it to do.
My workflow
Before I explain this pull request I'd like to explain how I work and hence why I made the changes.
I often work across two projects at any one time. However, within those projects are many git branches that I switch between. We implement git-flow rather religiously so I may be viewing the develop branch and then switching to a hotfix or a brand new feature. As such, it's really handy to quickly switch branch on the command line and recover exactly where I was last time from within Neovim.
Lastly, I like to know if Persistence is running or not. So I display a small glyph in my statusline to indicate its status. That way I know whether I need to initiate or stop it.
The proposed changes
Git branching
Enabling of an option called
use_git_branch
to enable session files to be created for the cwd and the current git branch. The main change has been the addition of a function calledget_branch()
which determines the current branch. I opted to run a vim command for this as it is cleaner than some of the pure Lua alternatives I saw.If enabled, then session files will be saved like:
where
_feature%add-git-branch-to-session
is the branchfeature\add-git-branch-to-session
.If
use_git_branch
is enabled and the cwd is not a git enabled repo, then_HEAD.vim
is appended to the session filename. I detect this by looking for a.git
folder within the cwd.Determine if Persistence is running
I added a global variable
using_persistence
to thestart
,save
,load
, andstop
commands. If active thentrue
is returned. If Persistence has been stopped then afalse
is returned. This makes it easy to check for Persistence's status using avim.g.using_persistence
command from within my statusline config.It allows me to have a really useful helper function in my dotfiles for loading/starting/stopping sessions:
Summary
Hopefully some simple changes that don't change the beautiful simplicity of this plugin. I also hope they're useful features for the rest of the community. I feel other session plugins are far too bloated, complicated and still lacking the features I need.