source: mainline/tools/srepl@ 8a1be76

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8a1be76 was 4618998, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 8 years ago

Fix tools/srepl to work in non-bash shells.

  • Property mode set to 100755
File size: 838 bytes
Line 
1#!/bin/sh
2
3usage()
4{
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
16
17if [ "$1" = "--" ]; then
18 usage
19elif [ "$#" -eq 1 ] || [ "$2" = "--" ]; then
20 pattern="$1"
21 shift
22 git grep -I -n "$pattern" "$@"
23elif [ "$#" -eq 2 ] || [ "$3" = "--" ]; then
24
25 if ( git status --porcelain | grep '^.[^ ]' ); then
26 echo "You have unstaged changes in your tree."
27 echo "Either stage them with 'git add', commit them,"
28 echo "or discard them with 'git checkout -- .'"
29 exit 1
30 fi
31
32 pattern="$1"
33 replacement="$2"
34 shift
35 shift
36 git grep -I -l "$pattern" "$@" | xargs sed -i "s/$pattern/$replacement/g"
37else
38 usage
39fi
Note: See TracBrowser for help on using the repository browser.