-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-mark.sh
More file actions
41 lines (36 loc) · 770 Bytes
/
git-mark.sh
File metadata and controls
41 lines (36 loc) · 770 Bytes
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
#!/bin/bash
if [ -z "$1" ]; then
printf "Fatal: argument needed (a mark name)" >&2 &&
exit 1
fi
add=true
if [ "${1:0:1}" == "-" ]; then
tag_char='+'
mark="${1:1}"
add=false
else
if [[ "${1:0:1}" =~ [[:punct:]] ]]; then
tag_char="${1:0:1}"
mark="${1:1}"
else
tag_char='+'
mark="$1"
fi
fi
shift 1
if [ -z "${1:-}" ]; then
branches="$(git branch --show-current)"
else
branches=$(printf '%s\n' "$@")
fi
for branch in $branches; do
# branch starts with $tag_char
if [[ $branch == $tag_char$mark/* ]]; then
[[ $add == true ]] &&
continue # already marked
git branch -m "$branch" ${branch#$tag_char$mark/} # remove the mark
elif [[ $add == false ]]; then continue
else
git branch -m "$branch" "$tag_char$mark/"${branch#$tag_char*/}
fi
done