From 28e20b21098eaa7d47e404e63f60772b6e9363d5 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Tue, 5 Nov 2019 15:32:19 +0100
Subject: Add git-branch-cleaning script
---
.local/bin/git-branch-cleaning | 63 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100755 .local/bin/git-branch-cleaning
(limited to '.local/bin/git-branch-cleaning')
diff --git a/.local/bin/git-branch-cleaning b/.local/bin/git-branch-cleaning
new file mode 100755
index 0000000..8c728be
--- /dev/null
+++ b/.local/bin/git-branch-cleaning
@@ -0,0 +1,63 @@
+#! /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"
+
+ printf "Going to remove the following %s branches:\n" "$(wc -l < "$buffer")"
+ 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 <