Created
October 23, 2014 23:18
-
-
Save erikerlandson/a3522d9bb0a89f2166db to your computer and use it in GitHub Desktop.
git alias to edit repo files using sed
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
[alias] | |
# use sed to edit files from 'git ls-files' in-place using the editing expression | |
# git sed [ args-to-git-ls-files ] <sed-expr> | |
# git sed s/foo/bar/g | |
# git sed --modified s/foo/bar/g | |
# handles nasty file names, e.g. with whitespaces, punctuation etc | |
sed = "!f() { let n=$#-1; let n=$((n>0?n:0)); eval sed -i ${@: -1} $(git ls-files ${@: 1:$n} | awk '{printf(\"\\\"%s\\\"\\n\", $0)}'); }; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment