Repository navigation
Expand file tree
/
Copy pathcompletion.zsh
More file actions
111 lines (97 loc) · 2.8 KB
/
Copy pathcompletion.zsh
File metadata and controls
111 lines (97 loc) · 2.8 KB
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
#compdef crystal
_crystal() {
_crystal_commands() {
local -a commands
commands=(
"init:generate new crystal project"
"build:compile program file"
"browser:open an http server to browse program file"
"deps:install project dependencies"
"docs:generate documentation"
"eval:eval code"
"hierarchy:show type hierarchy"
"run:compile and run program file"
"spec:compile and run specs (in spec directory)"
"types:show type of main variables"
)
_describe -t commands 'Crystal command' commands
}
local -a common_args; common_args=(
'(\*)'{-D+,--define=}'[define a compile-time flag]:' \
'(-h --help)'{-h,--help}'[show help]' \
'(--no-color)--no-color[disable colored output]' \
'(--prelude)--prelude[use given file as prelude]'
)
local -a programfile; programfile='*:Crystal File:_files -g "*.cr(.)"'
# TODO make 'emit' allow completion with more than one
local -a shared_run_build; shared_run_build=(
$programfile \
$common_args \
'(--ll)-ll[Dump ll to .crystal directory]' \
'(--link-flags)--link-flags[additional flags to pass to the linker]:' \
'(--mcpu)--mcpu[target specific cpu type]:' \
'(--no-codegen)--no-codegen[disable code generation]' \
'(-o)-o[Output filename]:' \
'(--prelude)--prelude[use given file as prelude]:' \
'(--release)--release[compile in release mode]' \
'(-s --stats)'{-s,--stats}'[enable statistics output]' \
'(--single-module)--single-module[generate a single llvm module]' \
'(--threads)--threads[maximum number of threads to use]:' \
'(--verbose)--verbose[display executed commands]' \
'(--emit)--emit[comma separated list of types of output for the compiler to emit]:foo:(asm llvm-bc llvm-ir obj)'
)
# TODO add help text for name and dir
_crystal-init() {
_arguments \
'1:type:(lib app)' \
&& ret=0
}
_crystal-build() {
_arguments \
$shared_run_build \
'(--cross-compile)--cross-compile[cross-compile FLAGS]:' \
'(--target)--target[target triple]:' \
&& ret=0
}
_crystal-browser() {
_arguments \
$common_args \
&& ret=0
}
_crystal-hierarchy() {
_arguments \
$programfile \
$common_args \
&& ret=0
}
_crystal-run() {
_arguments \
$shared_run_build \
&& ret=0
}
_crystal-types() {
_arguments \
$common_args \
&& ret=0
}
local curcontext=$curcontext ret=1
declare -A opt_args
_arguments -C \
'(- 1 *)'{-h,--help}'[show help]' \
'(- 1 *)'{-v,--version}'[show version]' \
'1:sub-command: _alternative "subcommands:sub command:_crystal_commands" "files:file:_files -g \*.cr\(-.\)"' \
'*::arg:->cmd' && ret=0
case $state in
(cmd)
if (( $CURRENT == 1 )); then
else
curcontext="${curcontext%:*:*}:crystal-$words[1]:"
if ! _call_function ret _crystal-$words[1] ; then
_default && ret=0
fi
return ret
fi
;;
esac
}
_crystal