-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitamselect
More file actions
executable file
·60 lines (45 loc) · 1.02 KB
/
gitamselect
File metadata and controls
executable file
·60 lines (45 loc) · 1.02 KB
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
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
# gitamselect
shopt -s extglob
declare usagestr=$(
cat <<EOF
$(basename $0) dir min max
Description:
Selectively applies numbered patch files in dir from the min up to
and including the max.
This script assumes that patch files will be named with a leading
number separated from the rest of the filename by a hyphen, and
ending with ".patch" e.g.
0003-this-is-a-patch-file.patch
Arguments:
dir - directory containing the patch files
min - lowest number patch
max - highest number patch
\0
EOF
)
usage() {
echo -e "$usagestr"
exit 1
}
main() {
declare dir="$1"
declare -i min=$2
declare -i max=$3
declare p
declare pat
declare -i num
[ "$1" == "-h" ] && usage
for p in $(ls -1 $dir/*.patch); do
pat=$(basename $p)
# convert the number to base 10
if [ "${pat:0:1}" != "0" ]; then
pat=$(echo "$pat" | cut -d'-' -f2-)
fi
printf -v num "%d" $((10#$(echo $pat | cut -d'-' -f1)))
([ $num -ge $min ] && [ $num -le $max ]) && git am "$p"
done
}
main $@
exit 0