Improve vim git commands
This commit is contained in:
parent
a08f4a7ceb
commit
e8c3537aba
1 changed files with 5 additions and 5 deletions
10
git.vim
10
git.vim
|
@ -18,19 +18,19 @@ function! s:gitroot()
|
||||||
endf
|
endf
|
||||||
|
|
||||||
function! s:cd_git_root(path)
|
function! s:cd_git_root(path)
|
||||||
let l:path = fnamemodify(a:path, ':p')
|
let l:path = fnamemodify(expand(a:path), ':p')
|
||||||
let l:wd = getcwd()
|
let l:wd = getcwd()
|
||||||
if isdirectory(l:path)
|
if isdirectory(l:path)
|
||||||
exec 'cd '.a:path
|
exec 'cd '.a:path
|
||||||
elseif filereadable(l:path)
|
elseif filereadable(l:path)
|
||||||
exec 'cd '.fnamemodify(l:path, ':h')
|
exec 'cd '.fnamemodify(l:path, ':h')
|
||||||
else
|
else
|
||||||
return 0
|
throw 'Invalid Path'
|
||||||
endif
|
endif
|
||||||
let l:ret = substitute(system('git rev-parse --show-toplevel'), '\n\_.*', '', '')
|
let l:ret = substitute(system('git rev-parse --show-toplevel'), '\n\_.*', '', '')
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
exec 'cd '.l:wd
|
exec 'cd '.l:wd
|
||||||
return 0
|
throw 'Not a git repo!'
|
||||||
else
|
else
|
||||||
exec 'cd '.l:ret
|
exec 'cd '.l:ret
|
||||||
return l:ret
|
return l:ret
|
||||||
|
@ -148,7 +148,7 @@ endfun
|
||||||
function! s:git_diff(...)
|
function! s:git_diff(...)
|
||||||
if a:0
|
if a:0
|
||||||
let l:wd = getcwd()
|
let l:wd = getcwd()
|
||||||
call s:cd_git_root(expand('%'))
|
call s:cd_git_root('%')
|
||||||
split
|
split
|
||||||
call s:file_at_revision(a:1)
|
call s:file_at_revision(a:1)
|
||||||
diffthis
|
diffthis
|
||||||
|
@ -197,7 +197,7 @@ command! Uncommited try
|
||||||
\| catch
|
\| catch
|
||||||
\| echo 'Not a git repo!'
|
\| echo 'Not a git repo!'
|
||||||
\| endtry
|
\| endtry
|
||||||
command! GitRoot call <SID>cd_git_root('.')
|
command! GitRoot call <SID>cd_git_root('%')
|
||||||
command! GitOrig exec 'e '.b:git_original_file
|
command! GitOrig exec 'e '.b:git_original_file
|
||||||
command! ShowGitRoot try
|
command! ShowGitRoot try
|
||||||
\| echo <sid>gitroot()
|
\| echo <sid>gitroot()
|
||||||
|
|
Loading…
Reference in a new issue