From 6fe8b6a7f84445b99c816c97eaa24b10f0286923 Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Sat, 10 Oct 2020 20:47:39 -0700 Subject: [PATCH] bin: Add -f/--force flag to git-branch-prune --- bin/git-branch-prune | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bin/git-branch-prune b/bin/git-branch-prune index 9068673..bb7b399 100755 --- a/bin/git-branch-prune +++ b/bin/git-branch-prune @@ -10,6 +10,24 @@ export USAGE=' set -euo pipefail +POSITIONAL=() +FORCE=0 +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -f|--force) + FORCE=1 + shift + ;; + *) + POSITIONAL+=("$1") + shift + ;; + esac +done +set -- "${POSITIONAL[@]}" + case "$#" in 0) remote='origin' @@ -33,6 +51,13 @@ if [ -z "${pruned_branches}" ]; then exit 0 fi -vipe <<< "${pruned_branches}" | \ + +if [ "${FORCE}" -eq 1 ]; then + selector='cat' +else + selector='vipe' +fi + +"${selector}" <<< "${pruned_branches}" | \ awk '{print $1}' | \ xargs git branch -D