Minor refactor.

This commit is contained in:
Andy Stewart
2015-08-17 09:45:31 +02:00
parent 0ca15c8ad2
commit 62462a25a7
2 changed files with 11 additions and 15 deletions

View File

@@ -9,23 +9,18 @@ if s:grep_available
endif endif
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@' let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
let s:fish = &shell =~# 'fish'
function! gitgutter#diff#run_diff(realtime, use_external_grep) function! gitgutter#diff#run_diff(realtime, use_external_grep)
" Detect whether user uses fish shell " Wrap compound commands in parentheses to make Windows happy.
let l:fish = &shell =~# 'fish' " bash doesn't mind the parentheses; fish doesn't want them.
let cmd = s:fish ? '' : '('
if !l:fish
" Wrap compound commands in parentheses to make Windows happy.
let cmd = '('
else
let cmd = ''
end
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
let tracked = getbufvar(bufnr, 'gitgutter_tracked') " i.e. tracked by git let tracked = getbufvar(bufnr, 'gitgutter_tracked') " i.e. tracked by git
if !tracked if !tracked
let cmd .= 'git ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename()) let cmd .= 'git ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename())
let cmd .= l:fish ? '; and ' : ' && (' let cmd .= s:fish ? '; and ' : ' && ('
endif endif
if a:realtime if a:realtime
@@ -38,7 +33,7 @@ function! gitgutter#diff#run_diff(realtime, use_external_grep)
let buff_file .= '.'.extension let buff_file .= '.'.extension
endif endif
let cmd .= 'git show '.blob_name.' > '.blob_file let cmd .= 'git show '.blob_name.' > '.blob_file
let cmd .= l:fish ? '; and ' : ' && ' let cmd .= s:fish ? '; and ' : ' && '
" Writing the whole buffer resets the '[ and '] marks and also the " Writing the whole buffer resets the '[ and '] marks and also the
" 'modified' flag (if &cpoptions includes '+'). These are unwanted " 'modified' flag (if &cpoptions includes '+'). These are unwanted
@@ -70,10 +65,11 @@ function! gitgutter#diff#run_diff(realtime, use_external_grep)
" differences are found. However we want to treat non-matches and " differences are found. However we want to treat non-matches and
" differences as non-erroneous behaviour; so we OR the command with one " differences as non-erroneous behaviour; so we OR the command with one
" which always exits with success (0). " which always exits with success (0).
let cmd.= l:fish ? '; or exit 0' : ' || exit 0' let cmd .= s:fish ? '; or ' : ' || '
let cmd .= 'exit 0'
endif endif
if !l:fish if !s:fish
let cmd .= ')' let cmd .= ')'
if !tracked if !tracked

View File

@@ -1,6 +1,7 @@
let s:file = '' let s:file = ''
let s:using_xolox_shell = -1 let s:using_xolox_shell = -1
let s:exit_code = 0 let s:exit_code = 0
let s:fish = &shell =~# 'fish'
function! gitgutter#utility#warn(message) function! gitgutter#utility#warn(message)
echohl WarningMsg echohl WarningMsg
@@ -131,8 +132,7 @@ function! gitgutter#utility#file_relative_to_repo_root()
endfunction endfunction
function! gitgutter#utility#command_in_directory_of_file(cmd) function! gitgutter#utility#command_in_directory_of_file(cmd)
let l:fish = &shell =~# 'fish' return 'cd '.gitgutter#utility#shellescape(gitgutter#utility#directory_of_file()) . (s:fish ? '; and ' : ' && ') . a:cmd
return 'cd ' . gitgutter#utility#shellescape(gitgutter#utility#directory_of_file()) . (l:fish ? '; and ' : ' && ') . a:cmd
endfunction endfunction
function! gitgutter#utility#highlight_name_for_change(text) function! gitgutter#utility#highlight_name_for_change(text)