Skip to content

Instantly share code, notes, and snippets.

@babarot
Created March 4, 2022 18:30
Show Gist options
  • Save babarot/135843910e2294781518587e9e90078e to your computer and use it in GitHub Desktop.
Save babarot/135843910e2294781518587e9e90078e to your computer and use it in GitHub Desktop.
#!/bin/bash
if ! type sd &>/dev/null; then
echo "sd: command not found" >&2
exit 1
fi
case "${#}" in
0)
echo "too few arguments" >&2
exit 1
;;
1)
# same as git grep
git grep "${1}"
;;
2)
git grep -l "${1}" | xargs -I% sd "${1}" "${2}" %
;;
*)
input="${1}"
output="${2}"
shift 2
git grep -l "${input}" "${@}" | xargs -I% sd "${input}" "${output}" %
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment