Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Created September 14, 2018 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doloopwhile/4df982c153a49e236837ce443311deb4 to your computer and use it in GitHub Desktop.
Save doloopwhile/4df982c153a49e236837ce443311deb4 to your computer and use it in GitHub Desktop.
git-sed command
#!/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