Skip to content

Instantly share code, notes, and snippets.

@jchnkl
Created April 5, 2014 19:41
Show Gist options
  • Select an option

  • Save jchnkl/9997072 to your computer and use it in GitHub Desktop.

Select an option

Save jchnkl/9997072 to your computer and use it in GitHub Desktop.
" requires python-vim and GitPython
" (Arch: python2-vim && python2-gitpython
" https://chris-lamb.co.uk/posts/committing-every-time-you-save-vim
function! AutoCommit()
python << PYEOF
import vim, git
def python_input(message='', default=''):
vim.command('call inputsave()')
vim.command("let user_input = input('" + message + "', '" + default + "')")
vim.command('call inputrestore()')
return vim.eval('user_input')
auto_branch = 'wip'
curfile = vim.current.buffer.name
if curfile:
try:
repo = git.Repo(curfile)
relfile = curfile.replace(repo.working_dir + '/', '')
if str(repo.active_branch) == auto_branch:
repo.git.add(curfile)
msg = python_input('Commit message? ', 'AUTO: ' + relfile)
repo.git.commit(m=msg)
except:
pass
PYEOF
endfunction
autocmd BufWritePost * call AutoCommit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment