mirror of
https://github.com/preservim/nerdtree.git
synced 2025-03-03 12:59:57 +08:00
make the git menu own harder
This commit is contained in:
parent
e9d6a7209c
commit
a163f327eb
@ -10,12 +10,30 @@
|
||||
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
"
|
||||
" ============================================================================
|
||||
"
|
||||
" Adds a "g" submenu to the NERD tree menu.
|
||||
"
|
||||
" Note: this plugin assumes that the current tree root has a .git dir under
|
||||
" it, and that the working tree and the .git repo are in the same place
|
||||
"
|
||||
if exists("g:loaded_nerdtree_git_menu")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_nerdtree_git_menu = 1
|
||||
|
||||
call NERDTreeAddMenuItem('(g)it menu', 'g', 'NERDTreeGitMenu')
|
||||
call NERDTreeAddMenuItem({
|
||||
\ 'text': '(g)it menu',
|
||||
\ 'shortcut': 'g',
|
||||
\ 'check_to_enable_callback': 'NERDTreeGitMenuEnabled',
|
||||
\ 'callback': 'NERDTreeGitMenu' })
|
||||
|
||||
function! NERDTreeGitMenuEnabled()
|
||||
return isdirectory(s:GitRepoPath())
|
||||
endfunction
|
||||
|
||||
function! s:GitRepoPath()
|
||||
return b:NERDTreeRoot.path.str(0) . ".git"
|
||||
endfunction
|
||||
|
||||
function! NERDTreeGitMenu()
|
||||
let node = g:NERDTreeFileNode.GetSelected()
|
||||
@ -36,26 +54,34 @@ function! NERDTreeGitMenu()
|
||||
let choice = nr2char(getchar())
|
||||
|
||||
if choice ==# "a"
|
||||
call s:promptCommand('git add ', path.strForOS(1), 'file')
|
||||
call s:promptCommand('add ', path.strForOS(1), 'file')
|
||||
elseif choice ==# "c"
|
||||
call s:promptCommand('git checkout ', path.strForOS(1), 'file')
|
||||
call s:promptCommand('checkout ', path.strForOS(1), 'file')
|
||||
elseif choice ==# "m"
|
||||
call s:promptCommand('git mv ', path.strForOS(1), 'file')
|
||||
let p = path.strForOS(1)
|
||||
call s:promptCommand('mv ', p . ' ' . p, 'file')
|
||||
elseif choice ==# "r"
|
||||
call s:promptCommand('git rm ', path.strForOS(1), 'file')
|
||||
call s:promptCommand('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)
|
||||
function! s:promptCommand(sub_command, cmd_tail_default, complete)
|
||||
let extra_options = ' --git-dir=' . s:GitRepoPath()
|
||||
let extra_options .= ' --work-tree=' . b:NERDTreeRoot.path.str(0) . ' '
|
||||
let base = "git" . extra_options . a:sub_command
|
||||
|
||||
let cmd_tail = input(":!" . base, a:cmd_tail_default, a:complete)
|
||||
if cmd_tail != ''
|
||||
let output = system(a:cmd_base . cmd_tail)
|
||||
let output = system(base . cmd_tail)
|
||||
redraw!
|
||||
if v:shell_error != 0
|
||||
echom output
|
||||
echo output
|
||||
endif
|
||||
else
|
||||
redraw
|
||||
echo "Aborted"
|
||||
endif
|
||||
endfunction
|
||||
|
Loading…
x
Reference in New Issue
Block a user