Last active
April 6, 2020 16:56
-
-
Save camsteffen/1920a4e53897b3336c176542383cd5e8 to your computer and use it in GitHub Desktop.
Deletes all merged branches with an option to edit the list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
setopt EXTENDED_GLOB | |
# get list of all merged branches | |
branches=(${(f)"$(git branch --format '%(refname:short)' --merged)"}) | |
# remove current branch | |
current=("$(git branch --show-current)") | |
branches=(${branches:|current}) | |
# remove master|develop branches | |
branches=(${branches:#(master|dev*)}) | |
if ((${#branches} == 0)) { | |
print 'No merged branches' | |
exit | |
} | |
print -- "${(F)branches}\n" | |
read '?Delete these merged branches? ' | |
integer dodelete=0 | |
case $REPLY in | |
'e') | |
# edit branches | |
branches=(${(f)$(vipe <<< ${(F)branches})}) | |
if ((? == 0 && ${#branches} > 0)) { | |
dodelete=1 | |
} | |
;; | |
'y') | |
dodelete=1 | |
;; | |
esac | |
if ! ((dodelete)) { | |
print 'No branches deleted' | |
exit | |
} | |
git branch -d "$branches[@]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment