Skip to content

Commit

Permalink
Work with all shells, not just bash.
Browse files Browse the repository at this point in the history
  • Loading branch information
airblade committed Mar 6, 2013
1 parent fd22bbb commit 00a8622
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugin/gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,29 @@ function! s:directory_of_current_file()
return shellescape(expand("%:p:h"))
endfunction

function! s:discard_stdout_and_stderr()
if !exists('s:discard')
if &shellredir ==? '>%s 2>&1'
let s:discard = ' > /dev/null 2>&1'
else
let s:discard = ' >& /dev/null'
endif
endif
return s:discard
endfunction

function! s:command_in_directory_of_current_file(cmd)
return 'cd ' . s:directory_of_current_file() . ' && ' . a:cmd
endfunction

function! s:is_in_a_git_repo()
let cmd = 'git rev-parse > /dev/null 2>&1'
let cmd = 'git rev-parse' . s:discard_stdout_and_stderr()
call system(s:command_in_directory_of_current_file(cmd))
return !v:shell_error
endfunction

function! s:is_tracked_by_git()
let cmd = 'git ls-files --error-unmatch > /dev/null 2>&1 ' . shellescape(s:current_file())
let cmd = 'git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:current_file())
call system(s:command_in_directory_of_current_file(cmd))
return !v:shell_error
endfunction
Expand Down

0 comments on commit 00a8622

Please sign in to comment.