jmtd → log → Useful script
Here's a useful shell procedure:
vigg ()
{
git grep --color=auto -lz "$1" | xargs -r0 sh -c "vi +/\"$1\" \"\$@\" < /dev/tty"
}
git grep
is a very effective way to run a recursive grep
over a git
repository, or part of a git repository (by default, it limits its search to
the sub-tree you are currently sitting in). I quite often find myself wanting
to edit every file that matched a search, and so wrote this snippet.
The /dev/tty
-ugliness is to work around vi
complaining that it's standard
input was set to /dev/null
by xargs
. BSD xargs
has a command, -o
, which
sorts this out; GNU xargs
doesn't, but the manual suggests the above portable
workaround. This marks the first time a BSD tool has had a feature I've wanted
and the GNU equivalent doesn't.
Comments
From the git-grep manpage:
Doesn't do this do the same as your script?
jupp $(git grep -l "$1")
Fails with whitespace in filenames, but then, nobody does that anyway. And is easy enough to type inline, without needing a function.
git jump grep
) and more (diff, merge). The only difference is that it will open a quickfix list, so you'll have to use:cn
instead of:bn
.