diff --git a/vimrc b/vimrc index 7004192..4ff1e6e 100644 --- a/vimrc +++ b/vimrc @@ -364,6 +364,15 @@ command! -nargs=* Hex call hex() " === GIT STUFF === " +function! s:gitroot() + let s:ret = substitute(system('git rev-parse --show-toplevel'), '\n\_.*', '', '') + if v:shell_error + throw s:ret + else + return s:ret + end +endf + function! s:git_history() if exists("b:git_history") if b:git_history[0]+10 > localtime() @@ -513,15 +522,31 @@ function! s:git_blame() keepjumps call setpos('.', [0, l:line, l:char, 0]) endfun -command! Blame call git_blame() -command! GitNext call git_next() | call s:git_info() +command! Blame try + \| call s:gitroot() | call git_blame() + \| catch | echo 'Not a git repo!' + \| endtry +command! GitNext try + \| call s:gitroot() | call git_next() | call s:git_info() + \| catch | echo 'Not a git repo!' + \| endtry command! GitPrev call git_prev() | call s:git_info() command! GitFirst call git_first() | call s:git_info() command! GitLast call git_last() | call s:git_info() command! GitInfo call git_info() command! -nargs=1 GitCheckout call file_at_revision() -command! -nargs=? GitCompare call git_diff() -command! GitRoot exec 'cd '.system('git rev-parse --show-toplevel') +command! -nargs=? GitCompare try + \| call s:gitroot() | call git_diff() + \| catch | echo 'Not a git repo!' + \| endtry +command! Uncommited try + \| call s:gitroot() | call git_diff() + \| catch | echo 'Not a git repo!' + \| endtry +command! GitRoot try + \| echo gitroot() + \| catch | echo 'Not a git repository' + \| endtry " === FILE STUFF ===