Skip to content

Instantly share code, notes, and snippets.

@fenollp
Created November 10, 2017 15:53
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 fenollp/4e462ff89b513f690a2792e862df8499 to your computer and use it in GitHub Desktop.
Save fenollp/4e462ff89b513f690a2792e862df8499 to your computer and use it in GitHub Desktop.
git sed s%pattern%replacement%flags [-- git-grep flags]
#!/bin/bash
ged() {
local sprf="$1" ; shift
[[ "$sprf" == 's%'* ]] || return 10 # MUST be s%p%r%f
local p="$(echo "$sprf" | cut -d% -f2)"
[[ "$p" == '' ]] && return 11
if git status --porcelain | grep '^ ' | grep .; then return 12; fi
local git_grep='git grep -IE'
local f="$(echo "$sprf" | cut -d% -f4)"
[[ "$f" == *'i'* ]] && local git_grep="$git_grep -i"
$git_grep --files-with-matches --null "$p" $@ | xargs --null --no-run-if-empty sed -i "$sprf"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment