Skip to content

Instantly share code, notes, and snippets.

@erikerlandson
Created October 23, 2014 23:18
Show Gist options
  • Save erikerlandson/a3522d9bb0a89f2166db to your computer and use it in GitHub Desktop.
Save erikerlandson/a3522d9bb0a89f2166db to your computer and use it in GitHub Desktop.
git alias to edit repo files using sed
[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