Created
December 7, 2010 10:21
-
-
Save amiryal/731648 to your computer and use it in GitHub Desktop.
A shell script that tries to emulate the most basic functionality of 'git grep' for Mercurial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Save the first argument as search pattern (the "what") | |
what=$1 | |
shift | |
# Use colours if output goes to terminal | |
if [ -t 1 ]; then | |
use_color="--color=always" | |
fi | |
# Convert the remaining positional arguments to -I arguments for 'hg locate' | |
declare -a patterns | |
for pattern in "$@"; do | |
patterns[${#patterns[*]}]="-I$pattern" | |
done | |
# Display matches nicely with colours and pager | |
hg locate -0 "${patterns[@]}" | xargs -0 grep $use_color "$what" | less -SFRX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment