├── README.md ├── autoload └── unite │ └── sources │ ├── grep_git.vim │ └── grep_hg.vim └── doc ├── screencast-001.gif └── unite-grep-vcs.txt /README.md: -------------------------------------------------------------------------------- 1 | unite-grep-vcs 2 | =============================================================================== 3 | ![unite-grep-vcs interface (screencast)](./doc/screencast-001.gif) 4 | 5 | Version: 0.1.0 6 | Support: Vim 7.3 and above (Let me know if there are issues) 7 | 8 | **NOTE** 9 | `grep/git` source is now moved into the [unite](https://github.com/Shougo/unite.vim) from [this](https://github.com/Shougo/unite.vim/commit/91acd3b8b1744e6f379420ff68d8b632d2e0c149) commit. 10 | 11 | *unite-grep-vcs* is an [unite](https://github.com/Shougo/unite.vim) source package plugin for 'git grep' or 'hg grep'. 12 | There is a similar plugin called [sgur/unite-git_grep](https://github.com/sgur/unite-git_grep). and the difference are: 13 | 14 | - unite-git_grep: grep command is called when user hit key in unite interface (like incremental search) 15 | - unite-grep-vcs: grep command is called once when user open the unite interface. This behavior is similar to 'Unite grep'. 16 | 17 | 18 | 19 | How to install 20 | ============================================================================== 21 | 22 | The structure of the [repository](https://github.com/lambdalisue/unite-grep-vcs) follow a standard vim plugin's directory structure thus you can use [Vundle.vim](https://github.com/gmarik/Vundle.vim) or [neobundle.vim](https://github.com/Shougo/neobundle.vim) to install vim-gista like: 23 | 24 | ```vim 25 | " Vundle.vim 26 | Plugin 'lambdalisue/unite-grep-vcs' 27 | 28 | " neobundle.vim 29 | NeoBundle 'lambdalisue/unite-grep-vcs' 30 | 31 | " neobundle.vim (Lazy) 32 | NeoBundleLazy 'lambdalisue/unite-grep-vcs', { 33 | \ 'autoload': { 34 | \ 'unite_sources': ['grep/git', 'grep/hg'], 35 | \}} 36 | ``` 37 | 38 | How to use 39 | ============================================================================== 40 | 41 | unite-grep-vcs provide the following two sources 42 | 43 | 1. `grep/git` call `git grep` command internally. 44 | 2. `grep/hg` call `hg grep` command internally. 45 | 46 | 47 | License 48 | =============================================================================== 49 | 50 | Original grep.vim License (unite.vim) 51 | ------------------------------------------------------------------------------- 52 | 53 | AUTHOR: Shougo Matsushita 54 | Tomohiro Nishimura 55 | 56 | License: MIT license 57 | Permission is hereby granted, free of charge, to any person obtaining 58 | a copy of this software and associated documentation files (the 59 | "Software"), to deal in the Software without restriction, including 60 | without limitation the rights to use, copy, modify, merge, publish, 61 | distribute, sublicense, and/or sell copies of the Software, and to 62 | permit persons to whom the Software is furnished to do so, subject to 63 | the following conditions: 64 | 65 | The above copyright notice and this permission notice shall be included 66 | in all copies or substantial portions of the Software. 67 | 68 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 69 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 70 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 71 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 72 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 73 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 74 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 75 | 76 | 77 | unite-grep-vcs License 78 | ------------------------------------------------------------------------------- 79 | The MIT License (MIT) 80 | 81 | Copyright (c) 2014 Alisue, hashnote.net 82 | 83 | Permission is hereby granted, free of charge, to any person obtaining a copy 84 | of this software and associated documentation files (the "Software"), to deal 85 | in the Software without restriction, including without limitation the rights 86 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 87 | copies of the Software, and to permit persons to whom the Software is 88 | furnished to do so, subject to the following conditions: 89 | 90 | The above copyright notice and this permission notice shall be included in 91 | all copies or substantial portions of the Software. 92 | 93 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 94 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 95 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 96 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 97 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 98 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 99 | THE SOFTWARE. 100 | -------------------------------------------------------------------------------- /autoload/unite/sources/grep_git.vim: -------------------------------------------------------------------------------- 1 | "****************************************************************************** 2 | " A Unite source for call 'git grep' 3 | " 4 | " Author: Alisue 5 | " URL: http://hashnote.net/ 6 | " License: MIT license 7 | " (C) 2014, Alisue, hashnote.net 8 | "****************************************************************************** 9 | let s:save_cpo = &cpo 10 | set cpo&vim 11 | 12 | function! unite#sources#grep_git#define() "{{{ 13 | return s:source 14 | endfunction "}}} 15 | 16 | function! unite#sources#grep_git#is_available() "{{{ 17 | if !executable('git') 18 | return 0 19 | endif 20 | call unite#util#system('git rev-parse') 21 | return (unite#util#get_last_status() == 0) ? 1 : 0 22 | endfunction "}}} 23 | function! unite#sources#grep_git#repository_root() "{{{ 24 | if !executable('git') 25 | return '' 26 | endif 27 | let stdout = unite#util#system('git rev-parse --show-toplevel') 28 | return (unite#util#get_last_status() == 0) ? stdout : '' 29 | endfunction "}}} 30 | 31 | " Inherit from 'grep' source 32 | let s:origin = unite#sources#grep#define() 33 | let s:source = deepcopy(s:origin) 34 | let s:source['name'] = 'grep/git' 35 | let s:source['description'] = 'candidates from git grep' 36 | 37 | function! s:source.hooks.on_init(args, context) "{{{ 38 | if !unite#sources#grep_git#is_available() 39 | call unite#print_source_error( 40 | \ 'The directory is not in git repository.', 41 | \ s:source.name) 42 | return 43 | endif 44 | if get(a:args, 0, '') ==# '/' 45 | " the behaviour of 'Unite grep' has changed from aa6afa9. 46 | let a:args[0] = unite#sources#grep_git#repository_root() 47 | endif 48 | return s:origin.hooks.on_init(a:args, a:context) 49 | endfunction " }}} 50 | 51 | 52 | function! s:source.gather_candidates(args, context) "{{{ 53 | " 54 | " Note: 55 | " Most of code in this function was copied from unite.vim 56 | " 57 | if !executable('git') 58 | call unite#print_source_message( 59 | \ 'command "git" is not executable.', s:source.name) 60 | let a:context.is_async = 0 61 | return [] 62 | endif 63 | 64 | if !unite#util#has_vimproc() 65 | call unite#print_source_message( 66 | \ 'vimproc plugin is not installed.', self.name) 67 | let a:context.is_async = 0 68 | return [] 69 | endif 70 | 71 | if empty(a:context.source__targets) 72 | \ || a:context.source__input == '' 73 | call unite#print_source_message('Canceled.', s:source.name) 74 | let a:context.is_async = 0 75 | return [] 76 | endif 77 | 78 | if a:context.is_redraw 79 | let a:context.is_async = 1 80 | endif 81 | 82 | let cmdline = printf('git grep -n --no-color %s %s -- %s', 83 | \ a:context.source__extra_opts, 84 | \ string(a:context.source__input), 85 | \ unite#helper#join_targets(a:context.source__targets), 86 | \) 87 | call unite#print_source_message('Command-line: ' . cmdline, s:source.name) 88 | 89 | " Note: 90 | " --no-color is specified thus $TERM='dumb' is not required (actually git 91 | " will blame if the $TERM value is not properly configured thus it should 92 | " not be 'dumb'). 93 | " 94 | " Note: 95 | " 'git grep' does not work properly with PTY 96 | " 97 | let a:context.source__proc = vimproc#plineopen3( 98 | \ vimproc#util#iconv(cmdline, &encoding, 'char'), 0) 99 | 100 | return self.async_gather_candidates(a:args, a:context) 101 | endfunction "}}} 102 | 103 | 104 | let &cpo = s:save_cpo 105 | unlet s:save_cpo 106 | "vim: sts=2 sw=2 smarttab et ai textwidth=0 fdm=marker 107 | -------------------------------------------------------------------------------- /autoload/unite/sources/grep_hg.vim: -------------------------------------------------------------------------------- 1 | "****************************************************************************** 2 | " A Unite source for call 'hg grep' 3 | " 4 | " Author: Alisue 5 | " URL: http://hashnote.net/ 6 | " License: MIT license 7 | " (C) 2014, Alisue, hashnote.net 8 | "****************************************************************************** 9 | let s:save_cpo = &cpo 10 | set cpo&vim 11 | 12 | function! unite#sources#grep_hg#define() "{{{ 13 | return s:source 14 | endfunction "}}} 15 | 16 | function! unite#sources#grep_hg#is_available() "{{{ 17 | if !executable('hg') 18 | return 0 19 | endif 20 | call unite#util#system('hg root') 21 | return (unite#util#get_last_status() == 0) ? 1 : 0 22 | endfunction "}}} 23 | function! unite#sources#grep_hg#repository_root() "{{{ 24 | if !executable('hg') 25 | return '' 26 | endif 27 | let stdout = unite#util#system('hg root') 28 | return (unite#util#get_last_status() == 0) ? stdout : '' 29 | endfunction "}}} 30 | 31 | " Inherit from 'grep' source 32 | let s:origin = unite#sources#grep#define() 33 | let s:source = deepcopy(s:origin) 34 | let s:source['name'] = 'grep/hg' 35 | let s:source['description'] = 'candidates from hg grep' 36 | 37 | function! s:source.hooks.on_init(args, context) "{{{ 38 | if !unite#sources#grep_hg#is_available() 39 | call unite#print_source_error( 40 | \ 'The directory is not in marcurial repository.', 41 | \ s:source.name) 42 | return 43 | endif 44 | if get(a:args, 0, '') ==# '/' 45 | " the behaviour of 'Unite grep' has changed from aa6afa9. 46 | let a:args[0] = unite#sources#grep_hg#repository_root() 47 | endif 48 | return s:origin.hooks.on_init(a:args, a:context) 49 | endfunction " }}} 50 | 51 | 52 | function! s:source.gather_candidates(args, context) "{{{ 53 | " 54 | " Note: 55 | " Most of code in this function was copied from unite.vim 56 | " 57 | if !executable('hg') 58 | call unite#print_source_message( 59 | \ 'command "hg" is not executable.', s:source.name) 60 | let a:context.is_async = 0 61 | return [] 62 | endif 63 | 64 | if !unite#util#has_vimproc() 65 | call unite#print_source_message( 66 | \ 'vimproc plugin is not installed.', self.name) 67 | let a:context.is_async = 0 68 | return [] 69 | endif 70 | 71 | if empty(a:context.source__targets) 72 | \ || a:context.source__input == '' 73 | call unite#print_source_message('Canceled.', s:source.name) 74 | let a:context.is_async = 0 75 | return [] 76 | endif 77 | 78 | if a:context.is_redraw 79 | let a:context.is_async = 1 80 | endif 81 | 82 | let cmdline = printf('hg grep -n %s %s %s', 83 | \ a:context.source__extra_opts, 84 | \ string(a:context.source__input), 85 | \ unite#helper#join_targets(a:context.source__targets), 86 | \) 87 | call unite#print_source_message('Command-line: ' . cmdline, s:source.name) 88 | 89 | " Note: 90 | " 'hg grep' does not have color thus $TERM='dumb' is not required. 91 | let a:context.source__proc = vimproc#plineopen3( 92 | \ vimproc#util#iconv(cmdline, &encoding, 'char'), 1) 93 | 94 | return self.async_gather_candidates(a:args, a:context) 95 | endfunction "}}} 96 | 97 | 98 | let &cpo = s:save_cpo 99 | unlet s:save_cpo 100 | "vim: sts=2 sw=2 smarttab et ai textwidth=0 fdm=marker 101 | -------------------------------------------------------------------------------- /doc/screencast-001.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lambdalisue/unite-grep-vcs/193e5b67cc06ce1766421025ff19dd99a6778dbd/doc/screencast-001.gif -------------------------------------------------------------------------------- /doc/unite-grep-vcs.txt: -------------------------------------------------------------------------------- 1 | *unite-grep-vcs.txt* Unite sources for git grep or hg grep 2 | 3 | Version: 0.1.0 4 | Author: Alisue *unite-grep-vcs-author* 5 | Support: Vim 7.3 and above 6 | License: MIT license {{{ 7 | Copyright (c) 2014 Alisue, hashnote.net 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining 10 | a copy of this software and associated documentation files 11 | (the "Software"), to deal in the Software without restriction, 12 | including without limitation the rights to use, copy, modify, merge, 13 | publish, distribute, sublicense, and/or sell copies of the Software, 14 | and to permit persons to whom the Software is furnished to do so, 15 | subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be 18 | included in all copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | }}} 28 | 29 | ============================================================================= 30 | CONTENTS *unite-grep-vcs-contents* 31 | 32 | Introduction |unite-grep-vcs-introduction| 33 | Install |unite-grep-vcs-install| 34 | Usage |unite-grep-vcs-usage| 35 | Unite interface |unite-grep-vcs-unite-interface| 36 | Sources |unite-grep-vcs-unite-interface-sources| 37 | 38 | 39 | ============================================================================== 40 | INTRODUCTION *unite-grep-vcs-introduction* 41 | 42 | *unite-grep-vcs* is an unite source package plugin for 'git grep' or 'hg grep'. 43 | There is a similar plugin called unite-git_grep and the difference are: 44 | 45 | - unite-git_grep: grep command is called when user hit key in unite interface. 46 | This behavior is quite different from the default 'grep' source. 47 | - unite-grep-vcs: grep command is called once when user open the unite 48 | interface. This behavior is similar to the default 'grep' source. 49 | 50 | References: 51 | - Shougo/unite.vim: https://github.com/Shougo/unite.vim 52 | - sgur/unite-git_grep.vim: https://github.com/sgur/unite-git_grep 53 | 54 | 55 | ============================================================================== 56 | INSTALL *unite-grep-vcs-install* 57 | 58 | Structure of the repository (https://github.com/lambdalisue/unite-grep-vcs) 59 | follow a standard vim plugin's directory structure thus you can use 60 | Vundle.vim or neobundle.vim to install |unite-grep-vcs| like: 61 | > 62 | " Vundle.vim 63 | Plugin 'lambdalisue/unite-grep-vcs' 64 | 65 | " neobundle.vim 66 | NeoBundle 'lambdalisue/unite-grep-vcs' 67 | 68 | " neobundle.vim (Lazy) 69 | NeoBundleLazy 'lambdalisue/unite-grep-vcs', { 70 | \ 'autoload': { 71 | \ 'unite_sources': ['grep/git', 'grep/hg'], 72 | \}} 73 | < 74 | 75 | ============================================================================== 76 | UNITE INTERFACE *unite-grep-vcs-unite-interface* 77 | 78 | ------------------------------------------------------------------------------ 79 | Sources *unite-grep-vcs-unite-interface-sources* 80 | 81 | *unite/sources/grep/git* 82 | unite/sources/grep/git 83 | Candidates from 'git grep' command. It will fail if the specified 84 | directory is not in git repository. 85 | If '/' is specified as source target, it will execute git grep on the 86 | repository. 87 | > 88 | :Unite grep/git:. 89 | :Unite grep/git:/ 90 | < 91 | *unite/sources/grep/hg* 92 | unite/sources/grep/hg 93 | Candidates from 'hg grep' command. It will fail if the specified 94 | directory is not in marcurial directory. 95 | If '/' is specified as source target, it will execute hg grep on the 96 | repository. 97 | > 98 | :Unite grep/hg:. 99 | :Unite grep/hg:/ 100 | < 101 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl:noet 102 | --------------------------------------------------------------------------------