Created
March 4, 2022 18:30
-
-
Save babarot/135843910e2294781518587e9e90078e to your computer and use it in GitHub Desktop.
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
#!/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