-
Notifications
You must be signed in to change notification settings - Fork 0
/
gbm.sh
executable file
·57 lines (48 loc) · 1.22 KB
/
gbm.sh
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
#!/bin/sh
GIT_COLOR="#f14e32"
git_color_text () {
gum style --foreground "$GIT_COLOR" "$1"
}
get_branches () {
if [ ${1+x} ]; then
gum choose --selected.foreground="$GIT_COLOR" --limit="$1" $(git branch --format="%(refname:short)")
else
gum choose --selected.foreground="$GIT_COLOR" --no-limit $(git branch --format="%(refname:short)")
fi
}
git rev-parse --git-dir > /dev/null 2>&1
if [ $? -ne 0 ];
then
echo "$(git_color_text "!!") Must be run in a $(git_color_text "git") repo"
exit 1
fi
gum style \
--border normal \
--margin "1" \
--padding "1" \
--border-foreground "$GIT_COLOR" \
"$(git_color_text 'Git') Branch Manager"
echo "Choose $(git_color_text 'branches') to operate on:"
branches=$(get_branches)
echo ""
echo "Choose a $(git_color_text "command"):"
command=$(gum choose --cursor.foreground="$GIT_COLOR" rebase delete update)
echo ""
echo $branches | tr " " "\n" | while read -r branch
do
case $command in
rebase)
base_branch=$(get_branches 1)
git fetch origin
git checkout "$branch"
git rebase "origin/$base_branch"
;;
delete)
git branch -D "$branch"
;;
update)
git checkout "$branch"
git pull --ff-only
;;
esac
done