Skip to content

Commit 284c94b

Browse files
committed
Improved Completions
1 parent 56d7280 commit 284c94b

File tree

4 files changed

+167
-5
lines changed

4 files changed

+167
-5
lines changed

.goreleaser.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ archives:
2727
- id: tar.gz
2828
format: tar.gz
2929
files:
30-
- src: misc/completion/enma-completion.sh
30+
- src: misc/completions/enma-completion.sh
3131
dst: completions/enma-completion.sh
32+
- src: misc/completions/zsh/_enma
33+
dst: completions/zsh/_enma
34+
- src: misc/completions/bash/enma-completion.bash
35+
dst: completions//bash/enma-completion.bash
3236

3337
checksum:
3438
name_template: "{{ .ProjectName }}_checksums.txt"
@@ -46,10 +50,8 @@ brews:
4650
install: |
4751
bin.install "enma"
4852
extra_install: |
49-
cp "completions/enma-completion.sh", "completions/enma.zsh"
50-
51-
bash_completion.install "completions/enma-completion.sh" => "enma"
52-
zsh_completion.install "completions/enma.zsh" => "_enma"
53+
bash_completion.install "completions/bash/enma-completion.bash" => "enma"
54+
zsh_completion.install "completions/zsh/_enma" => "_enma"
5355
test: |
5456
system "#{bin}/enma", "--version"
5557
commit_author:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -------- Bash Section --------
2+
_enma_bash() {
3+
local cur prev words cword
4+
_init_completion -n : || return
5+
6+
local subcommands="init hotload watch"
7+
local global_opts="--help -h --version -v --config -c"
8+
local opts
9+
10+
if [[ ${COMP_CWORD} -eq 1 ]]; then
11+
COMPREPLY=( $(compgen -W "${subcommands} ${global_opts}" -- "$cur") )
12+
return 0
13+
fi
14+
15+
local subcmd=${COMP_WORDS[1]}
16+
case "$subcmd" in
17+
init)
18+
opts="--help -h --mode --file"
19+
;;
20+
hotload)
21+
opts="--daemon --build --signal --watch-dir --pre-build --post-build --working-dir --placeholder --args-path-style --build-at-start --check-content-diff --absolute-path --timeout --delay --retry --pattern-regex --include-ext --exclude-ext --exclude-dir --ignore-dir-regex --ignore-file-regex --default-ignores --enmaignore --logs --pid"
22+
;;
23+
watch)
24+
opts="--command --watch-dir --pre-cmd --post-cmd --working-dir --placeholder --args-path-style --check-content-diff --absolute-path --timeout --delay --retry --pattern-regex --include-ext --exclude-ext --exclude-dir --ignore-dir-regex --ignore-file-regex --default-ignores --enmaignore --logs --pid"
25+
;;
26+
*)
27+
opts=$global_opts
28+
;;
29+
esac
30+
31+
COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
32+
}
33+
34+
complete -F _enma_bash enma

