lfn
serial
ticket/834-toolchain-update
topic/msim-upgrade
topic/simplify-dev-export
Last change
on this file since d4a829e was bdb8ba9, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago |
Add tools/srepl, a simple search/replace script.
|
-
Property mode
set to
100755
|
File size:
848 bytes
|
Line | |
---|
1 | #!/bin/sh
|
---|
2 |
|
---|
3 | function usage {
|
---|
4 | echo "Usage:"
|
---|
5 | echo
|
---|
6 | echo " $0 search_pattern [-- <pathspec> ]"
|
---|
7 | echo " $0 search_pattern replacement [-- <pathspec> ]"
|
---|
8 | echo
|
---|
9 | echo "Pattern should be a basic regexp as accepted by grep and sed."
|
---|
10 | echo "For information on pathspec syntax, see git documentation."
|
---|
11 | echo
|
---|
12 | exit 1
|
---|
13 | }
|
---|
14 |
|
---|
15 |
|
---|
16 | if [ "$1" == "--" ]; then
|
---|
17 | usage
|
---|
18 | elif [ "$#" -eq 1 ] || [ "$2" == "--" ]; then
|
---|
19 | pattern="$1"
|
---|
20 | shift
|
---|
21 | git grep -I -n "$pattern" "$@"
|
---|
22 | elif [ "$#" -eq 2 ] || [ "$3" == "--" ]; then
|
---|
23 |
|
---|
24 | if ( git status --porcelain | grep '^.[^ ]' ); then
|
---|
25 | echo "You have unstaged changes in your tree."
|
---|
26 | echo "Either stage them with 'git add', commit them,"
|
---|
27 | echo "or discard them with 'git checkout -- .'"
|
---|
28 | exit 1
|
---|
29 | fi
|
---|
30 |
|
---|
31 | pattern="$1"
|
---|
32 | replacement="$2"
|
---|
33 | shift
|
---|
34 | shift
|
---|
35 | git grep -I -l "$pattern" "$@" | xargs sed -i "s/$pattern/$replacement/g"
|
---|
36 | else
|
---|
37 | usage
|
---|
38 | fi
|
---|
Note:
See
TracBrowser
for help on using the repository browser.