Skip to content

Commit d60ded7

Browse files
committed
Clean up git-prune-branches
* Quote bare variables * Standardize on spaces for indentations * Update `` to $()
1 parent 438df8c commit d60ded7

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

bin/git-prune-branches

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# git-prune-branches
44
#
@@ -14,40 +14,42 @@
1414
# License: MIT
1515
# Original source: https://github.com/jut-io/git-scripts/blob/master/bin/git-prune-branches
1616

17-
merged=`git branch --no-color --merged master | grep -v master | sed 's/\*/ /'`
17+
merged=$(git branch --no-color --merged master | grep -v master | sed 's/\*/ /')
1818

1919
if [ ! -z "$merged" ] ; then
2020
echo "Deleting the following merged branches:"
2121
for branch in $merged ; do
22-
echo " " $branch
22+
echo " " "$branch"
2323
done
2424

2525
all=n
2626
delete=n
2727
for branch in $merged ; do
28-
if [ $all = 'n' ] ; then
29-
delete=n
30-
read -p "Delete $branch (y=yes, n=no, a=all)? " prompt
31-
echo "all=$all delete=$delete prompt=$prompt"
32-
if [ "$prompt" = 'a' ] ; then
33-
delete=y
34-
all=y
35-
elif [ "$prompt" = 'y' ]; then
36-
delete=y
37-
fi
38-
fi
28+
if [ $all = 'n' ] ; then
29+
delete=n
30+
# shellcheck disable=SC2162
31+
read -p "Delete $branch (y=yes, n=no, a=all)? " prompt
32+
echo "all=$all delete=$delete prompt=$prompt"
33+
if [ "$prompt" = 'a' ] ; then
34+
delete=y
35+
all=y
36+
elif [ "$prompt" = 'y' ]; then
37+
delete=y
38+
fi
39+
fi
3940

40-
if [ "$delete" = 'y' ] ; then
41-
git branch -d $branch
42-
fi
41+
if [ "$delete" = 'y' ] ; then
42+
git branch -d "$branch"
43+
fi
4344
done
4445
fi
4546

46-
remotes=`git remote`
47+
remotes=$(git remote)
4748
for remote in $remotes ; do
4849
prompt=n
50+
# shellcheck disable=SC2162
4951
read -p "Prune deleted branches from remote '$remote' (y=yes n=no)? " prompt
5052
if [ "$prompt" = 'y' ] ; then
51-
git remote prune $remote
53+
git remote prune "$remote"
5254
fi
5355
done

0 commit comments

Comments
 (0)