Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions completions/_wt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#compdef wt

_wt_worktree_names() {
local -a names
# Skip first entry (main worktree), extract branch names from brackets
names=(${(f)"$(git worktree list 2>/dev/null | tail -n +2 | sed -n 's/.*\[\(.*\)\].*/\1/p')"})
compadd -a names
}

_wt_git_branches() {
local -a branches
branches=(${(f)"$(git branch -a 2>/dev/null | sed 's/^[* ]*//' | sed 's|remotes/origin/||' | sort -u)"})
compadd -a branches
}

_wt() {
local -a subcmds
subcmds=(
'new:Create new worktree'
'ls:List all worktrees with status'
'cd:Change to worktree (main if no name)'
'up:Run up commands (spin up dev environment)'
'down:Run down commands (spin down dev environment)'
'rm:Remove worktree'
'purge:Interactive cleanup of clean worktrees'
'prune:Clean up stale worktree references'
'config:Show path to config file'
'update:Update wt to latest version'
'uninstall:Uninstall wt-cli'
'version:Show version'
'help:Show help'
)

if (( CURRENT == 2 )); then
_describe 'command' subcmds
return
fi

case "${words[2]}" in
cd)
_wt_worktree_names
;;
rm)
if [[ "${words[CURRENT-1]}" == "-f" ]]; then
_wt_worktree_names
elif [[ "${words[CURRENT]}" == -* ]]; then
compadd -- -f
else
_wt_worktree_names
fi
;;
new)
case "${words[CURRENT-1]}" in
-b|--branch)
_wt_git_branches
;;
-p|--pr|-u|--up|-n|--no-cd)
# no completion
;;
*)
if [[ "${words[CURRENT]}" == -* ]]; then
compadd -- -b -p -u -n
fi
;;
esac
;;
esac
}

_wt "$@"
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ echo "Downloading wt.sh..."
curl -sSL "$BASE_URL/wt.sh" -o "$WT_SH"
chmod +x "$WT_SH"

# Download zsh completions
echo "Downloading zsh completions..."
mkdir -p "$WT_DIR/completions"
curl -sSL "$BASE_URL/completions/_wt" -o "$WT_DIR/completions/_wt"

# Create default config
if [[ ! -f "$CONFIG_FILE" ]]; then
mkdir -p "$CONFIG_DIR"
Expand Down
8 changes: 7 additions & 1 deletion wt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# wt - Git worktree management CLI
# https://github.com/jorgensandhaug/wt-cli

_WT_VERSION="1.0.0"
_WT_VERSION="1.1.0"

_wt_config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/wt"
_wt_config_file="$_wt_config_dir/config.json"
Expand Down Expand Up @@ -788,3 +788,9 @@ wt() {
fi
_wt_main "$@"
}

# zsh completion
if [[ -n "$ZSH_VERSION" ]]; then
fpath=(~/.wt/completions $fpath)
autoload -Uz compinit && compinit -C
fi
Loading