Skip to content

Commit a261d1f

Browse files
committed
feat(completions): add --help flag to all subcommands
Add -h/--help completion for subcommands that were missing it: - zsh/bash/fish: lock, unlock, move, prune, repair - bash: clone
1 parent c2f20c1 commit a261d1f

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

completions/git-wt.bash

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ _git_wt() {
1818

1919
case "$cmd" in
2020
clone)
21-
# clone takes a URL and optional folder name
22-
# No completion for URLs, but complete local paths for folder name
23-
if [[ $cword -eq 3 ]]; then
21+
if [[ $cur == -* ]]; then
22+
COMPREPLY=($(compgen -W "--help -h" -- "$cur"))
23+
elif [[ $cword -eq 3 ]]; then
24+
# No completion for URLs, but complete local paths for folder name
2425
_filedir -d
2526
fi
2627
;;
@@ -71,10 +72,14 @@ _git_wt() {
7172
fi
7273
;;
7374
lock | unlock | move | prune | repair)
74-
# Pass-through commands - complete with worktree paths
75-
local worktrees
76-
worktrees=$(git worktree list --porcelain 2>/dev/null | grep '^worktree ' | sed 's/^worktree //' | grep -v '\.bare$')
77-
COMPREPLY=($(compgen -W "$worktrees" -- "$cur"))
75+
if [[ $cur == -* ]]; then
76+
COMPREPLY=($(compgen -W "--help -h" -- "$cur"))
77+
else
78+
# Pass-through commands - complete with worktree paths
79+
local worktrees
80+
worktrees=$(git worktree list --porcelain 2>/dev/null | grep '^worktree ' | sed 's/^worktree //' | grep -v '\.bare$')
81+
COMPREPLY=($(compgen -W "$worktrees" -- "$cur"))
82+
fi
7883
;;
7984
esac
8085
}

completions/git-wt.fish

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ complete -c git-wt -n '__fish_git_wt_using_command list' -s h -l help -d 'Show h
8585
complete -c git-wt -n '__fish_git_wt_using_command migrate' -s h -l help -d 'Show help'
8686

8787
# lock/unlock/move/prune/repair completions
88+
complete -c git-wt -n '__fish_git_wt_using_command lock' -s h -l help -d 'Show help'
8889
complete -c git-wt -n '__fish_git_wt_using_command lock' -xa '(__fish_git_wt_worktrees)'
90+
complete -c git-wt -n '__fish_git_wt_using_command unlock' -s h -l help -d 'Show help'
8991
complete -c git-wt -n '__fish_git_wt_using_command unlock' -xa '(__fish_git_wt_worktrees)'
92+
complete -c git-wt -n '__fish_git_wt_using_command move' -s h -l help -d 'Show help'
9093
complete -c git-wt -n '__fish_git_wt_using_command move' -xa '(__fish_git_wt_worktrees)'
94+
complete -c git-wt -n '__fish_git_wt_using_command prune' -s h -l help -d 'Show help'
9195
complete -c git-wt -n '__fish_git_wt_using_command prune' -xa '(__fish_git_wt_worktrees)'
96+
complete -c git-wt -n '__fish_git_wt_using_command repair' -s h -l help -d 'Show help'
9297
complete -c git-wt -n '__fish_git_wt_using_command repair' -xa '(__fish_git_wt_worktrees)'

completions/git-wt.zsh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ _git-wt() {
6363
'(-h --help)'{-h,--help}'[Show help]'
6464
;;
6565
lock|unlock|move|prune|repair)
66-
_arguments '*:worktree:__git_wt_worktrees'
66+
_arguments \
67+
'(-h --help)'{-h,--help}'[Show help]' \
68+
'*:worktree:__git_wt_worktrees'
6769
;;
6870
esac
6971
;;

0 commit comments

Comments
 (0)