Skip to content

Instantly share code, notes, and snippets.

@jeebak
Last active October 22, 2015 02:42

Revisions

  1. jeebak revised this gist Oct 22, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions git-pie-ify
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@
    #
    # https://gist.github.com/jeebak/f9088cede18d31f2d3a0
    #
    # Added to: https://github.com/unixorn/git-extra-commands
    # Further updates will be there.
    #

    [[ $# -ne 2 ]] && echo "Usage: git pie-ify pattern replacement" 1>&2 && exit 1

  2. jeebak revised this gist Oct 21, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-pie-ify
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # https://gist.github.com/jeebak/f9088cede18d31f2d3a0
    #

    [[ $# -ne 2 ]] && echo "Usage: git pie-fiy pattern replacement" && exit 1
    [[ $# -ne 2 ]] && echo "Usage: git pie-ify pattern replacement" 1>&2 && exit 1

    pattern="$(sed 's;/;\\/;g' <<< "$1")"
    replacement="$(sed 's;/;\\/;g' <<< "$2")"
  3. jeebak revised this gist Oct 21, 2015. No changes.
  4. jeebak revised this gist Oct 21, 2015. No changes.
  5. jeebak revised this gist Oct 21, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions git-pie-ify
    Original file line number Diff line number Diff line change
    @@ -3,16 +3,16 @@
    # https://gist.github.com/jeebak/f9088cede18d31f2d3a0
    #

    [[ $# -ne 2 ]] && echo "Usage: git pie-fiy from to" && exit
    [[ $# -ne 2 ]] && echo "Usage: git pie-fiy pattern replacement" && exit 1

    from="$(sed 's;/;\\/;g' <<< "$1")"
    to="$(sed 's;/;\\/;g' <<< "$2")"
    pattern="$(sed 's;/;\\/;g' <<< "$1")"
    replacement="$(sed 's;/;\\/;g' <<< "$2")"

    while read -r file; do
    if [[ -f "$file" ]]; then
    echo "Processing: '$file'"
    # TODO: fall back to sed, if perl's not available, accounting for different
    # (osx/linux) versions.
    perl -p -i -e 's/'"$from"'/'"$to"'/g' "$file"
    perl -p -i -e 's/'"$pattern"'/'"$replacement"'/g' "$file"
    fi
    done <<< "$(git grep --name-only "$from")"
    done <<< "$(git grep --name-only "$pattern")"
  6. jeebak revised this gist Oct 21, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-pie-ify
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,4 @@ while read -r file; do
    # (osx/linux) versions.
    perl -p -i -e 's/'"$from"'/'"$to"'/g' "$file"
    fi
    done <<< "$(git grep "$from" | sed 's/:.*$//' | sort -u)"
    done <<< "$(git grep --name-only "$from")"
  7. jeebak revised this gist Oct 21, 2015. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions git-pie-ify
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    #!/usr/bin/env bash
    #
    # https://gist.github.com/jeebak/f9088cede18d31f2d3a0
    #

    [[ $# -ne 2 ]] && echo "Usage: git pie-fiy from to" && exit

    @@ -8,8 +11,8 @@ to="$(sed 's;/;\\/;g' <<< "$2")"
    while read -r file; do
    if [[ -f "$file" ]]; then
    echo "Processing: '$file'"
    # TODO: fall back on sed, if perl's not available, accounting for different
    # (max/linux versions of sed.)
    # TODO: fall back to sed, if perl's not available, accounting for different
    # (osx/linux) versions.
    perl -p -i -e 's/'"$from"'/'"$to"'/g' "$file"
    fi
    done <<< "$(git grep "$from" | sed 's/:.*$//' | sort -u)"
  8. jeebak revised this gist Oct 20, 2015. No changes.
  9. jeebak created this gist Oct 20, 2015.
    15 changes: 15 additions & 0 deletions git-pie-ify
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/usr/bin/env bash

    [[ $# -ne 2 ]] && echo "Usage: git pie-fiy from to" && exit

    from="$(sed 's;/;\\/;g' <<< "$1")"
    to="$(sed 's;/;\\/;g' <<< "$2")"

    while read -r file; do
    if [[ -f "$file" ]]; then
    echo "Processing: '$file'"
    # TODO: fall back on sed, if perl's not available, accounting for different
    # (max/linux versions of sed.)
    perl -p -i -e 's/'"$from"'/'"$to"'/g' "$file"
    fi
    done <<< "$(git grep "$from" | sed 's/:.*$//' | sort -u)"