Changeset 2021428 in mainline


Ignore:
Timestamp:
2018-05-12T16:40:25Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
df96271
Parents:
8a1be76
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-05-12 15:56:07)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-05-12 16:40:25)
Message:

Improve tools/srepl.

  • option -d for removing the line entirely.
  • automatically deal with slashes in the pattern.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/srepl

    r8a1be76 r2021428  
    1414}
    1515
    16 
    17 if [ "$1" = "--" ]; then
    18         usage
    19 elif [ "$#" -eq 1 ]  || [ "$2" = "--" ]; then
    20         pattern="$1"
    21         shift
    22         git grep -I -n "$pattern" "$@"
    23 elif [ "$#" -eq 2 ] || [ "$3" = "--" ]; then
    24 
     16check_unstaged()
     17{
    2518        if ( git status --porcelain | grep '^.[^ ]' ); then
    2619                echo "You have unstaged changes in your tree."
     
    2922                exit 1
    3023        fi
     24}
    3125
    32         pattern="$1"
    33         replacement="$2"
     26_slashify()
     27{
     28        # Some shells have shoddy handling of backslashes in echo.
     29        printf '%s\n' "$1" | sed 's/\([^\\]\)\//\1\\\//g'
     30}
     31
     32if [ "$1" = "--" ]; then
     33        usage
     34elif [ "$1" = "-d" ]; then
     35        check_unstaged
     36
     37        pattern=`_slashify "$2"`
     38        shift
     39        shift
     40        git grep -I -l "$pattern" "$@" | xargs sed -i "/$pattern/d"
     41
     42elif [ "$#" -eq 1 ]  || [ "$2" = "--" ]; then
     43        pattern=`_slashify "$1"`
     44        shift
     45        git grep -I -n "$pattern" "$@"
     46elif [ "$#" -eq 2 ] || [ "$3" = "--" ]; then
     47        check_unstaged
     48
     49        pattern=`_slashify "$1"`
     50        replacement=`_slashify "$2"`
    3451        shift
    3552        shift
Note: See TracChangeset for help on using the changeset viewer.