-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitBranchList
executable file
·51 lines (44 loc) · 1.06 KB
/
gitBranchList
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
#!/bin/bash
######################################################
# Display a list of avaiable git branches in the #
# terminal #
######################################################
source ~/bash-helpers/_colours
git fetch
# Show local or remote according to flags set
while getopts ":lr" opt; do
case $opt in
l)
showLocal=true
;;
r)
showRemote=true
;;
?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# If no flags are set, show both
if [[ $OPTIND -eq 1 ]]; then
echo "No options were passed"
showLocal=true
showRemote=true
fi
if [[ -n $showLocal ]]; then
echo "Local branches:"
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads); do
echo "${GREEN} ${branch}${RESTORE}"
done
fi
if [[ -n $showRemote ]]; then
if [[ -n $showLocal ]]; then
echo ""
fi
echo "Remote branches:"
origin="origin/"
for branch in $(git for-each-ref --format='%(refname:short)' refs/remotes); do
echo "${GREEN} ${branch//$origin/}${RESTORE}"
done
fi