Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created March 1, 2014 17:55
Show Gist options
  • Save pesterhazy/9294048 to your computer and use it in GitHub Desktop.
Save pesterhazy/9294048 to your computer and use it in GitHub Desktop.
Search your git repository using ag (the silver searcher)
#!/bin/bash
# Put additional ignore patterns (one by line) in .grepignore
#
git-ag () {
if [[ "$1" = "-a" ]]
then
all=1
shift
else
all=0
fi
pattern="$1"
shift
if [[ "$all" = 1 ]]
then
git ls-files -- "$@" | xargs -d "\n" ag -S "$pattern"
else
git ls-files -- "$@" | grep -vf .grepignore | xargs -d "\n" ag -S "$pattern"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment