Last change
on this file since 77578e8 was 8fd0675f, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago |
Update files with /bin/sh shebang and an extra space
|
-
Property mode
set to
100755
|
File size:
1.2 KB
|
Line | |
---|
1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # SPDX-FileCopyrightText: 2019 Jiří Zárevúcky
|
---|
4 | #
|
---|
5 | # SPDX-License-Identifier: BSD-3-Clause
|
---|
6 | #
|
---|
7 |
|
---|
8 | usage()
|
---|
9 | {
|
---|
10 | echo "Usage:"
|
---|
11 | echo
|
---|
12 | echo " $0 search_pattern [-- <pathspec> ]"
|
---|
13 | echo " $0 search_pattern replacement [-- <pathspec> ]"
|
---|
14 | echo
|
---|
15 | echo "Pattern should be a basic regexp as accepted by grep and sed."
|
---|
16 | echo "For information on pathspec syntax, see git documentation."
|
---|
17 | echo
|
---|
18 | exit 1
|
---|
19 | }
|
---|
20 |
|
---|
21 | check_unstaged()
|
---|
22 | {
|
---|
23 | if ( git status --porcelain | grep '^.[^ ]' ); then
|
---|
24 | echo "You have unstaged changes in your tree."
|
---|
25 | echo "Either stage them with 'git add', commit them,"
|
---|
26 | echo "or discard them with 'git checkout -- .'"
|
---|
27 | exit 1
|
---|
28 | fi
|
---|
29 | }
|
---|
30 |
|
---|
31 | _slashify()
|
---|
32 | {
|
---|
33 | # Some shells have shoddy handling of backslashes in echo.
|
---|
34 | printf '%s\n' "$1" | sed 's/\([^\\]\)\//\1\\\//g'
|
---|
35 | }
|
---|
36 |
|
---|
37 | if [ "$1" = "--" ]; then
|
---|
38 | usage
|
---|
39 | elif [ "$1" = "-d" ]; then
|
---|
40 | check_unstaged
|
---|
41 |
|
---|
42 | pattern=`_slashify "$2"`
|
---|
43 | shift
|
---|
44 | shift
|
---|
45 | git grep -I -l "$pattern" "$@" | xargs sed -i "/$pattern/d"
|
---|
46 |
|
---|
47 | elif [ "$#" -eq 1 ] || [ "$2" = "--" ]; then
|
---|
48 | pattern=`_slashify "$1"`
|
---|
49 | shift
|
---|
50 | git grep -I -n "$pattern" "$@"
|
---|
51 | elif [ "$#" -eq 2 ] || [ "$3" = "--" ]; then
|
---|
52 | check_unstaged
|
---|
53 |
|
---|
54 | pattern=`_slashify "$1"`
|
---|
55 | replacement=`_slashify "$2"`
|
---|
56 | shift
|
---|
57 | shift
|
---|
58 | git grep -I -l "$pattern" "$@" | xargs sed -i "s/$pattern/$replacement/g"
|
---|
59 | else
|
---|
60 | usage
|
---|
61 | fi
|
---|
Note:
See
TracBrowser
for help on using the repository browser.