nerdtree

A tree explorer plugin for vim.
Index Commits Files Refs
commit 4d77c3ae45501ede4d2df63056fd6d158058f693
parent a7f9abe8276e6138e1e7056635030a15a1d600fc
Author: Martin Grenfell <martin_grenfell@msn.com>
Date:   Mon, 20 Jul 2009 01:05:21 +1200

add basic git plugin

Diffstat:
Aftplugin/nerdtree_git_menu.vim | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+), 0 deletions(-)
diff --git a/ftplugin/nerdtree_git_menu.vim 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 <martin_grenfell at msn dot com>
+" 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