I use MacVim, I use mksession
, so I know I can create a my_session.vim
file and later I can load the session with :load my_session.vim
, but I don't like to save/load sessions, I just want to open my modified files in git repos.
Make it executable
chmod +x /path/to/git-edit.sh
Add it to your ~/.bashrc
echo ". /path/to/git-edit.sh" >> ~/.bashrc
Add an alias to your ~/.gitconfig
[alias]
edit = !bash -ic 'git_edit_files \"$@\"' -
or to path/to/your/project/.git/config
cd path/to/your/project
git config alias.edit '!bash -ic '\''git_edit_files "$@"'\'' -'
and last but not least, and just to make it even easier, let's add some alias to your ~/.bashrc
or ~/.bash_profile
:
alias gedm='git edit --modified'
alias gedc='git edit --cached'
alias gedu='git edit --untracked'
Every file will be opened in its own MacVim window and split horizontally, and NERDTree will be opened too, so once the script and aliases are all setup:
$ git edit # open modified files
$ git edit -m # open modified files
$ git edit -c # open cached/staged files, those you have "git add'ed"
$ git edit -u # open untracked files
with bash aliases:
$ gedm # open modified files
$ gedc # open cached/staged files, those you have "git add'ed"
$ gedu # open untracked files
The script doesn't gives you too much flexibility on the options we pass to MacVim, so you'll have to customize the script if you want to open the files in its own tab or with vertical splitting, you can do it in git-edit.sh#46
:
mvim -o $files -c 'NERDTree' > /dev/null 2>&1
To open in tabs:
mvim -p ...
To open in windows but split vertically:
mvim -O ...
If you don't want NERDTree, get rid of it by removing:
-c 'NERDTree'