Skip to content

Instantly share code, notes, and snippets.

@amiryal
Created December 7, 2010 10:21
Show Gist options
  • Save amiryal/731648 to your computer and use it in GitHub Desktop.
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
#!/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