-
Notifications
You must be signed in to change notification settings - Fork 3
/
refactor
executable file
·53 lines (42 loc) · 1.19 KB
/
refactor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
## Runs refactoring script in loops and in order
## Version: 0.0
##
## Usage:
##
## refactor <what> <where> [<where>]
##
## Samples:
##
## refactor dojo/hitch2bind ../MyProjectFolder/UI/
if [ "$1" == "-h" -o "$1" == "--help" -o "$#" -lt 2 ]
then
sed -n "s;^## \?;;p" "${BASH_SOURCE[0]}"
cd ${0%/*}
exit 1
fi
script="$1"
shift
steps=$(ls -1 ${0%/*}/src/$script*) # v01, v02 etc...
! [ "$steps" ] && echo 1>&2 "[ERROR] unknown script name $1, check first param" && exit 1
echo 1>&2 "Steps found:"
echo 1>&2 "$steps"
# execute all steps
for s in $steps
do
# repeat the same script while it returns some replacements
# some scripts need to be run multiple times
# because of how their grasp is coded
# this is by design to simplify grasp scripts
while : ; do
echo 1>&2 -e "Running $s: ... "
# run script with , replace and count and folders
replaced_count=$($s -i -c --no-color --no-bold -r "$@" | awk -F "[:]" '{s+=$2};END{print s}')
echo 1>&2 -e "\treplaced: $replaced_count"
[ "$replaced_count" == "0" -o -z "$replaced_count" ] && break;
done
done
echo 1>&2 "Checking for broken files:"
# check
grasp -s "program" --silent -r "$@"
echo 1>&2 "done"