lfn
serial
ticket/834-toolchain-update
topic/msim-upgrade
topic/simplify-dev-export
Last change
on this file since cb15b49c was 2021428, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago |
Improve tools/srepl.
- option
-d for removing the line entirely.
- automatically deal with slashes in the pattern.
|
-
Property mode
set to
100755
|
File size:
1.2 KB
|
Rev | Line | |
---|
[bdb8ba9] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
[4618998] | 3 | usage()
|
---|
| 4 | {
|
---|
[bdb8ba9] | 5 | echo "Usage:"
|
---|
| 6 | echo
|
---|
| 7 | echo " $0 search_pattern [-- <pathspec> ]"
|
---|
| 8 | echo " $0 search_pattern replacement [-- <pathspec> ]"
|
---|
| 9 | echo
|
---|
| 10 | echo "Pattern should be a basic regexp as accepted by grep and sed."
|
---|
| 11 | echo "For information on pathspec syntax, see git documentation."
|
---|
| 12 | echo
|
---|
| 13 | exit 1
|
---|
| 14 | }
|
---|
| 15 |
|
---|
[2021428] | 16 | check_unstaged()
|
---|
| 17 | {
|
---|
| 18 | if ( git status --porcelain | grep '^.[^ ]' ); then
|
---|
| 19 | echo "You have unstaged changes in your tree."
|
---|
| 20 | echo "Either stage them with 'git add', commit them,"
|
---|
| 21 | echo "or discard them with 'git checkout -- .'"
|
---|
| 22 | exit 1
|
---|
| 23 | fi
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | _slashify()
|
---|
| 27 | {
|
---|
| 28 | # Some shells have shoddy handling of backslashes in echo.
|
---|
| 29 | printf '%s\n' "$1" | sed 's/\([^\\]\)\//\1\\\//g'
|
---|
| 30 | }
|
---|
[bdb8ba9] | 31 |
|
---|
[4618998] | 32 | if [ "$1" = "--" ]; then
|
---|
[bdb8ba9] | 33 | usage
|
---|
[2021428] | 34 | elif [ "$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 |
|
---|
[4618998] | 42 | elif [ "$#" -eq 1 ] || [ "$2" = "--" ]; then
|
---|
[2021428] | 43 | pattern=`_slashify "$1"`
|
---|
[bdb8ba9] | 44 | shift
|
---|
| 45 | git grep -I -n "$pattern" "$@"
|
---|
[4618998] | 46 | elif [ "$#" -eq 2 ] || [ "$3" = "--" ]; then
|
---|
[2021428] | 47 | check_unstaged
|
---|
[bdb8ba9] | 48 |
|
---|
[2021428] | 49 | pattern=`_slashify "$1"`
|
---|
| 50 | replacement=`_slashify "$2"`
|
---|
[bdb8ba9] | 51 | shift
|
---|
| 52 | shift
|
---|
| 53 | git grep -I -l "$pattern" "$@" | xargs sed -i "s/$pattern/$replacement/g"
|
---|
| 54 | else
|
---|
| 55 | usage
|
---|
| 56 | fi
|
---|
Note:
See
TracBrowser
for help on using the repository browser.