misc/completions/zsh/_enma

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#compdef enma
2+
3+
_enma() {
4+
local context state state_descr line
5+
typeset -A opt_args
6+
7+
local -a subcommands
8+
subcommands=(
9+
'init:Initialize configuration'
10+
'hotload:Watch & reload daemon'
11+
'watch:Watch & run commands'
12+
'--help:Show help'
13+
'--version:Show version'
14+
'--config:Define enma.toml'
15+
)
16+
17+
_arguments -C \
18+
'1:command:->subcmd' \
19+
'*::options:->args'
20+
21+
case $state in
22+
subcmd)
23+
_describe 'subcommand' subcommands
24+
;;
25+
args)
26+
case $words[1] in
27+
init)
28+
_values 'init options' \
29+
'--help[Show help]' \
30+
'--mode[Specify mode <hotload|watch|enmaignore>]:mode:(hotload watch enmaignore)' \
31+
'--file[Specify output config file]:file:_files'
32+
;;
33+
hotload)
34+
if [[ "$OSTYPE" == (linux*|darwin*|freebsd*|openbsd*|netbsd*) ]]; then
35+
_values 'hotload options' \
36+
'--help[Show help]' \
37+
'--daemon[Daemon command]:cmd:_command_names' \
38+
'--build[Build command]:cmd:_command_names' \
39+
'--signal[ (optional) signal to stop daemon command]:sig:( SIGTERM SIGKILL SIGHUP SIGUSR1 SIGUSR2 SIGINT )' \
40+
'--watch-dir[ (optional) Directories to watch]:dir:_files -/' \
41+
'--pre-build[ (optional) Pre-build command]:cmd:_command_names' \
42+
'--post-build[ (optional) Post-build command]:cmd:_command_names' \
43+
'--working-dir[ (optional) Working directory]:dir:_files -/' \
44+
'--placeholder[ (optional) Placeholder token]:token:' \
45+
'--args-path-style[ (optional) Filepath style]:style:(dir base ext)' \
46+
'--build-at-start[ (optional) Build at startup]:bool:(on off)' \
47+
'--check-content-diff[ (optional) Only on content change]:bool:(on off)' \
48+
'--absolute-path[ (optional) Use absolute path]:bool:(on off)' \
49+
'--timeout[ (optional) Timeout duration]:string:' \
50+
'--delay[ (optional) Delay after build]:string:' \
51+
'--retry[ (optional) Retry count]:int:' \
52+
'--pattern-regex[ (optional) Regex to match files]:regex:' \
53+
'--include-ext[ (optional) File extensions to include]' \
54+
'--exclude-ext[ (optional) File extensions to exclude]' \
55+
'--exclude-dir[ (optional) Dirs to exclude]:dir:_files -/' \
56+
'--ignore-dir-regex[ (optional) Dir ignore regex]' \
57+
'--ignore-file-regex[ (optional) File ignore regex]' \
58+
'--default-ignores[ (optional) Specify default ignore volume <max|min|none>]:mode:(maximum minimal none)' \
59+
'--enmaignore[ (optional) Ignore file list]:file:_files' \
60+
'--logs[ (optional) Log file]:file:_files' \
61+
'--pid[ (optional) PID file]:file:_files'
62+
else
63+
_values 'hotload options' \
64+
'--help[Show help]' \
65+
'--daemon[Daemon command]:cmd:_command_names' \
66+
'--build[Build command]:cmd:_command_names' \
67+
'--signal[ (optional) signal to stop daemon command]:sig:( SIGTERM SIGKILL SIGHUP SIGINT )' \
68+
'--watch-dir[ (optional) Directories to watch]:dir:_files -/' \
69+
'--pre-build[ (optional) Pre-build command]:cmd:_command_names' \
70+
'--post-build[ (optional) Post-build command]:cmd:_command_names' \
71+
'--working-dir[ (optional) Working directory]:dir:_files -/' \
72+
'--placeholder[ (optional) Placeholder token]:token:' \
73+
'--args-path-style[ (optional) Filepath style]:style:(dir base ext)' \
74+
'--build-at-start[ (optional) Build at startup]:bool:(on off)' \
75+
'--check-content-diff[ (optional) Only on content change]:bool:(on off)' \
76+
'--absolute-path[ (optional) Use absolute path]:bool:(on off)' \
77+
'--timeout[ (optional) Timeout duration]:string:' \
78+
'--delay[ (optional) Delay after build]:string:' \
79+
'--retry[ (optional) Retry count]:int:' \
80+
'--pattern-regex[ (optional) Regex to match files]:regex:' \
81+
'--include-ext[ (optional) File extensions to include]' \
82+
'--exclude-ext[ (optional) File extensions to exclude]' \
83+
'--exclude-dir[ (optional) Dirs to exclude]:dir:_files -/' \
84+
'--ignore-dir-regex[ (optional) Dir ignore regex]' \
85+
'--ignore-file-regex[ (optional) File ignore regex]' \
86+
'--default-ignores[ (optional) Specify default ignore volume <max|min|none>]:mode:(maximum minimal none)' \
87+
'--enmaignore[ (optional) Ignore file list]:file:_files' \
88+
'--logs[ (optional) Log file]:file:_files' \
89+
'--pid[ (optional) PID file]:file:_files'
90+
fi
91+
;;
92+
watch)
93+
_values 'watch options' \
94+
'--help[Show help]' \
95+
'--command[Command to run]:cmd:_command_names' \
96+
'--watch-dir[ (optional) Directories to watch]:dir:_files -/' \
97+
'--pre-cmd[ (optional) Pre-command]:cmd:_command_names' \
98+
'--post-cmd[ (optional) Post-command]:cmd:_command_names' \
99+
'--working-dir[ (optional) Working directory]:dir:_files -/' \
100+
'--placeholder[ (optional) Placeholder token]:token:' \
101+
'--args-path-style[ (optional) Filepath style]:style:(dir base ext full)' \
102+
'--check-content-diff[ (optional) Only on content change]:bool:(on off)' \
103+
'--absolute-path[ (optional) Use absolute path]:bool:(on off)' \
104+
'--timeout[ (optional) Timeout duration]:string:' \
105+
'--delay[ (optional) Delay duration]:string:' \
106+
'--retry[ (optional) Retry count]:int:' \
107+
'--pattern-regex[ (optional) Regex to match files]:regex:' \
108+
'--include-ext[ (optional) File extensions to include]' \
109+
'--exclude-ext[ (optional) File extensions to exclude]' \
110+
'--exclude-dir[ (optional) Dirs to exclude]:dir:_files -/' \
111+
'--ignore-dir-regex[ (optional) Dir ignore regex]' \
112+
'--ignore-file-regex[ (optional) File ignore regex]' \
113+
'--enmaignore[ (optional) Ignore file list]:file:_files' \
114+
'--logs[ (optional) Log file]:file:_files' \
115+
'--pid[ (optional) PID file]:file:_files'
116+
;;
117+
*)
118+
_message 'No subcommand matched.'
119+
;;
120+
esac
121+
;;
122+
esac
123+
}
124+
125+
compdef _enma enma
126+
return 0

0 commit comments

Comments
 (0)