dhruvasagar / vim-prosession

Handle vim sessions like a pro
254 stars 22 forks source link

Enable only in git repositories? #80

Closed cd-a closed 3 years ago

cd-a commented 3 years ago

Is there a way to have this only be enabled when I'm in a git repository?

We already have g:prosession_ignore_dirs but this is for directories.

But usually I don't want to have sessions in random locations around the filesystem, only in git folders where there's lots of work to be done.

dhruvasagar commented 3 years ago

@dahmc I've added a new configuration g:Prosession_ignore_expr to allow more control over directories to be ignored. I hope this should help you with this.

This is a Funcref that must return a boolean value, either v:true or v:false, upon invocation to determine if a directory should be ignored by prosession.

let g:Prosession_ignore_expr = {->v:false}

This could be used to ignore directories by using some specific criteria. Following is an example to ignore all directories that are not git repos.

let g:Prosession_ignore_expr = {-> !isdirectory('.git')}
cd-a commented 3 years ago

@dhruvasagar damn, that was quick. Thank you so much!

It works like a charm for git repos.

I did this to have it work with monorepos as well, where I only work in a subfolder:

let g:prosession_ignore_expr = [
                              \ {-> !isdirectory('.git')},
                              \ {-> !isdirectory('../.git')},
                              \]

Thanks again!

dhruvasagar commented 3 years ago

@dahmc That won't work. You should use this instead :

let g:Prosession_ignore_expr = {-> !(isdirectory('.git') || isdirectory('../.git'))}

Also NOTE, this new configuration g:Prosession_ignore_expr starts with a capital letter as opposed to others, that's because viml requires funcref to be capitalized.

cd-a commented 3 years ago

@dhruvasagar haha ok, I really thought that worked, but I use yours now (plus a trailing closing bracket at the end).

Thanks!