From 00a862285f708c5e2271e3031ffc031c76f60eae Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 6 Mar 2013 12:11:38 +0100 Subject: [PATCH] Work with all shells, not just bash. --- plugin/gitgutter.vim | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index ed4d9a4..e6fdc22 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -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