aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/git-branch-cleanup
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2019-12-18 09:43:33 +0100
committerPatrick Spek <p.spek@tyil.nl>2019-12-18 09:43:33 +0100
commit7eaa516aecfb59b10f38a5c3652ed55adcd20792 (patch)
tree663c57e643ca0d229199635748160591eb76c7ea /.local/bin/git-branch-cleanup
parent565f3ec7ce2e7147081f755350073c267fb585b3 (diff)
Include git-branch-cleanup script properly this time
Diffstat (limited to '.local/bin/git-branch-cleanup')
-rwxr-xr-x.local/bin/git-branch-cleanup71
1 files changed, 71 insertions, 0 deletions
diff --git a/.local/bin/git-branch-cleanup b/.local/bin/git-branch-cleanup
new file mode 100755
index 0000000..5e86714
--- /dev/null
+++ b/.local/bin/git-branch-cleanup
@@ -0,0 +1,71 @@
+#! /usr/bin/env sh
+
+main()
+{
+ # Handle opts
+ opts "$@"
+ shift "$OPTS"
+ unset OPTS
+
+ # Show help
+ [ "$OPT_HELP_ONLY" ] && usage && exit 0
+
+ # Get a list of branches
+ buffer=$(mktemp)
+
+ git branch --merged \
+ | awk '{ print $NF }' \
+ | grep -Ev "^master$" \
+ > "$buffer"
+
+ count=$(wc -l < "$buffer")
+
+ if [ $count -lt 1 ]
+ then
+ printf "No branches to remove\n"
+ exit 0
+ fi
+
+ printf "Going to remove the following %s branches:\n" "$count"
+ cat -- "$buffer"
+
+ printf "\n^C to cancel...\n"
+ read
+
+ while read -r branch
+ do
+ git branch -D -- "$branch"
+ done < "$buffer"
+}
+
+opts()
+{
+ OPTS=0
+
+ while getopts ":h" opt
+ do
+ case "$opt" in
+ h) OPT_HELP_ONLY=1 ;;
+ *)
+ printf "Invalid option passed: %s\n" "$OPTARG" >&2
+ ;;
+ esac
+ done
+
+ unset opt
+}
+
+usage()
+{
+ cat <<EOF
+Usage:
+ $(basename "$0") -h
+
+Clean up merged branches.
+
+Options:
+ -h Show this help text and exit.
+EOF
+}
+
+main "$@"