Created
September 14, 2018 02:20
-
-
Save doloopwhile/eff38319af29ace9506183c6fd99d813 to your computer and use it in GitHub Desktop.
Git 管理下のファイルを一括置換する git-sed コマンドを作った ref: https://qiita.com/tonluqclml/items/13b323cea92425b85218
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
$ git ls-files | xargs -n 1 sed -i 's|find_by_admin|find_by(type: :admin)|g' |
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
$ git sed 's|find_by_admin|find_by(type: :admin)|g' |
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
$ git sed 's|find_by_admin|find_by(type: :admin)|g' spec/ test/ |
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