Skip to content

Instantly share code, notes, and snippets.

@danthegoodman
Created February 7, 2018 19:22
Show Gist options
  • Save danthegoodman/ed48234db84cd56d4751adbfeb85d51d to your computer and use it in GitHub Desktop.
Save danthegoodman/ed48234db84cd56d4751adbfeb85d51d to your computer and use it in GitHub Desktop.
mag - Multi Ag
#!/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