-
Notifications
You must be signed in to change notification settings - Fork 1
/
gucr.in
71 lines (58 loc) · 1.66 KB
/
gucr.in
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
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
m4_include(gu_tools.inc.sh)
usage() {
printf '%s\n' \
'gucr @VERSION@' \
'' \
'gucr creates new branches based from a specified branch or ' \
'from default ${BASED_BRANCH} branch.' \
'' \
'Usage: gucr [-h] [[-C] create] [-r remote] [-b branch]' \
'' \
' -h Show this usage.' \
' create: Name of the branch to create.' \
' remote: Name of the remote to base/create from.' \
' branch: Name of the branch to base/create from.'
}
# defaults
if [ -z "${REMOTE-}" ]; then
REMOTE=origin
fi
if [ -z "${BRANCH-}" ]; then
BRANCH=${BASED_BRANCH}
fi
# process flags
pointer=1
while [[ $pointer -le $# ]]; do
if [[ ${!pointer} != "-"* ]]; then ((pointer++)) # not a parameter flag so advance pointer
else
param=${!pointer}
((pointer_plus = pointer + 1))
slice_len=1
case $param in
# paramter-flags with arguments
-R|--create) CREATE=${!pointer_plus}; ((slice_len++));;
-r|--remote) REMOTE=${!pointer_plus}; ((slice_len++));;
-b|--branch) BRANCH=${!pointer_plus}; ((slice_len++));;
# binary flags
-h|--help) HELP=true;;
esac
# splice out pointer frame from positional list
[[ $pointer -gt 1 ]] \
&& set -- ${@:1:((pointer - 1))} ${@:((pointer + $slice_len)):$#} \
|| set -- ${@:((pointer + $slice_len)):$#};
fi
done
if [ ! -z "${HELP-}" ]; then
usage
exit 0
fi
if [ -z "${CREATE-}" ]; then
CREATE=$1
fi
set -e
if remote_avail ${REMOTE}; then
git_cleaning && git checkout ${BRANCH} && git pull
git checkout ${BRANCH} -b ${CREATE}
fi
# vim: set et ts=2 sw=2: