~kris/dots

srice

ref: 178c9a25a484ead715392d50e21d03df486b8b41 srice/.local/bin/gbd -rwxr-xr-x 750 bytes
178c9a25 — Kris Yotam conky: sync proper config from moirai (was the greenred variant) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
# gbd -- interactive git branch deletion with fzf
set -eu

protected="main master develop"

branches=$(git branch --sort=-committerdate | sed 's/^..//' | grep -v "^$(git branch --show-current)$")

for p in $protected; do
    branches=$(echo "$branches" | grep -v "^${p}$" || true)
done

if [ -z "$branches" ]; then
    echo "No deletable branches"
    exit 0
fi

selected=$(echo "$branches" | fzf -m \
    --header "Select branches to delete (TAB to multi-select)" \
    --preview 'git log --oneline --graph --color=always {} | head -20')

if [ -n "$selected" ]; then
    echo "$selected" | while read -r branch; do
        git branch -d "$branch" 2>/dev/null || echo "Cannot delete $branch (not fully merged, use -D to force)"
    done
fi