Created
February 7, 2018 19:22
-
-
Save danthegoodman/ed48234db84cd56d4751adbfeb85d51d to your computer and use it in GitHub Desktop.
mag - Multi Ag
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
#!/usr/bin/env bash | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: mag [QUERY]..." | |
echo "" | |
echo "Multi-ag : Searches files for multiple patterns using ag" | |
exit 1 | |
fi | |
QUERY='ag -l "'"$1"'"' | |
FINAL="$1" | |
shift | |
while [[ $# -ne 0 ]]; do | |
QUERY="$QUERY"' | xargs ag -l "'"$1"'"' | |
FINAL="$FINAL|$1" | |
shift | |
done | |
QUERY="$QUERY"' | xargs ag --heading "'"$FINAL"'"' | |
echo "$QUERY" | |
echo "---" | |
bash -c "$QUERY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment