From 5c23cadf57d2bd4b072e46f2320c9acec53134d6 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Fri, 5 Apr 2013 11:23:11 +0200 Subject: [PATCH] Allow plugin to bypass any alias for grep. This is an opt-in configuration. --- README.mkd | 10 +++++++++- doc/gitgutter.txt | 8 ++++++++ plugin/gitgutter.vim | 4 +++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.mkd b/README.mkd index 11706fd..6f7a209 100644 --- a/README.mkd +++ b/README.mkd @@ -77,6 +77,7 @@ You can customise: * The signs' colours and symbols * Line highlights * Extra arguments for `git diff` +* Whether or not to escape `grep` (default to no) * Whether or not vim-gitgutter is on initially (defaults to on) * Whether or not signs are shown (defaults to yes) * Whether or not line highlighting is on initially (defaults to off) @@ -152,6 +153,14 @@ If you want to pass extra arguments to `git diff`, for example to ignore whitesp let g:gitgutter_diff_args = '-w' ``` +#### Whether or not to escape `grep` + +If you have `grep` aliased to something which changes its output, for example `grep --color=auto -H`, you will need to tell vim-gitgutter to use raw grep: + +```viml +let g:gitgutter_escape_grep = 1 +``` + #### To turn off vim-gitgutter by default Add `let g:gitgutter_enabled = 0` to your `~/.vimrc`. @@ -218,7 +227,6 @@ Here are some things you can check: * Your git config is compatible with the version of git which your Vim is calling (`:echo system('git --version')`). * Your Vim supports signs (`:echo has('signs')` should give `1`). * Your file is being tracked by git and has unstaged changes. -* `grep` is on your path and available to Vim (`:echo executable('grep')` should return 1) ### Alternatives diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index b787526..c78981d 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -95,6 +95,7 @@ You can customise: - The signs' colours and symbols - Line highlights - Extra arguments for git-diff +- Whether or not to escape grep (defaults to no) - Whether or not vim-gitgutter is on initially (defaults to on) - Whether or not signs are shown (defaults to yes) - Whether or not line highlighting is on initially (defaults to off) @@ -181,6 +182,13 @@ To pass extra arguments to git-diff, add this to your |vimrc|: let g:gitgutter_diff_args = '-w' < +TO ESCAPE GREP + +To avoid any alias you have for grep, use this: +> + let g:gitgutter_escape_grep = 1 +< + TO TURN OFF VIM-GITGUTTER BY DEFAULT Add to your |vimrc| diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index df24cc2..606ff37 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -27,6 +27,7 @@ call s:set('g:gitgutter_sign_modified', '~') call s:set('g:gitgutter_sign_removed', '_') call s:set('g:gitgutter_sign_modified_removed', '~_') call s:set('g:gitgutter_diff_args', '') +call s:set('g:gitgutter_escape_grep', 0) let s:file = '' @@ -48,6 +49,7 @@ function! s:init() let s:dummy_sign_id = 153 let s:grep_available = executable('grep') + let s:grep_command = ' | ' . (g:gitgutter_escape_grep ? '\grep' : 'grep') . ' -e "^@@ "' let g:gitgutter_initialised = 1 endif @@ -193,7 +195,7 @@ endfunction function! s:run_diff() let cmd = 'git diff --no-ext-diff --no-color -U0 ' . g:gitgutter_diff_args . ' ' . shellescape(s:file()) if s:grep_available - let cmd .= ' | grep -e "^@@ "' + let cmd .= s:grep_command endif let diff = system(s:command_in_directory_of_file(cmd)) return diff