Skip to content

Commit

Permalink
Allow plugin to bypass any alias for grep.
Browse files Browse the repository at this point in the history
This is an opt-in configuration.
  • Loading branch information
airblade committed Apr 5, 2013
1 parent 5bc25a8 commit 5c23cad
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions doc/gitgutter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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|
Expand Down
4 changes: 3 additions & 1 deletion plugin/gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5c23cad

Please sign in to comment.