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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Bash completion for git-gardener
_git_gardener() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Check if we should complete branch names
if [[ ${prev} == "-b" || ${prev} == "--branch" ]]; then
# Only complete branch names, no files
local branches=$(git branch 2>/dev/null | sed 's/^[ *]*//')
COMPREPLY=( $(compgen -W "${branches}" -- ${cur}) )
return 0
fi
# Main commands
local commands="init add list config clean pull-all tui cd remove prune move completion help"
# Options for different commands
case "${COMP_CWORD}" in
1)
# Complete main commands
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
;;
*)
# Command-specific completion
case "${COMP_WORDS[1]}" in
cd)
# Complete worktree names for cd command
if [[ ${COMP_CWORD} -eq 2 ]]; then
local worktrees=$(git-gardener list --names-only 2>/dev/null)
COMPREPLY=( $(compgen -W "${worktrees}" -- ${cur}) )
fi
;;
add)
case "${prev}" in
-b|--branch)
# Complete branch names from git
local branches=$(git branch 2>/dev/null | sed 's/^[ *]*//')
COMPREPLY=( $(compgen -W "${branches}" -- ${cur}) )
# Disable file completion for branch names
return 0
;;
-p|--path)
# Complete directory paths
COMPREPLY=( $(compgen -d -- ${cur}) )
;;
--upstream)
# Complete remote names
local remotes=$(git remote 2>/dev/null)
COMPREPLY=( $(compgen -W "${remotes}" -- ${cur}) )
;;
*)
# Complete options
local opts="-b --branch -p --path --upstream -c --create-branch -h --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
esac
;;
list)
# Complete list options
local opts="-a --all --names-only -h --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
config)
if [[ ${COMP_CWORD} -eq 2 ]]; then
# Complete config subcommands
COMPREPLY=( $(compgen -W "view set" -- ${cur}) )
elif [[ ${COMP_CWORD} -eq 3 && "${COMP_WORDS[2]}" == "set" ]]; then
# Complete config keys
local keys="root_dir editor post_create"
COMPREPLY=( $(compgen -W "${keys}" -- ${cur}) )
fi
;;
clean)
# Complete clean options
local opts="--merged --stale --force -h --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
pull-all)
case "${prev}" in
-j|--parallel)
# No completion for numbers
;;
*)
local opts="-j --parallel -h --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
esac
;;
tui)
# Complete TUI options
local opts="--fullscreen --no-mouse -h --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
remove)
# Complete worktree names for remove command
if [[ ${COMP_CWORD} -eq 2 ]]; then
local worktrees=$(git-gardener list --names-only 2>/dev/null)
COMPREPLY=( $(compgen -W "${worktrees}" -- ${cur}) )
else
# Complete options
local opts="-f --force -h --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
fi
;;
prune)
# Complete prune options
local opts="--dry-run -h --help"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
move)
if [[ ${COMP_CWORD} -eq 2 ]]; then
# Complete worktree names for first argument
local worktrees=$(git-gardener list --names-only 2>/dev/null)
COMPREPLY=( $(compgen -W "${worktrees}" -- ${cur}) )
elif [[ ${COMP_CWORD} -eq 3 ]]; then
# Complete directory paths for second argument
COMPREPLY=( $(compgen -d -- ${cur}) )
fi
;;
completion)
# Complete shell names
if [[ ${COMP_CWORD} -eq 2 ]]; then
COMPREPLY=( $(compgen -W "bash zsh fish" -- ${cur}) )
fi
;;
*)
# Global options
local opts="-v --verbose -h --help -V --version"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
esac
;;
esac
}
# Register the completion function
complete -F _git_gardener -o nosort -o nospace git-gardener