From 4d77c3ae45501ede4d2df63056fd6d158058f693 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Mon, 20 Jul 2009 01:05:21 +1200 Subject: [PATCH] add basic git plugin --- ftplugin/nerdtree_git_menu.vim | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ftplugin/nerdtree_git_menu.vim diff --git a/ftplugin/nerdtree_git_menu.vim b/ftplugin/nerdtree_git_menu.vim new file mode 100644 index 0000000..ed354d9 --- /dev/null +++ b/ftplugin/nerdtree_git_menu.vim @@ -0,0 +1,61 @@ +" ============================================================================ +" File: nerdtree_git_menu.vim +" Description: plugin for the NERD Tree that provides a git menu +" Maintainer: Martin Grenfell +" Last Change: 20 July, 2009 +" License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +" ============================================================================ +if exists("g:loaded_nerdtree_git_menu") + finish +endif +let g:loaded_nerdtree_git_menu = 1 + +call NERDTreeAddMenuItem('(g)it menu', 'g', 'NERDTreeGitMenu') + +function! NERDTreeGitMenu() + let node = g:NERDTreeFileNode.GetSelected() + + let path = node.path + let parent = path.getParent() + + let prompt = "NERDTree Git Menu\n" . + \ "==========================================================\n". + \ "Select the desired operation: \n" . + \ " (a) - git add\n". + \ " (c) - git checkout\n". + \ " (m) - git mv\n". + \ " (r) - git rm\n" + + echo prompt + + let choice = nr2char(getchar()) + + if choice ==# "a" + call s:promptCommand('git add ', path.strForOS(1), 'file') + elseif choice ==# "c" + call s:promptCommand('git checkout ', path.strForOS(1), 'file') + elseif choice ==# "m" + call s:promptCommand('git mv ', path.strForOS(1), 'file') + elseif choice ==# "r" + call s:promptCommand('git rm ', path.strForOS(1), 'file') + endif + + call node.parent.refresh() + call NERDTreeRender() +endfunction + +function! s:promptCommand(cmd_base, cmd_tail_default, complete) + let cmd_tail = input(":!" . a:cmd_base, a:cmd_tail_default, a:complete) + if cmd_tail != '' + let output = system(a:cmd_base . cmd_tail) + redraw! + if v:shell_error != 0 + echom output + endif + endif +endfunction