Files
dotfiles/home/dot_config/fish/functions/wtr.fish
Xevion 8804b425fb feat: add git worktree management utilities for Fish and Bash
Add comprehensive worktree tooling with FZF integration:
- wtb: create branch worktree with gitignored file cloning
- wtcd/wtr: interactive picker and multi-remove with FZF
- wtf/wth: feature/hotfix branch shortcuts
- wts/wtl: status overview and listing
- Automatic .worktrees/ organization and .gitignore management
2026-01-23 13:42:30 -06:00

41 lines
1.3 KiB
Fish

function wtr --description "FZF-based git worktree remover (multi-select)"
set -l root (git rev-parse --show-toplevel 2>/dev/null)
if test -z "$root"
echo "Not in a git repository" >&2
return 1
end
# Get the main worktree path to exclude it
set -l main_wt (git worktree list --porcelain | grep '^worktree ' | head -n1 | string replace 'worktree ' '')
# Select worktrees with fzf (excluding main)
set -l selected (git worktree list | grep -v "^$main_wt " | fzf --multi --height=40% --reverse \
--header="Select worktrees to remove (Tab to multi-select)" \
--preview="git -C {1} log --oneline -5 2>/dev/null || echo 'No commits'")
if test -z "$selected"
echo "No worktrees selected"
return 0
end
echo "Will remove the following worktrees:"
for line in $selected
set -l wt_path (echo "$line" | awk '{print $1}')
echo " - $wt_path"
end
echo ""
read -P "Confirm removal? [y/N] " -n 1 confirm
echo ""
if string match -qi 'y' "$confirm"
for line in $selected
set -l wt_path (echo "$line" | awk '{print $1}')
echo "Removing $wt_path..."
git worktree remove "$wt_path"
end
else
echo "Cancelled"
end
end