Skip to content

Instantly share code, notes, and snippets.

@marzocchi
Created September 21, 2016 12:45
Show Gist options
  • Save marzocchi/d25ba65d403a27f9929c6b05c74a2fe2 to your computer and use it in GitHub Desktop.
Save marzocchi/d25ba65d403a27f9929c6b05c74a2fe2 to your computer and use it in GitHub Desktop.
Delete GIT branches using a dialog with multiple selection
#!/usr/bin/env zsh
set -e
ANSWER_FILE=$(mktemp)
function ask() {
local -a choices
for branch in $(git branch); do
choices+="$branch $branch off"
done
dialog --separate-output --checklist "Choose one or more branches" 10 0 0 -- ${=choices} 2> ${ANSWER_FILE}
local exit_status=$?
}
ask
clear
read REPLY\?"Really delete: $(cat ${ANSWER_FILE} | xargs) (y/N): "
if [[ "$REPLY" != "y" ]]; then
exit 1
fi
for i in `cat "${ANSWER_FILE}"`; do
git branch -D "$i"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment