Created
September 14, 2018 02:16
-
-
Save doloopwhile/4df982c153a49e236837ce443311deb4 to your computer and use it in GitHub Desktop.
git-sed command
This file contains hidden or 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 | |
set -euC | |
if [ "$#" -eq 0 ]; then | |
echo 'git sed COMMAND [PATH [PATH[...]]]' >&2 | |
exit 1 | |
fi | |
if which gsed > /dev/null; then | |
SED=gsed # for macOS | |
else | |
SED=sed | |
fi | |
CMD=(-e "$1") | |
shift | |
apply_sed() { | |
f="$1" | |
} | |
while read -r f; do | |
[ -f "$f" ] && [ ! -L "$f" ] && "$SED" -i "${CMD[@]}" "$f" | |
done < <(git ls-files -- "$@") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment