Created
November 10, 2017 15:53
-
-
Save fenollp/4e462ff89b513f690a2792e862df8499 to your computer and use it in GitHub Desktop.
git sed s%pattern%replacement%flags [-- git-grep flags]
This file contains 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 | |
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