#! /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 <