Skip to content

Commit 0219960

Browse files
committed
cleanup by Claude
1 parent e1cf2d1 commit 0219960

1 file changed

Lines changed: 44 additions & 26 deletions

File tree

local/etc/uceap.d/completion.sh

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
function completion() {
2-
commands=("${funcs[@]//_/-}")
3-
if [ $# -eq 1 ]; then
4-
shell="$1"
5-
case "$shell" in
6-
bash)
7-
cat <<EOF
2+
# Validate arguments
3+
if [ $# -ne 1 ]; then
4+
echo "[error] Usage: completion <shell>" >&2
5+
return 1
6+
fi
7+
8+
# Convert function names to command names (replace _ with -)
9+
local commands=("${funcs[@]//_/-}")
10+
local shell="$1"
11+
12+
case "$shell" in
13+
bash)
14+
_generate_bash_completion "${commands[@]}"
15+
;;
16+
zsh)
17+
_generate_zsh_completion "${commands[@]}"
18+
;;
19+
*)
20+
echo "[error] Unsupported shell: $shell" >&2
21+
return 1
22+
;;
23+
esac
24+
}
25+
26+
function _generate_bash_completion() {
27+
cat <<EOF
828
_uceap_completions() {
929
local cur prev opts
1030
COMPREPLY=()
@@ -20,29 +40,27 @@ _uceap_completions() {
2040
}
2141
complete -F _uceap_completions uceap
2242
EOF
23-
;;
24-
zsh)
25-
echo '_uceap() {
26-
local -a commands
27-
commands=('"${commands[*]}"')
28-
if (( CURRENT == 2 )); then
29-
_arguments "1: :((help ${commands[*]}))"
30-
elif (( CURRENT == 3 )) && [[ $words[2] == help ]]; then
31-
_arguments "2: :(${commands[*]})"
32-
fi
3343
}
34-
compdef _uceap uceap'
35-
;;
36-
*)
37-
echo "[error] Unsupported shell: $shell"
38-
return 1
39-
;;
40-
esac
41-
else
42-
echo "[error] Invalid number of arguments"
43-
return 1
44+
45+
function _generate_zsh_completion() {
46+
cat <<EOF
47+
_uceap() {
48+
local -a commands
49+
commands=(${commands[*]})
50+
if (( CURRENT == 2 )); then
51+
_arguments "1: :((help \${commands[*]}))"
52+
return
53+
fi
54+
if (( CURRENT == 3 )); then
55+
if [[ \$words[2] == help ]]; then
56+
_arguments "2: :(\${commands[*]})"
57+
return
58+
fi
4459
fi
4560
}
61+
compdef _uceap uceap
62+
EOF
63+
}
4664

4765
_completion_desc="generate shell completion scripts"
4866
_completion_help='

0 commit comments

Comments
 (0)