diff --git a/bin/git-branch-prune b/bin/git-branch-prune new file mode 100755 index 0000000..9068673 --- /dev/null +++ b/bin/git-branch-prune @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +export USAGE=' +' + +# This is the recommended pattern from `man git-sh-setup`. +# +# shellcheck disable=SC1090 +. "$(git --exec-path)/git-sh-setup" + +set -euo pipefail + +case "$#" in + 0) + remote='origin' + ;; + 1) + remote="$1" + ;; + *) usage ;; +esac + +git remote prune "${remote}" + +# This grep "fails" if there are no matches, so temporarily disable error +# checking. +set +e +pruned_branches=$(git branch -vv | grep ': gone]') +set -e + +if [ -z "${pruned_branches}" ]; then + >&2 echo 'Nothing to do!' + exit 0 +fi + +vipe <<< "${pruned_branches}" | \ + awk '{print $1}' | \ + xargs git branch -D diff --git a/git/config b/git/config index d2219a6..3225605 100644 --- a/git/config +++ b/git/config @@ -23,7 +23,7 @@ default = simple ap = add -p b = branch bn = symbolic-ref --short HEAD -bp = !git remote prune origin && git branch -vv | grep ': gone]' | vipe | awk '{print $1}' | xargs git branch -D +bp = branch-prune bv = branch -vv c = commit chk = commit -a -n -m 'CHECKPOINT'