-
Notifications
You must be signed in to change notification settings - Fork 11
/
vimgrep
executable file
·40 lines (34 loc) · 924 Bytes
/
vimgrep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
help() {
echo 'usage: vimgrep (REGULAR_EXPRESSION|rg_option)+'
echo ' vimgrep --help'
echo
echo ' will:'
echo ' - use ripgrep (`rg`) to grep files'
echo ' - display the result'
echo ' - ask for confirmation'
echo ' - edit the files with vim'
echo
echo ' You can set the VVV environment variable to'
echo ' set options for vim:'
echo
echo ' VVV=-o vimgrep foo'
echo
echo ' Attention: this will run `rg` twice'
echo
exit 1
}
[ "$1" == "--help" -o "$1" == "" ] && help
echo
rg --color always "$@"
res=$?
echo
if [ "$res" == "0" ]; then
echo 'CTRL-C now if you do not want to edit the file(s) above or ENTER to continue.'
echo
echo 'once editing a file use `:cnext` to jump to the next occurence of the search string'
read answer
vim $VVV -q <(rg --vimgrep "$1")
else
echo 'No match was found'
fi