├── zig-shell-completions.plugin.zsh ├── Makefile ├── LICENSE ├── README.md ├── zig.completor.bash ├── _zig.bash └── _zig /zig-shell-completions.plugin.zsh: -------------------------------------------------------------------------------- 1 | fpath+="${0:h}" 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: bash 2 | bash: 3 | bash-completor -c ./zig.completor.bash 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Veikka Tuominen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # shell-completions 2 | 3 | Shell completions for the [Zig compiler](https://github.com/ziglang/zig). 4 | 5 | ## Installation for zsh 6 | 7 | The `_zig` file needs to be included in your `$fpath`. This can be achieved in two ways: 8 | 1. Move the `_zig` file to one of the folders listed in `$fpath`. You can list these folders with `print -l $fpath`. 9 | 2. Add the folder containing `_zig` to the `$fpath`. This can be achieved by adding `fpath=(/path/to/this/repo/shell-completions $fpath)` to your `~/.zshrc` file (to update the current terminal run `source ~/.zshrc`). 10 | 11 | Once the `$fpath` variable is updated, run `compinit` to rebuild `~/.zcompdump`. 12 | 13 | ### Installation for Oh My Zsh 14 | 15 | 1. Clone the plugin as `zig-shell-completions` 16 | 17 | ```sh 18 | git clone https://github.com/ziglang/shell-completions $ZSH/custom/plugins/zig-shell-completions 19 | ``` 20 | 21 | 2. Add the plugin `zig-shell-completions` to `$plugin` 22 | 23 | ```sh 24 | plugins+=(zig-shell-completions) 25 | ``` 26 | 27 | ## Installation for bash 28 | 29 | ```sh 30 | curl -LO "https://raw.githubusercontent.com/ziglang/shell-completions/master/_zig.bash" 31 | echo ". $PWD/_zig.bash" >> ~/.bashrc 32 | ``` 33 | -------------------------------------------------------------------------------- /zig.completor.bash: -------------------------------------------------------------------------------- 1 | # shellcheck disable=2034 2 | # The output path is relative to current config file. 3 | output=_zig.bash 4 | maintainers=('ADoyle (adoyle.h@gmail.com)') 5 | notice='Current no completions for zig commands: cc c++ lib' 6 | 7 | cmd=zig 8 | cmd_opts=(-h --help) 9 | 10 | subcmds=( 11 | build fetch init 12 | build-exe build-lib build-obj test run 13 | ast-check fmt reduce translate-c 14 | ar cc c++ dlltool lib ranlib objcopy rc 15 | env help std libc targets version zen 16 | ) 17 | 18 | word_to_varname=( 19 | [c++]=cpp 20 | ) 21 | 22 | reply_zig_file=( 23 | 'reply_files_in_pattern' 24 | '\.(zig|zir|zon|o|obj|lib|a|so|dll|dylib|tbd|s|S|c|cxx|cc|C|cpp|stub|m|mm|bc|cu)$' 25 | ) 26 | 27 | reply_build_steps() { 28 | local words=( $(zig build --list-steps 2>/dev/null | grep -Eo '^\s*\w+' | grep -Eo '\w+') ) 29 | 30 | [ $? = 0 ] || return 1 31 | 32 | COMPREPLY=( $(compgen -W "${words[*]}" -- "$cur") ) 33 | } 34 | 35 | subcmd_opts__fallback='--help' 36 | 37 | subcmd_opts_build=( 38 | -p:@dirs 39 | --prefix:@dirs 40 | --prefix-lib-dir:@dirs 41 | --prefix-exe-dir:@dirs 42 | --prefix-include-dir:@dirs 43 | 44 | --release=:'fast,safe,small' 45 | 46 | -fdarling -fno-darling 47 | -fqemu -fno-qemu 48 | --glibc-runtimes:@files 49 | -frosetta -fno-rosetta 50 | -fwasmtime -fno-wasmtime 51 | -fwine -fno-wine 52 | 53 | -h --help 54 | -l --list-steps 55 | --verbose 56 | --color:'auto,off,on' 57 | --prominent-compile-errors 58 | --summary:'all,new,failures,none' 59 | -j:@hold 60 | --maxrss:@hold 61 | --skip-oom-steps 62 | --fetch 63 | --watch 64 | --fuzz 65 | --debounce:@hold 66 | -fincremental -fno-incremental 67 | 68 | -Dtarget= 69 | -Dcpu= 70 | -Dofmt= 71 | -Ddynamic-linker= 72 | -Doptimize=:'Debug,ReleaseSafe,ReleaseFast,ReleaseSmall' 73 | 74 | --search-prefix:@dirs 75 | --sysroot:@dirs 76 | --libc:@files 77 | 78 | --system:@dirs 79 | -fsys= -fno-sys= 80 | 81 | -freference-trace:@hold 82 | -fno-reference-trace 83 | 84 | --build-file:@files 85 | --cache-dir:@dirs 86 | --global-cache-dir:@dirs 87 | --zig-lib-dir:@dirs 88 | --build-runner:@files 89 | --seed:@hold 90 | 91 | --debug-log:@hold 92 | --debug-pkg-config 93 | --debug-rt 94 | --verbose-link 95 | --verbose-air 96 | --verbose-llvm-ir:@hold 97 | --verbose-llvm-bc=:@files 98 | --verbose-cimport 99 | --verbose-cc 100 | --verbose-llvm-cpu-features 101 | ) 102 | # https://ziglearn.org/chapter-3/#build-steps 103 | subcmd_args_build=@build_steps 104 | subcmd_args_build_fallback='install,uninstall,run,test' 105 | subcmd_opts_build_fallback=@files 106 | 107 | subcmd_opts_fmt=( 108 | -h --help 109 | --color:'auto,off,on' 110 | --stdin 111 | --check 112 | --ast-check 113 | --exclude:@zig_file 114 | ) 115 | subcmd_args_fmt=@zig_file 116 | 117 | subcmd_opts_libc=( 118 | -h --help 119 | -target:@hold 120 | -includes 121 | ) 122 | subcmd_args_libc=@zig_file 123 | 124 | subcmd_opts_ar=( 125 | --format:'default,gnu,darwin,bsd,bigarchive' 126 | --plugin= 127 | -h --help 128 | --output 129 | --rsp-quoting:'posix,windows' 130 | --thin 131 | --version 132 | -X32 133 | -X64 134 | -X32_64 135 | -X:@hold 136 | @:@files 137 | ) 138 | subcmd_args_ar=@zig_file 139 | 140 | subcmd_opts_ast_check=( 141 | -h --help 142 | --color:'auto,off,on' 143 | -t 144 | ) 145 | subcmd_args_ast_check=@zig_file 146 | 147 | opts_run_general=( 148 | -h --help 149 | --watch 150 | --color:'auto,off,on' 151 | -femit-bin:@files -fno-emit-bin 152 | -femit-asm:@files -fno-emit-asm 153 | -femit-llvm-ir:@files -fno-emit-llvm-ir 154 | -femit-llvm-bc:@files -fno-emit-llvm-bc 155 | -femit-h:@files -fno-emit-h 156 | -femit-docs:@dirs -fno-emit-docs 157 | -femit-analysis:@files -fno-emit-analysis 158 | -femit-implib:@files -fno-emit-implib 159 | --show-builtin 160 | --cache-dir:@dirs 161 | --global-cache-dir:@dirs 162 | --zig-lib-dir:@dirs 163 | --enable-cache 164 | ) 165 | 166 | opts_run_compile=( 167 | -target:@hold 168 | -mcpu:@hold 169 | -mcmodel=:'default,tiny,small,kernel,medium,large' 170 | -mred-zone -mno-red-zone 171 | -fomit-frame-pointer:@hold -fno-omit-frame-pointer 172 | -mexec-model= 173 | --name:@hold 174 | -O:'Debug,ReleaseFast,ReleaseSafe,ReleaseSmall' 175 | --pkg-begin:@hold 176 | --pkg-end 177 | --main-pkg-path:@dirs 178 | -fPIC -fno-PIC 179 | -fPIE -fno-PIE 180 | -flto -fno-lto 181 | -fstack-check -fno-stack-check 182 | -fstack-protector -fno-stack-protector 183 | -fsanitize-c -fno-sanitize-c 184 | -fvalgrind -fno-valgrind 185 | -fsanitize-thread -fno-sanitize-thread 186 | -fdll-export-fns -fno-dll-export-fns 187 | -funwind-tables -fno-unwind-tables 188 | -fLLVM -fno-LLVM 189 | -fClang -fno-Clang 190 | -fstage1 -fno-stage1 191 | -freference-trace -fno-reference-trace 192 | -fsingle-threaded -fno-single-threaded 193 | -fbuiltin -fno-builtin 194 | -ffunction-sections -fno-function-sections 195 | -fstrip -fno-strip 196 | -ofmt=:'elf,c,wasm,coff,macho,spirv,plan9,hex,raw' 197 | -idirafter:@dirs 198 | -isystem:@dirs 199 | -I:@dirs 200 | -D 201 | --libc 202 | -cflags:@hold 203 | ) 204 | 205 | opts_run_debug=( 206 | -ftime-report 207 | -fstack-report 208 | --verbose-link 209 | --verbose-cc 210 | --verbose-air 211 | --verbose-llvm-ir 212 | --verbose-cimport 213 | --verbose-llvm-cpu-features 214 | --debug-log:@hold 215 | --debug-compile-errors 216 | --debug-link-snapshot 217 | ) 218 | 219 | opts_run_link=( 220 | -l:@files 221 | --library:@files 222 | -needed-l:@files 223 | --needed-library:@files 224 | -L:@dirs 225 | --library-directory:@dirs 226 | -T:@files 227 | --script:@files 228 | --version-script:@files 229 | --dynamic-linker:@files 230 | --sysroot:@dirs 231 | --version:@hold 232 | --entry:@hold 233 | -fsoname:@hold 234 | -fno-soname 235 | -fLLD -fno-LLD 236 | -fcompiler-rt -fno-compiler-rt 237 | -rdynamic 238 | -rpath:@dirs 239 | -feach-lib-rpath -fno-each-lib-rpath 240 | -fallow-shlib-undefined -fno-allow-shlib-undefined 241 | -fbuild-id 242 | -fno-build-id 243 | --eh-frame-hdr 244 | --emit-relocs 245 | -z:'nodelete,notext,defs,origin,nocopyreloc,now,lazy,relro,norelro' 246 | -dynamic 247 | -static 248 | -Bsymbolic 249 | --compress-debug-sections=:'none,zlib' 250 | --gc-sections --no-gc-sections 251 | --subsystem:@hold 252 | --stack:@hold 253 | --image-base:@hold 254 | -weak-l:@files 255 | -weak_library:@files 256 | -framework:@hold 257 | -needed_framework:@hold 258 | -needed_library:@files 259 | -weak_framework:@hold 260 | -F:@dirs 261 | -install_name= 262 | --entitlements:@files 263 | -pagezero_size:@hold 264 | -search_paths_first 265 | -search_dylibs_first 266 | -headerpad:@hold 267 | -headerpad_max_install_names 268 | -dead_strip 269 | -dead_strip_dylibs 270 | --import-memory 271 | --import-table 272 | --export-table 273 | --initial-memory= 274 | --max-memory= 275 | --shared-memory 276 | --global-base= 277 | --export= 278 | ) 279 | 280 | subcmd_opts_test=( 281 | --test-filter:@hold 282 | --test-name-prefix:@hold 283 | --test-cmd:@hold 284 | --test-cmd-bin 285 | --test-evented-io 286 | --test-no-exec 287 | 288 | ${opts_run_general[@]} 289 | ${opts_run_compile[@]} 290 | ${opts_run_link[@]} 291 | ${opts_run_debug[@]} 292 | ) 293 | subcmd_args_test=@zig_file 294 | 295 | subcmd_opts_run=( 296 | -- 297 | 298 | ${opts_run_general[@]} 299 | ${opts_run_compile[@]} 300 | ${opts_run_link[@]} 301 | ${opts_run_debug[@]} 302 | ) 303 | subcmd_args_run=@zig_file 304 | 305 | subcmd_comp_alias=( 306 | ['build-exe']=run 307 | ['build-lib']=run 308 | ['build-obj']=run 309 | ['build-translate-c']=run 310 | ) 311 | 312 | subcmd_opts_ranlib=( 313 | -h --help 314 | -v --version 315 | -D 316 | -U 317 | ) 318 | 319 | subcmd_opts_dlltool=( 320 | -D:@hold 321 | -d:@files 322 | -f:@hold 323 | -k 324 | -l:@hold 325 | -m:@hold 326 | -S:@hold 327 | ) 328 | -------------------------------------------------------------------------------- /_zig.bash: -------------------------------------------------------------------------------- 1 | # This file is generated by [bash-completor](https://github.com/adoyle-h/bash-completor/tree/v0.1.0). Do not modify it manually. 2 | # 3 | # [Usage] 4 | # Put "source _zig.bash" in your bashrc. 5 | # 6 | # If you want to debug the completion. 7 | # Search '# Uncomment this line for debug' line in this file. 8 | # 9 | # [Update Script] 10 | # bash-completor -c ./zig.completor.bash 11 | # 12 | # [Maintainers] 13 | # ADoyle (adoyle.h@gmail.com) 14 | # 15 | # [Notice] 16 | # Current no completions for zig commands: cc c++ lib 17 | 18 | # shellcheck disable=2207 19 | # editorconfig-checker-disable 20 | 21 | _zig_comp_cmd_opts=( -h --help ) 22 | 23 | 24 | _zig_comp_subcmd_opts__fallback=( --help ) 25 | 26 | _zig_comp_subcmd_opts_ar=( --format --plugin= -h --help --output --rsp-quoting --thin --version -X32 -X64 -X32_64 -X @ ) 27 | 28 | _zig_comp_subcmd_opts_ast_check=( -h --help --color -t ) 29 | 30 | _zig_comp_subcmd_opts_build=( -p --prefix --prefix-lib-dir --prefix-exe-dir --prefix-include-dir --release= -fdarling -fno-darling -fqemu -fno-qemu --glibc-runtimes -frosetta -fno-rosetta -fwasmtime -fno-wasmtime -fwine -fno-wine -h --help -l --list-steps --verbose --color --prominent-compile-errors --summary -j --maxrss --skip-oom-steps --fetch --watch --fuzz --debounce -fincremental -fno-incremental -Dtarget= -Dcpu= -Dofmt= -Ddynamic-linker= -Doptimize= --search-prefix --sysroot --libc --system -fsys= -fno-sys= -freference-trace -fno-reference-trace --build-file --cache-dir --global-cache-dir --zig-lib-dir --build-runner --seed --debug-log --debug-pkg-config --debug-rt --verbose-link --verbose-air --verbose-llvm-ir --verbose-llvm-bc= --verbose-cimport --verbose-cc --verbose-llvm-cpu-features ) 31 | 32 | _zig_comp_subcmd_opts_build_fallback=( @files ) 33 | 34 | _zig_comp_subcmd_opts_dlltool=( -D -d -f -k -l -m -S ) 35 | 36 | _zig_comp_subcmd_opts_fmt=( -h --help --color --stdin --check --ast-check --exclude ) 37 | 38 | _zig_comp_subcmd_opts_libc=( -h --help -target -includes ) 39 | 40 | _zig_comp_subcmd_opts_ranlib=( -h --help -v --version -D -U ) 41 | 42 | _zig_comp_subcmd_opts_run=( -- -h --help --watch --color -femit-bin -fno-emit-bin -femit-asm -fno-emit-asm -femit-llvm-ir -fno-emit-llvm-ir -femit-llvm-bc -fno-emit-llvm-bc -femit-h -fno-emit-h -femit-docs -fno-emit-docs -femit-analysis -fno-emit-analysis -femit-implib -fno-emit-implib --show-builtin --cache-dir --global-cache-dir --zig-lib-dir --enable-cache -target -mcpu -mcmodel= -mred-zone -mno-red-zone -fomit-frame-pointer -fno-omit-frame-pointer -mexec-model= --name -O --pkg-begin --pkg-end --main-pkg-path -fPIC -fno-PIC -fPIE -fno-PIE -flto -fno-lto -fstack-check -fno-stack-check -fstack-protector -fno-stack-protector -fsanitize-c -fno-sanitize-c -fvalgrind -fno-valgrind -fsanitize-thread -fno-sanitize-thread -fdll-export-fns -fno-dll-export-fns -funwind-tables -fno-unwind-tables -fLLVM -fno-LLVM -fClang -fno-Clang -fstage1 -fno-stage1 -freference-trace -fno-reference-trace -fsingle-threaded -fno-single-threaded -fbuiltin -fno-builtin -ffunction-sections -fno-function-sections -fstrip -fno-strip -ofmt= -idirafter -isystem -I -D --libc -cflags -l --library -needed-l --needed-library -L --library-directory -T --script --version-script --dynamic-linker --sysroot --version --entry -fsoname -fno-soname -fLLD -fno-LLD -fcompiler-rt -fno-compiler-rt -rdynamic -rpath -feach-lib-rpath -fno-each-lib-rpath -fallow-shlib-undefined -fno-allow-shlib-undefined -fbuild-id -fno-build-id --eh-frame-hdr --emit-relocs -z -dynamic -static -Bsymbolic --compress-debug-sections= --gc-sections --no-gc-sections --subsystem --stack --image-base -weak-l -weak_library -framework -needed_framework -needed_library -weak_framework -F -install_name= --entitlements -pagezero_size -search_paths_first -search_dylibs_first -headerpad -headerpad_max_install_names -dead_strip -dead_strip_dylibs --import-memory --import-table --export-table --initial-memory= --max-memory= --shared-memory --global-base= --export= -ftime-report -fstack-report --verbose-link --verbose-cc --verbose-air --verbose-llvm-ir --verbose-cimport --verbose-llvm-cpu-features --debug-log --debug-compile-errors --debug-link-snapshot ) 43 | 44 | _zig_comp_subcmd_opts_test=( --test-filter --test-name-prefix --test-cmd --test-cmd-bin --test-evented-io --test-no-exec -h --help --watch --color -femit-bin -fno-emit-bin -femit-asm -fno-emit-asm -femit-llvm-ir -fno-emit-llvm-ir -femit-llvm-bc -fno-emit-llvm-bc -femit-h -fno-emit-h -femit-docs -fno-emit-docs -femit-analysis -fno-emit-analysis -femit-implib -fno-emit-implib --show-builtin --cache-dir --global-cache-dir --zig-lib-dir --enable-cache -target -mcpu -mcmodel= -mred-zone -mno-red-zone -fomit-frame-pointer -fno-omit-frame-pointer -mexec-model= --name -O --pkg-begin --pkg-end --main-pkg-path -fPIC -fno-PIC -fPIE -fno-PIE -flto -fno-lto -fstack-check -fno-stack-check -fstack-protector -fno-stack-protector -fsanitize-c -fno-sanitize-c -fvalgrind -fno-valgrind -fsanitize-thread -fno-sanitize-thread -fdll-export-fns -fno-dll-export-fns -funwind-tables -fno-unwind-tables -fLLVM -fno-LLVM -fClang -fno-Clang -fstage1 -fno-stage1 -freference-trace -fno-reference-trace -fsingle-threaded -fno-single-threaded -fbuiltin -fno-builtin -ffunction-sections -fno-function-sections -fstrip -fno-strip -ofmt= -idirafter -isystem -I -D --libc -cflags -l --library -needed-l --needed-library -L --library-directory -T --script --version-script --dynamic-linker --sysroot --version --entry -fsoname -fno-soname -fLLD -fno-LLD -fcompiler-rt -fno-compiler-rt -rdynamic -rpath -feach-lib-rpath -fno-each-lib-rpath -fallow-shlib-undefined -fno-allow-shlib-undefined -fbuild-id -fno-build-id --eh-frame-hdr --emit-relocs -z -dynamic -static -Bsymbolic --compress-debug-sections= --gc-sections --no-gc-sections --subsystem --stack --image-base -weak-l -weak_library -framework -needed_framework -needed_library -weak_framework -F -install_name= --entitlements -pagezero_size -search_paths_first -search_dylibs_first -headerpad -headerpad_max_install_names -dead_strip -dead_strip_dylibs --import-memory --import-table --export-table --initial-memory= --max-memory= --shared-memory --global-base= --export= -ftime-report -fstack-report --verbose-link --verbose-cc --verbose-air --verbose-llvm-ir --verbose-cimport --verbose-llvm-cpu-features --debug-log --debug-compile-errors --debug-link-snapshot ) 45 | 46 | declare -A _zig_comp_word_to_varname=([c++]="cpp" ) 47 | _zig_comp_util_get_varname () 48 | { 49 | local name=${1:-}; 50 | local encoded=${_zig_comp_word_to_varname[$name]:-}; 51 | if [[ -z ${encoded} ]]; then 52 | encoded=${name//[^a-zA-Z_]/_}; 53 | fi; 54 | echo "${encoded}" 55 | } 56 | 57 | _zig_comp_reply_build_steps () 58 | { 59 | local words=($(zig build --list-steps 2> /dev/null | grep -Eo '^\s*\w+' | grep -Eo '\w+')); 60 | [ $? = 0 ] || return 1; 61 | COMPREPLY=($(compgen -W "${words[*]}" -- "$cur")) 62 | } 63 | 64 | _zig_comp_reply_dirs () 65 | { 66 | local IFS=$'\n'; 67 | compopt -o nospace -o filenames; 68 | COMPREPLY=($(compgen -A directory -- "$cur")) 69 | } 70 | 71 | _zig_comp_reply_files () 72 | { 73 | local IFS=$'\n'; 74 | compopt -o nospace -o filenames; 75 | COMPREPLY=($(compgen -A file -- "$cur")) 76 | } 77 | 78 | _zig_comp_reply_files_in_pattern () 79 | { 80 | compopt -o nospace -o filenames; 81 | local path; 82 | while read -r path; do 83 | if [[ $path =~ $1 ]] || [[ -d $path ]]; then 84 | COMPREPLY+=("$path"); 85 | fi; 86 | done < <(compgen -A file -- "$cur") 87 | } 88 | 89 | _zig_comp_reply_list () 90 | { 91 | local IFS=', '; 92 | local array_list="" array_name; 93 | for array_name in $@; 94 | do 95 | array_list="$array_list \${${array_name}[*]}"; 96 | done; 97 | array_list="${array_list[*]:1}"; 98 | IFS=$'\n'' '; 99 | eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )" 100 | } 101 | 102 | _zig_comp_reply_words () 103 | { 104 | local IFS=$'\n'; 105 | COMPREPLY=($(IFS=', ' compgen -W "$*" -- "${cur#=}")) 106 | } 107 | 108 | _zig_comp_reply_set() { 109 | local IFS=', ' 110 | local array_list="" array_name 111 | # shellcheck disable=2068 112 | for array_name in $@; do 113 | array_list="$array_list \${_zig_comp_var_${array_name}[*]}" 114 | done 115 | array_list="${array_list[*]:1}" 116 | 117 | IFS=$'\n'' ' 118 | eval "COMPREPLY=( \$(compgen -W \"$array_list\" -- \"\$cur\") )" 119 | } 120 | 121 | _zig_comp_reply_zig_file() { 122 | _zig_comp_reply_files_in_pattern '\.(zig|zir|zon|o|obj|lib|a|so|dll|dylib|tbd|s|S|c|cxx|cc|C|cpp|stub|m|mm|bc|cu)$' 123 | } 124 | 125 | _zig_comp_subcmds=( build fetch init build-exe build-lib build-obj test run ast-check fmt reduce translate-c ar cc c++ dlltool lib ranlib objcopy rc env help std libc targets version zen ) 126 | 127 | _zig_comp_equal_sign_subcmd_opts_build() { 128 | case "${1}=" in 129 | --release=) _zig_comp_reply_words 'fast,safe,small' ;; 130 | -Dtarget=) ;; 131 | -Dcpu=) ;; 132 | -Dofmt=) ;; 133 | -Ddynamic-linker=) ;; 134 | -Doptimize=) _zig_comp_reply_words 'Debug,ReleaseSafe,ReleaseFast,ReleaseSmall' ;; 135 | -fsys=) ;; 136 | -fno-sys=) ;; 137 | --verbose-llvm-bc=) _zig_comp_reply_files ;; 138 | esac 139 | } 140 | 141 | _zig_completions_build() { 142 | if [[ ${cur:0:1} == [-+] ]]; then 143 | # rely options of command 144 | _zig_comp_reply_list _zig_comp_subcmd_opts_build 145 | if [[ ${COMPREPLY[*]} =~ =$ ]]; then compopt -o nospace; fi 146 | elif [[ ${cur} == = ]]; then 147 | _zig_comp_equal_sign_subcmd_opts_build "$prev" 148 | elif [[ ${prev:0:1} == [-+] ]]; then 149 | case "${prev}" in 150 | # rely the value of command option 151 | -p) _zig_comp_reply_dirs ;; 152 | --prefix) _zig_comp_reply_dirs ;; 153 | --prefix-lib-dir) _zig_comp_reply_dirs ;; 154 | --prefix-exe-dir) _zig_comp_reply_dirs ;; 155 | --prefix-include-dir) _zig_comp_reply_dirs ;; 156 | --color) _zig_comp_reply_words 'auto,off,on' ;; 157 | --summary) _zig_comp_reply_words 'all,new,failures,none' ;; 158 | -j) ;; 159 | --maxrss) ;; 160 | --debounce) ;; 161 | --search-prefix) _zig_comp_reply_dirs ;; 162 | --sysroot) _zig_comp_reply_dirs ;; 163 | --system) _zig_comp_reply_dirs ;; 164 | -freference-trace) ;; 165 | --cache-dir) _zig_comp_reply_dirs ;; 166 | --global-cache-dir) _zig_comp_reply_dirs ;; 167 | --zig-lib-dir) _zig_comp_reply_dirs ;; 168 | --seed) ;; 169 | --debug-log) ;; 170 | --verbose-llvm-ir) ;; 171 | *) _zig_comp_reply_files ;; 172 | esac 173 | elif [[ ${prev} == = ]]; then 174 | _zig_comp_equal_sign_subcmd_opts_build "${COMP_WORDS[$(( COMP_CWORD - 2 ))]}" 175 | else 176 | # rely the argument of command 177 | _zig_comp_reply_build_steps 178 | fi 179 | } 180 | 181 | _zig_comp_equal_sign_subcmd_opts_test() { 182 | case "${1}=" in 183 | -mcmodel=) _zig_comp_reply_words 'default,tiny,small,kernel,medium,large' ;; 184 | -mexec-model=) ;; 185 | -ofmt=) _zig_comp_reply_words 'elf,c,wasm,coff,macho,spirv,plan9,hex,raw' ;; 186 | --compress-debug-sections=) _zig_comp_reply_words 'none,zlib' ;; 187 | -install_name=) ;; 188 | --initial-memory=) ;; 189 | --max-memory=) ;; 190 | --global-base=) ;; 191 | --export=) ;; 192 | esac 193 | } 194 | 195 | _zig_completions_test() { 196 | if [[ ${cur:0:1} == [-+] ]]; then 197 | # rely options of command 198 | _zig_comp_reply_list _zig_comp_subcmd_opts_test 199 | if [[ ${COMPREPLY[*]} =~ =$ ]]; then compopt -o nospace; fi 200 | elif [[ ${cur} == = ]]; then 201 | _zig_comp_equal_sign_subcmd_opts_test "$prev" 202 | elif [[ ${prev:0:1} == [-+] ]]; then 203 | case "${prev}" in 204 | # rely the value of command option 205 | --test-filter) ;; 206 | --test-name-prefix) ;; 207 | --test-cmd) ;; 208 | --color) _zig_comp_reply_words 'auto,off,on' ;; 209 | -femit-bin) _zig_comp_reply_files ;; 210 | -femit-asm) _zig_comp_reply_files ;; 211 | -femit-llvm-ir) _zig_comp_reply_files ;; 212 | -femit-llvm-bc) _zig_comp_reply_files ;; 213 | -femit-h) _zig_comp_reply_files ;; 214 | -femit-docs) _zig_comp_reply_dirs ;; 215 | -femit-analysis) _zig_comp_reply_files ;; 216 | -femit-implib) _zig_comp_reply_files ;; 217 | --cache-dir) _zig_comp_reply_dirs ;; 218 | --global-cache-dir) _zig_comp_reply_dirs ;; 219 | --zig-lib-dir) _zig_comp_reply_dirs ;; 220 | -target) ;; 221 | -mcpu) ;; 222 | -fomit-frame-pointer) ;; 223 | --name) ;; 224 | -O) _zig_comp_reply_words 'Debug,ReleaseFast,ReleaseSafe,ReleaseSmall' ;; 225 | --pkg-begin) ;; 226 | --main-pkg-path) _zig_comp_reply_dirs ;; 227 | -idirafter) _zig_comp_reply_dirs ;; 228 | -isystem) _zig_comp_reply_dirs ;; 229 | -I) _zig_comp_reply_dirs ;; 230 | -cflags) ;; 231 | -l) _zig_comp_reply_files ;; 232 | --library) _zig_comp_reply_files ;; 233 | -needed-l) _zig_comp_reply_files ;; 234 | --needed-library) _zig_comp_reply_files ;; 235 | -L) _zig_comp_reply_dirs ;; 236 | --library-directory) _zig_comp_reply_dirs ;; 237 | -T) _zig_comp_reply_files ;; 238 | --script) _zig_comp_reply_files ;; 239 | --version-script) _zig_comp_reply_files ;; 240 | --dynamic-linker) _zig_comp_reply_files ;; 241 | --sysroot) _zig_comp_reply_dirs ;; 242 | --version) ;; 243 | --entry) ;; 244 | -fsoname) ;; 245 | -rpath) _zig_comp_reply_dirs ;; 246 | -z) _zig_comp_reply_words 'nodelete,notext,defs,origin,nocopyreloc,now,lazy,relro,norelro' ;; 247 | --subsystem) ;; 248 | --stack) ;; 249 | --image-base) ;; 250 | -weak-l) _zig_comp_reply_files ;; 251 | -weak_library) _zig_comp_reply_files ;; 252 | -framework) ;; 253 | -needed_framework) ;; 254 | -needed_library) _zig_comp_reply_files ;; 255 | -weak_framework) ;; 256 | -F) _zig_comp_reply_dirs ;; 257 | --entitlements) _zig_comp_reply_files ;; 258 | -pagezero_size) ;; 259 | -headerpad) ;; 260 | --debug-log) ;; 261 | *) _zig_comp_reply_zig_file ;; 262 | esac 263 | elif [[ ${prev} == = ]]; then 264 | _zig_comp_equal_sign_subcmd_opts_test "${COMP_WORDS[$(( COMP_CWORD - 2 ))]}" 265 | else 266 | # rely the argument of command 267 | _zig_comp_reply_zig_file 268 | fi 269 | } 270 | 271 | _zig_comp_equal_sign_subcmd_opts_run() { 272 | case "${1}=" in 273 | -mcmodel=) _zig_comp_reply_words 'default,tiny,small,kernel,medium,large' ;; 274 | -mexec-model=) ;; 275 | -ofmt=) _zig_comp_reply_words 'elf,c,wasm,coff,macho,spirv,plan9,hex,raw' ;; 276 | --compress-debug-sections=) _zig_comp_reply_words 'none,zlib' ;; 277 | -install_name=) ;; 278 | --initial-memory=) ;; 279 | --max-memory=) ;; 280 | --global-base=) ;; 281 | --export=) ;; 282 | esac 283 | } 284 | 285 | _zig_completions_run() { 286 | if [[ $COMP_LINE == *' -- '* ]]; then 287 | # When current command line contains the "--" option, other options are forbidden. 288 | _zig_comp_reply_zig_file 289 | elif [[ ${cur:0:1} == [-+] ]]; then 290 | # rely options of command 291 | _zig_comp_reply_list _zig_comp_subcmd_opts_run 292 | if [[ ${COMPREPLY[*]} =~ =$ ]]; then compopt -o nospace; fi 293 | elif [[ ${cur} == = ]]; then 294 | _zig_comp_equal_sign_subcmd_opts_run "$prev" 295 | elif [[ ${prev:0:1} == [-+] ]]; then 296 | case "${prev}" in 297 | # rely the value of command option 298 | --color) _zig_comp_reply_words 'auto,off,on' ;; 299 | -femit-bin) _zig_comp_reply_files ;; 300 | -femit-asm) _zig_comp_reply_files ;; 301 | -femit-llvm-ir) _zig_comp_reply_files ;; 302 | -femit-llvm-bc) _zig_comp_reply_files ;; 303 | -femit-h) _zig_comp_reply_files ;; 304 | -femit-docs) _zig_comp_reply_dirs ;; 305 | -femit-analysis) _zig_comp_reply_files ;; 306 | -femit-implib) _zig_comp_reply_files ;; 307 | --cache-dir) _zig_comp_reply_dirs ;; 308 | --global-cache-dir) _zig_comp_reply_dirs ;; 309 | --zig-lib-dir) _zig_comp_reply_dirs ;; 310 | -target) ;; 311 | -mcpu) ;; 312 | -fomit-frame-pointer) ;; 313 | --name) ;; 314 | -O) _zig_comp_reply_words 'Debug,ReleaseFast,ReleaseSafe,ReleaseSmall' ;; 315 | --pkg-begin) ;; 316 | --main-pkg-path) _zig_comp_reply_dirs ;; 317 | -idirafter) _zig_comp_reply_dirs ;; 318 | -isystem) _zig_comp_reply_dirs ;; 319 | -I) _zig_comp_reply_dirs ;; 320 | -cflags) ;; 321 | -l) _zig_comp_reply_files ;; 322 | --library) _zig_comp_reply_files ;; 323 | -needed-l) _zig_comp_reply_files ;; 324 | --needed-library) _zig_comp_reply_files ;; 325 | -L) _zig_comp_reply_dirs ;; 326 | --library-directory) _zig_comp_reply_dirs ;; 327 | -T) _zig_comp_reply_files ;; 328 | --script) _zig_comp_reply_files ;; 329 | --version-script) _zig_comp_reply_files ;; 330 | --dynamic-linker) _zig_comp_reply_files ;; 331 | --sysroot) _zig_comp_reply_dirs ;; 332 | --version) ;; 333 | --entry) ;; 334 | -fsoname) ;; 335 | -rpath) _zig_comp_reply_dirs ;; 336 | -z) _zig_comp_reply_words 'nodelete,notext,defs,origin,nocopyreloc,now,lazy,relro,norelro' ;; 337 | --subsystem) ;; 338 | --stack) ;; 339 | --image-base) ;; 340 | -weak-l) _zig_comp_reply_files ;; 341 | -weak_library) _zig_comp_reply_files ;; 342 | -framework) ;; 343 | -needed_framework) ;; 344 | -needed_library) _zig_comp_reply_files ;; 345 | -weak_framework) ;; 346 | -F) _zig_comp_reply_dirs ;; 347 | --entitlements) _zig_comp_reply_files ;; 348 | -pagezero_size) ;; 349 | -headerpad) ;; 350 | --debug-log) ;; 351 | *) _zig_comp_reply_zig_file ;; 352 | esac 353 | elif [[ ${prev} == = ]]; then 354 | _zig_comp_equal_sign_subcmd_opts_run "${COMP_WORDS[$(( COMP_CWORD - 2 ))]}" 355 | else 356 | # rely the argument of command 357 | _zig_comp_reply_zig_file 358 | fi 359 | } 360 | 361 | _zig_completions_ast_check() { 362 | if [[ ${cur:0:1} == [-+] ]]; then 363 | # rely options of command 364 | _zig_comp_reply_list _zig_comp_subcmd_opts_ast_check 365 | elif [[ ${prev:0:1} == [-+] ]]; then 366 | case "${prev}" in 367 | # rely the value of command option 368 | --color) _zig_comp_reply_words 'auto,off,on' ;; 369 | *) _zig_comp_reply_zig_file ;; 370 | esac 371 | else 372 | # rely the argument of command 373 | _zig_comp_reply_zig_file 374 | fi 375 | } 376 | 377 | _zig_completions_fmt() { 378 | if [[ ${cur:0:1} == [-+] ]]; then 379 | # rely options of command 380 | _zig_comp_reply_list _zig_comp_subcmd_opts_fmt 381 | elif [[ ${prev:0:1} == [-+] ]]; then 382 | case "${prev}" in 383 | # rely the value of command option 384 | --color) _zig_comp_reply_words 'auto,off,on' ;; 385 | *) _zig_comp_reply_zig_file ;; 386 | esac 387 | else 388 | # rely the argument of command 389 | _zig_comp_reply_zig_file 390 | fi 391 | } 392 | 393 | _zig_comp_equal_sign_subcmd_opts_ar() { 394 | case "${1}=" in 395 | --plugin=) ;; 396 | esac 397 | } 398 | 399 | _zig_completions_ar() { 400 | if [[ ${cur:0:1} == [-+] ]]; then 401 | # rely options of command 402 | _zig_comp_reply_list _zig_comp_subcmd_opts_ar 403 | if [[ ${COMPREPLY[*]} =~ =$ ]]; then compopt -o nospace; fi 404 | elif [[ ${cur} == = ]]; then 405 | _zig_comp_equal_sign_subcmd_opts_ar "$prev" 406 | elif [[ ${prev:0:1} == [-+] ]]; then 407 | case "${prev}" in 408 | # rely the value of command option 409 | --format) _zig_comp_reply_words 'default,gnu,darwin,bsd,bigarchive' ;; 410 | --rsp-quoting) _zig_comp_reply_words 'posix,windows' ;; 411 | -X) ;; 412 | @) _zig_comp_reply_files ;; 413 | *) _zig_comp_reply_zig_file ;; 414 | esac 415 | elif [[ ${prev} == = ]]; then 416 | _zig_comp_equal_sign_subcmd_opts_ar "${COMP_WORDS[$(( COMP_CWORD - 2 ))]}" 417 | else 418 | # rely the argument of command 419 | _zig_comp_reply_zig_file 420 | fi 421 | } 422 | 423 | _zig_completions_dlltool() { 424 | if [[ ${cur:0:1} == [-+] ]]; then 425 | # rely options of command 426 | _zig_comp_reply_list _zig_comp_subcmd_opts_dlltool 427 | elif [[ ${prev:0:1} == [-+] ]]; then 428 | case "${prev}" in 429 | # rely the value of command option 430 | -D) ;; 431 | -f) ;; 432 | -l) ;; 433 | -m) ;; 434 | -S) ;; 435 | *) _zig_comp_reply_files ;; 436 | esac 437 | else 438 | # rely the argument of command 439 | _zig_comp_reply_files 440 | fi 441 | } 442 | 443 | _zig_completions_ranlib() { 444 | if [[ ${cur:0:1} == [-+] ]]; then 445 | # rely options of command 446 | _zig_comp_reply_list _zig_comp_subcmd_opts_ranlib 447 | elif [[ ${prev:0:1} == [-+] ]]; then 448 | case "${prev}" in 449 | # rely the value of command option 450 | *) _zig_comp_reply_files ;; 451 | esac 452 | else 453 | # rely the argument of command 454 | _zig_comp_reply_files 455 | fi 456 | } 457 | 458 | _zig_completions_libc() { 459 | if [[ ${cur:0:1} == [-+] ]]; then 460 | # rely options of command 461 | _zig_comp_reply_list _zig_comp_subcmd_opts_libc 462 | elif [[ ${prev:0:1} == [-+] ]]; then 463 | case "${prev}" in 464 | # rely the value of command option 465 | -target) ;; 466 | *) _zig_comp_reply_zig_file ;; 467 | esac 468 | else 469 | # rely the argument of command 470 | _zig_comp_reply_zig_file 471 | fi 472 | } 473 | _zig_completions_build_lib() { _zig_completions_run; } 474 | _zig_completions_build_translate_c() { _zig_completions_run; } 475 | _zig_completions_build_exe() { _zig_completions_run; } 476 | _zig_completions_build_obj() { _zig_completions_run; } 477 | 478 | _zig_completions__fallback() { 479 | if [[ ${cur:0:1} == [-+] ]]; then 480 | # rely options of command 481 | _zig_comp_reply_list _zig_comp_subcmd_opts__fallback 482 | elif [[ ${prev:0:1} == [-+] ]]; then 483 | case "${prev}" in 484 | # rely the value of command option 485 | *) _zig_comp_reply_files ;; 486 | esac 487 | else 488 | # rely the argument of command 489 | _zig_comp_reply_files 490 | fi 491 | } 492 | 493 | _zig_completions() { 494 | COMPREPLY=() 495 | local cur=${COMP_WORDS[COMP_CWORD]} 496 | local prev=${COMP_WORDS[COMP_CWORD-1]} 497 | 498 | # Uncomment this line for debug 499 | # echo "[COMP_CWORD:$COMP_CWORD][cur:$cur][prev:$prev][WORD_COUNT:${#COMP_WORDS[*]}][COMP_WORDS:${COMP_WORDS[*]}]" >> bash-debug.log 500 | 501 | if (( COMP_CWORD > 1 )); then 502 | # Enter the subcmd completion 503 | local subcmd_varname 504 | subcmd_varname="$(_zig_comp_util_get_varname "${COMP_WORDS[1]}")" 505 | if type "_zig_completions_$subcmd_varname" &>/dev/null; then 506 | "_zig_completions_$subcmd_varname" 507 | else 508 | # If subcmd completion function not defined, use the fallback 509 | "_zig_completions__fallback" 510 | fi 511 | return 0 512 | fi 513 | 514 | # Enter the cmd completion 515 | if [[ ${cur:0:1} == [-+] ]]; then 516 | # rely options of command 517 | _zig_comp_reply_list _zig_comp_cmd_opts 518 | elif [[ ${prev:0:1} == [-+] ]]; then 519 | case "${prev}" in 520 | # rely the value of command option 521 | *) _zig_comp_reply_files ;; 522 | esac 523 | else 524 | # rely the argument of command 525 | _zig_comp_reply_list _zig_comp_subcmds 526 | fi 527 | } 528 | 529 | complete -F _zig_completions -o bashdefault zig 530 | # vi: sw=2 ts=2 531 | -------------------------------------------------------------------------------- /_zig: -------------------------------------------------------------------------------- 1 | #compdef zig 2 | 3 | local -a __zig_commands 4 | __zig_commands=( 5 | 'build:Build project from build.zig' 6 | 'fetch:Copy a package into global cache and print its hash' 7 | 'init:Initialize a Zig package in the current directory' 8 | 'build-exe:Create executable from source or object files' 9 | 'build-lib:Create library from source or object files' 10 | 'build-obj:Create object from source or object files' 11 | 'test:Perform unit testing' 12 | 'run:Create executable and run immediately' 13 | 'ast-check:Look for simple compile errors in any set of files' 14 | 'fmt:Reformat Zig source into canonical form' 15 | 'reduce:Minimize a bug report' 16 | 'translate-c:Convert C code to Zig code' 17 | 'ar:Use Zig as a drop-in archiver' 18 | 'cc:Use Zig as a drop-in C compiler' 19 | 'c++:Use Zig as a drop-in C++ compiler' 20 | 'dlltool:Use Zig as a drop-in dlltool.exe' 21 | 'lib:Use Zig as a drop-in lib.exe' 22 | 'ranlib:Use Zig as a drop-in ranlib' 23 | 'objcopy:Use Zig as a drop-in objcopy' 24 | 'rc:Use Zig as a drop-in rc.exe' 25 | 'env:Print lib path, std path, cache directory, and version' 26 | 'help:Print this help and exit' 27 | 'std:View standard library documentation in a browser' 28 | 'libc:Display native libc paths file or validate one' 29 | 'targets:List available compilation targets' 30 | 'version:Print version number and exit' 31 | 'zen:Print Zen of Zig and exit' 32 | ) 33 | 34 | __zig_general_options=( 35 | '--color[Enable or disable colored error messages]: :(on off auto)' 36 | '-j[Limit concurrent jobs (default is to use all CPU cores)]:int' 37 | '-fincremental[Enable incremental compilation]' 38 | '-fno-incremental[Disable incremental compilation]' 39 | '-femit-bin=[(default) Output machine code]:path:_files -/' 40 | '-fno-emit-bin[Do not output machine code]:' 41 | '-femit-asm[Output .s (assembly code)]:path:_files -/' 42 | '-fno-emit-asm[(default) Do not output .s (assembly code)]:' 43 | '-femit-llvm-ir[Produce a .ll file with LLVM IR (requires LLVM extensions)]:path:_files -/' 44 | '-fno-emit-llvm-ir[(default) Do not produce a .ll file with LLVM IR]:' 45 | '-femit-llvm-bc[Produce a LLVM module as a .bc file (requires LLVM extensions)]:path:_files -/' 46 | '-fno-emit-llvm-bc[(default) Do not produce a LLVM module as a .bc file]' 47 | '-femit-h[Generate a C header file (.h)]:path:_files -/' 48 | '-fno-emit-h[(default) Do not generate a C header file (.h)]:' 49 | '-femit-docs[Create a docs/ dir with html documentation]:path:_files -/' 50 | '-fno-emit-docs[(default) Do not produce docs/ dir with html documentation]:' 51 | '-femit-implib[(default) Produce an import .lib when building a Windows DLL]:path:_files -/' 52 | '-fno-emit-implib[Do not produce an import .lib when building a Windows DLL]:' 53 | '--show-builtin[Output the source of @import("builtin") then exit]:' 54 | '--cache-dir[Override the local cache directory]:path:_files -/' 55 | '--global-cache-dir[Override the global cache directory]:path:_files -/' 56 | '--zig-lib-dir[Override path to Zig installation lib directory]:path:_files -/' 57 | ) 58 | 59 | __zig_compile_options=( 60 | '--name[Override root name (not a file path)]:name' 61 | '--libc[Provide a file which specifies libc paths]:dir:_files' 62 | '-x[Treat subsequent input files as having type ]:language' 63 | '--dep[Add an entry to the next module''s import table]:import' 64 | '-M[Create a module based on the current per-module settings. The first module is the main module. "std" can be configured by omitting src After a -M argument, per-module settings are reset.]:name' 65 | '--error-limit[Set the maximum amount of distinct error values]:int' 66 | '-fllvm[Force using LLVM as the codegen backend]' 67 | '-fno-llvm[Prevent using LLVM as a codegen backend]' 68 | '-flibllvm[Force using the LLVM API in the codegen backend]' 69 | '-fno-libllvm[Prevent using the LLVM API in the codegen backend]' 70 | '-fclang[Force using Clang as the C/C++ compilation backend]' 71 | '-fno-clang[Prevent using Clang as the C/C++ compilation backend]' 72 | '-fPIE[Force-enable Position Independent Executable]' 73 | '-fno-PIE[Force-disable Position Independent Executable]' 74 | '-flto[Force-enable Link Time Optimization (requires LLVM extensions)]' 75 | '-fno-lto[Force-disable Link Time Optimization]' 76 | '-fdll-export-fns[Mark exported functions as DLL exports (Windows)]' 77 | '-fno-dll-export-fns[Force-disable marking exported functions as DLL exports]' 78 | '-freference-trace[How many lines of reference trace should be shown per compile error]:int' 79 | '-fno-reference-trace[Disable reference trace]' 80 | '-ffunction-sections[Places each function in a separate section]' 81 | '-fno-function-sections[All functions go into same section]' 82 | '-fdata-sections[Places each data in a separate section]' 83 | '-fno-data-sections[All data go into same section]' 84 | '-fstructured-cfg[(SPIR-V) force SPIR-V kernels to use structured control flow]' 85 | '-fno-structured-cfg[(SPIR-V) force SPIR-V kernels to not use structured control flow]' 86 | '-mexec-model=[(WASI) Execution model]:mode:(command reactor)' 87 | '-municode[(Windows) Use wmain/wWinMain as entry point]' 88 | 89 | '-target[-- see the targets command]:target' 90 | '-O-[Choose what to optimize for]:mode:(( 91 | Debug\:"(default) Optimizations off, safety on" 92 | ReleaseFast\:"Optimizations on, safety off" 93 | ReleaseSafe\:"Optimizations on, safety on" 94 | ReleaseSmall\:"Optimize for small binary, safety off" 95 | ))' 96 | '-ofmt=[Override target object format]:mode:(( 97 | elf\:"Executable and Linking Format" 98 | c\:"Compile to C source code" 99 | wasm\:"WebAssembly" 100 | coff\:"Common Object File Format (Windows)" 101 | macho\:"macOS relocatables" 102 | spriv\:"Standard, Portable Intermediate Representation V (SPIR-V)" 103 | plan9\:"Plan 9 from Bell Labs object format" 104 | hex\:"Intel IHEX (planned)" 105 | raw\:"Dump machine code directly (planned)" 106 | ))' 107 | '-mcpu[Specify target CPU and feature set]:cpu' 108 | '-mcmodel=[Limit range of code and data virtual addresses]:model:(default extreme kernel large medany medium medlov medmid normal small tiny)' 109 | '-mred-zone[Force-enable the "red-zone"]' 110 | '-mno-red-zone[Force-disable the "red-zone"]' 111 | '-fomit-frame-pointer[Omit the stack frame pointer]' 112 | '-fno-omit-frame-pointer[Store the stack frame pointer]' 113 | '-fPIC[Force-enable Position Independent Code]' 114 | '-fno-PIC[Force-disable Position Independent Code]' 115 | '-fstack-check[Enable stack probing in unsafe builds]' 116 | '-fno-stack-check[Disable stack probing in safe builds]' 117 | '-fstack-protector[Enable stack protection in unsafe builds]' 118 | '-fno-stack-protector[Disable stack protection in safe builds]' 119 | '-fvalgrind[Include valgrind client requests in release builds]' 120 | '-fno-valgrind[Omit valgrind client requests in debug builds]' 121 | '-fsanitize-c=[Enable C undefined behavior detection in unsafe builds]:mode:(trap full)' 122 | '-fno-sanitize-c[Disable C undefined behavior detection in safe builds]' 123 | '-fsanitize-thread[Enable Thread Sanitizer]' 124 | '-fno-sanitize-thread[Disable Thread Sanitizer]' 125 | '-ffuzz[Enable fuzz testing instrumentation]' 126 | '-fno-fuzz[Disable fuzz testing instrumentation]' 127 | '-fbuiltin[Enable implicit builtin knowledge of functions]' 128 | '-fno-builtin[Disable implicit builtin knowledge of functions]' 129 | '-funwind-tables[Always produce unwind table entries for all functions]' 130 | '-fasync-unwind-tables[Always produce asynchronous unwind table entries for all functions]' 131 | '-fno-unwind-tables[Never produce unwind table entries]' 132 | '-ferror-tracing[Enable error tracing in ReleaseFast mode]' 133 | '-fno-error-tracing[Disable error tracing in Debug and ReleaseSafe mode]' 134 | '-fsingle-threaded[Code assumes there is only one thread]' 135 | '-fno-single-threaded[Code may not assume there is only one thread]' 136 | '-fstrip[Omit debug symbols]' 137 | '-fno-strip[Keep debug symbols]' 138 | '-idirafter[Add directory to AFTER include search path]:dir:_files -/' 139 | '-isystem[Add directory to SYSTEM include search path]:dir:_files -/' 140 | '-I-[Add directory to include search path]:dir:_files -/' 141 | '-D[Define C \[macro\] to \[value\] (1 if \[value\] omitted)]:string' 142 | '-cflags[Set extra flags for the next positional C source files]:[flags]' 143 | '-rcincludes=[Set the type of includes to use when compiling .rc source files]:type:(( 144 | any\:"(default) Use msvc if available, fall back to gnu" 145 | msvc\:"Use msvc include paths (must be present on the system)" 146 | gnu\:"Use mingw include paths (distributed with Zig)" 147 | none\:"Do not use any autodetected include paths" 148 | ))' 149 | ) 150 | 151 | __zig_link_options=( 152 | '-T-[Use a custom linker script]:script:_files' 153 | '--version-script[Provide a version .map file]:path:_files -/' 154 | '--undefined-version[Allow version scripts to refer to undefined symbols]' 155 | '--no-undefined-version[(default) Disallow version scripts from referring to undefined symbols]' 156 | '--enable-new-dtags[Use the new behavior for dynamic tags (RUNPATH)]' 157 | '--disable-new-dtags[Use the old behavior for dynamic tags (RPATH)]' 158 | '--dynamic-linker[Set the dynamic interpreter path (usually ld.so)]:path:_files -/' 159 | '--sysroot[Set the system root directory (usually /)]:path:_files -/' 160 | '--version[Dynamic library semver]:string' 161 | '-fentry=[Set the entrypoint symbol name]:string' 162 | '-fno-entry[Do not output any entry point]' 163 | '--force_undefined[Specify the symbol must be defined for the link to succeed]:name' 164 | '-fsoname=[Override the default SONAME value]:name' 165 | '-fno-soname[Disable emitting a SONAME]' 166 | '-flld[Force using LLD as the linker]' 167 | '-fno-lld[Prevent using LLD as the linker]' 168 | '-fcompiler-rt[Always include compiler-rt symbols in output]' 169 | '-fno-compiler-rt[Prevent including compiler-rt symbols in output]' 170 | '-fubsan-rt[Always include ubsan-rt symbols in the output]' 171 | '-fno-ubsan-rt[Prevent including ubsan-rt symbols in the output]' 172 | '-rdynamic[Add all symbols to the dynamic symbol table]' 173 | '-feach-lib-rpath[Ensure adding rpath for each used dynamic library]' 174 | '-fno-each-lib-rpath[Prevent adding rpath for each used dynamic library]' 175 | '-fallow-shlib-undefined[Allows undefined symbols in shared libraries]' 176 | '-fno-allow-shlib-undefined[Disallows undefined symbols in shared libraries]' 177 | '-fallow-so-scripts[Allows .so files to be GNU ld scripts]' 178 | '-fno-allow-so-scripts[(default) .so files must be ELF files]' 179 | '--build-id=[At a minor link-time expense, embeds a build ID in binaries]:style:(( 180 | fast\:"8-byte non-cryptographic hash (COFF, ELF, WASM)" 181 | sha1, tree\:"20-byte cryptographic hash (ELF, WASM)" 182 | md5\:"16-byte cryptographic hash (ELF)" 183 | uuid\:"16-byte random UUID (ELF, WASM)" 184 | 0x[hexstring]\:"Constant ID, maximum 32 bytes (ELF, WASM)" 185 | none\:"(default) No build ID" 186 | ))' 187 | '--eh-frame-hdr[Enable C++ exception handling by passing --eh-frame-hdr to linker]' 188 | '--no-eh-frame-hdr[Disable C++ exception handling by passing --no-eh-frame-hdr to linker]' 189 | '--emit-relocs[Enable output of relocation sections for post build tools]' 190 | '-z[Set linker extension flags]: :(( 191 | nodelete\:"Indicate that the object cannot be deleted from a process" 192 | notext\:"Permit read-only relocations in read-only segments" 193 | defs\:"Force a fatal error if any undefined symbols remain" 194 | undefs\:"Reverse of -z defs" 195 | origin\:"Indicate that the object must have its origin processed" 196 | nocopyreloc\:"Disable the creation of copy relocations" 197 | now\:"(default) Force all relocations to be processed on load" 198 | lazy\:"Do not force all relocations to be processed on load" 199 | relro\:"(default) Force all relocations to be read-only after processing" 200 | norelro\:"Do not force all relocations to be read-only after processing" 201 | common-page-size=\:"Set the common page size for ELF binaries" 202 | max-page-size=\:"Set the max page size for ELF binaries" 203 | ))' 204 | '-dynamic[Force output to be dynamically linked]' 205 | '-static[Force output to be statically linked]' 206 | '-Bsymbolic[Bind global references locally]' 207 | '--compress-debug-sections=[Debug section compression settings]: :(( 208 | none\:"No compression" 209 | zlib\:"Compression with deflate/inflate" 210 | zstd\:"Compression with zstandard" 211 | ))' 212 | '--gc-sections[Force removal of functions and data that are unreachable by the entry point or exported symbols]' 213 | '--no-gc-sections[Do not force removal of unreachable functions and data]' 214 | '--sort-section=[Sort wildcard section patterns by ''name'' or ''alignment'']:value' 215 | '--subsystem[(Windows) /SUBSYSTEM: to the linker]:subsystem' 216 | '--stack[Override default stack size]:int' 217 | '--image-base[Set base address for executable image]:int' 218 | '-install_name=[(Darwin) add dylibs install name]:string' 219 | '--entitlements[(Darwin) add path to entitlements file for embedding in code signature]:path:_files -/' 220 | '-pagezero_size[(Darwin) size of the __PAGEZERO segment in hexadecimal notation]:int' 221 | '-headerpad[(Darwin) set minimum space for future expansion of the load commands in hexadecimal notation]:int' 222 | '-headerpad_max_install_names[(Darwin) set enough space as if all paths were MAXPATHLEN]' 223 | '-dead_strip[(Darwin) remove functions and data that are unreachable by the entry point or exported symbols]' 224 | '-dead_strip_dylibs[(Darwin) remove dylibs that are unreachable by the entry point or exported symbols]' 225 | '-ObjC[(Darwin) force load all members of static archives that implement an Objective-C class or category]' 226 | '--import-memory[(WebAssembly) import memory from the environment]' 227 | '--export-memory[(WebAssembly) export memory to the host (Default unless --import-memory used)]' 228 | '--import-symbols[(WebAssembly) import missing symbols from the host environment]' 229 | '--import-table[(WebAssembly) import function table from the host environment]' 230 | '--export-table[(WebAssembly) export function table to the host environment]' 231 | '--initial-memory=[(WebAssembly) initial size of the linear memory]:int' 232 | '--max-memory=[(WebAssembly) maximum size of the linear memory]:int' 233 | '--shared-memory[(WebAssembly) use shared linear memory]' 234 | '--global-base=[(WebAssembly) where to start to place global data]:int' 235 | 236 | '-l-[Link against system library (only if actually used)]:library:__zig_library' 237 | '--library[Link against system library (only if actually used)]:library:__zig_library' 238 | '-needed-l-[Link against system library (even if unused)]:library:__zig_library' 239 | '--needed-library[Link against system library (even if unused)]:library:__zig_library' 240 | '-weak-l-[(Darwin) link against system library and mark it and all referenced symbols as weak]:library:__zig_library' 241 | '-L-[Add a directory to the library search path]:d:_files -/' 242 | '--library-directory[Add a directory to the library search path]:d:_files -/' 243 | '-search_paths_first[For each library search path, check for dynamic lib then static lib before proceeding to next path]' 244 | '-search_paths_first_static[For each library search path, check for static lib then dynamic lib before proceeding to next path]' 245 | '-search_dylibs_first[Search for dynamic libs in all library search paths, then static libs]' 246 | '-search_static_first[Search for static libs in all library search paths, then dynamic libs]' 247 | '-search_dylibs_only[Only search for dynamic libs]' 248 | '-search_static_only[Only search for static libs]' 249 | '-rpath[Add directory to the runtime library search path]:path:_files -/' 250 | '-framework[(Darwin) link against framework]:framework' 251 | '-needed_framework[(Darwin) link against framework (even if unused)]:framework' 252 | '-weak_framework[(Darwin) link against framework and mark it and all referenced symbols as weak]:framework' 253 | '-F[(Darwin) add search path for frameworks]:dir:_files -/' 254 | '--export=[(WebAssembly) Force a symbol to be exported]:string' 255 | ) 256 | 257 | __zig_debug_options=( 258 | '-fopt-bisect-limit=[Only run first LLVM optimization passes]:int' 259 | '-ftime-report[Print timing diagnostics]' 260 | '-fstack-report[Print stack size diagnostics]' 261 | '--verbose-link[Display linker invocations]' 262 | '--verbose-cc[Display C compiler invocations]' 263 | '--verbose-air[Enable compiler debug output for Zig AIR]' 264 | '--verbose-intern-pool[Enable compiler debug output for InternPool]' 265 | '--verbose-generic-instances[Enable compiler debug output for generic instance generation]' 266 | '--verbose-llvm-ir[Enable compiler debug output for LLVM IR]' 267 | '--verbose-llvm-bc=[Enable compiler debug output for unoptimized LLVM BC]:path' 268 | '--verbose-cimport[Enable compiler debug output for C imports]' 269 | '--verbose-llvm-cpu-features[Enable compiler debug output for LLVM CPU features]' 270 | '--debug-log[Enable printing debug/info log messages for scope]:string' 271 | '--debug-compile-errors[Crash with helpful diagnostics at the first compile error]' 272 | '--debug-link-snapshot[Enable dumping of the linkers state in JSON format]' 273 | '--debug-rt[Debug compiler runtime libraries]' 274 | '*:files:__zig_files' 275 | ) 276 | 277 | __zig_test_options=( 278 | '--test-filter[Skip tests that do not match filter]:string' 279 | '--test-name-prefix[Add prefix to all tests]:string' 280 | '--test-cmd[Specify test execution command one arg at a time]:string' 281 | '--test-cmd-bin[Appends test binary path to test cmd args]' 282 | '--test-evented-io[Runs the test in evented I/O mode]' 283 | '--test-no-exec[Compiles test binary without running it]' 284 | '--test-runner[Specify a custom test runner]:path' 285 | ) 286 | 287 | __zig_files() { 288 | _files -g "*.{zig,o,obj,lib,a,so,dll,dylib,tbd,s,S,c,cpp,C,cc,cxx,c++,bc,def,rc,res}" 289 | } 290 | 291 | __zig_library() { 292 | _wanted libraries expl library \ 293 | compadd - \ 294 | ${^=LD_LIBRARY_PATH:-/usr/lib /usr/local/lib}/lib*.(a|so*)(:t:fr:s/lib//) 295 | } 296 | 297 | __zig_build() { 298 | steps=() 299 | args=( 300 | '-p-[Override default install prefix]:path:_files -/' 301 | '--prefix[Override default install prefix]:path:_files -/' 302 | '--prefix-lib-dir[Override default library directory path]:path:_files -/' 303 | '--prefix-exe-dir[Override default executable directory path]:path:_files -/' 304 | '--prefix-include-dir[Override default include directory path]:path:_files -/' 305 | '--release=[Request release mode, optionally specifying a preferred optimization mode: fast, safe, small]:mode:(fast safe small)' 306 | '-fdarling[Enable integration with system-installed Darling to execute macOS programs on Linux hosts]' 307 | '-fno-darling[(default) Disable integration with system-installed Darling to execute macOS programs on Linux hosts]' 308 | '-fqemu[Enable integration with system-installed QEMU to execute foreign-architecture programs on Linux hosts]' 309 | '-fno-qemu[(default) Disable integration with system-installed QEMU to execute foreign-architecture programs on Linux hosts]' 310 | '--libc-runtimes[Enhances QEMU integration by providing dynamic libc (e.g. glibc or musl) built for multiple foreign architectures, allowing execution of non-native]:dir:_files' 311 | '-frosetta[Rely on Rosetta to execute x86_64 programs on ARM64 macOS hosts]' 312 | '-fno-rosetta[(default) Do not rely on Rosetta to execute x86_64 programs on ARM64 macOS hosts]' 313 | '-fwasmtime[Enable integration with system-installed wasmtime to execute WASI binaries]' 314 | '-fno-wasmtime[(default) disable integration with system-installed wasmtime to execute WASI binaries]' 315 | '-fwine[Enable integration with system-installed Wine to execute Windows programs on Linux hosts]' 316 | '-fno-wine[(default) disable integration with system-installed Wine to execute Windows programs on Linux hosts]' 317 | '--verbose[Print commands before executing them]' 318 | '--color[Enable or disable colored error messages]: :(on off auto)' 319 | '--prominent-compile-errors[Output compile errors formatted for a human to read]' 320 | '--summary[Control the printing of the build summary]:mode:(( 321 | all\:"Print the build summary in its entirety" 322 | new\:"Omit cached steps" 323 | failures\:"(Default) Only print failed steps" 324 | none\:"Do not print the build summary" 325 | ))' 326 | '-j[Limit concurrent jobs (default is to use all CPU cores)]:int' 327 | '--maxrss[Limit memory usage (default is to use available memory)]:int' 328 | '--skip-oom-steps[Instead of failing, skip steps that would exceed --maxrss]' 329 | '--fetch=[Fetch dependency tree (optionally choose laziness) and exit]:mode:(( 330 | needed\:"(Default) Lazy dependencies are fetched as needed" 331 | all\:"Lazy dependencies are always fetched" 332 | ))' 333 | '--watch[Continuously rebuild when source files are modified]' 334 | '--fuzz[Continuously search for unit test failures]' 335 | '--debounce[Delay before rebuilding after changed file detected]:int' 336 | '-fincremental[Enable incremental compilation]' 337 | '-fno-incremental[Disable incremental compilation]' 338 | '--sysroot[Set the system root directory (usually /)]:path:_files -/' 339 | '--search-prefix[Add a path to look for binaries, libraries, headers]:path:_files -/' 340 | '--libc[Provide a file which specifies libc paths]:dir:_files' 341 | '--system[Disable package fetching; enable all integrations]:name' 342 | '-fsys=[Enable a system integration]:name' 343 | '-fno-sys=[Disable a system integration]:name' 344 | '-freference-trace=[How many lines of reference trace should be shown per compile error]:int' 345 | '-fno-reference-trace[Disable reference trace]' 346 | '-fallow-so-scripts[Allows .so files to be GNU ld scripts]' 347 | '-fno-allow-so-scripts[(default) .so files must be ELF files]' 348 | '--build-file[Override path to build.zig]:file' 349 | '--cache-dir[Override path to local Zig cache directory]:path' 350 | '--global-cache-dir[Override path to global Zig cache directory]:path' 351 | '--zig-lib-dir[Override path to Zig lib directory]:path' 352 | '--build-runner[Override path to build runner]:file' 353 | '--seed[For shuffling dependency traversal order (default: random)]:int' 354 | '--build-id=[At a minor link-time expense, embeds a build ID in binaries]:style:(( 355 | fast\:"8-byte non-cryptographic hash (COFF, ELF, WASM)" 356 | sha1, tree\:"20-byte cryptographic hash (ELF, WASM)" 357 | md5\:"16-byte cryptographic hash (ELF)" 358 | uuid\:"16-byte random UUID (ELF, WASM)" 359 | 0x[hexstring]\:"Constant ID, maximum 32 bytes (ELF, WASM)" 360 | none\:"(default) No build ID" 361 | ))' 362 | '--debug-log[Enable debugging the compiler]:scope' 363 | '--debug-pkg-config[Fail if unknown pkg-config flags encountered]' 364 | '--debug-rt[Debug compiler runtime libraries]' 365 | '--verbose-link[Enable compiler debug output for linking]' 366 | '--verbose-air[Enable compiler debug output for Zig AIR]' 367 | '--verbose-llvm-ir=[Enable compiler debug output for LLVM IR]:file' 368 | '--verbose-llvm-bc=[Enable compiler debug output for LLVM BC]:file' 369 | '--verbose-cimport[Enable compiler debug output for C imports]' 370 | '--verbose-cc[Enable compiler debug output for C compilation]' 371 | '--verbose-llvm-cpu-features[Enable compiler debug output for LLVM CPU features]' 372 | ) 373 | in_options=false 374 | in_project_options=false 375 | help=$($__zig_exe build --help 2> /dev/null | tail -n +4) 376 | while IFS= read -r line ; do 377 | if [ "$in_options" = "false" ]; then 378 | if [ -z "$line" ]; then 379 | in_options=true 380 | continue 381 | fi 382 | # step (default) description -> step:(default) description 383 | steps+=("$(sed -r 's/^ *([^ ]+)( \(default\))? +(.*) *$/\1:\3\2/' <<<"$line")") 384 | elif [ "$in_project_options" = "false" ]; then 385 | if [ "$line" = "Project-Specific Options:" ]; then 386 | in_project_options=true 387 | continue 388 | fi 389 | elif [ "$line" = "System Integration Options:" ]; then 390 | break 391 | else 392 | if [ -n "$(grep ' -' <<<"$line")" ]; then 393 | # -Dflag=[arg] description -> -Dflag=[description]:arg 394 | args+=("$(sed -r 's/^ *([^\[ ]+) ?(\[([^]]*)\])? *(.+) *$/\1[\4]:\3/' <<<"$line")") 395 | fi 396 | fi 397 | done <<< $help 398 | 399 | if [ -z "$(grep "^-" <<<$words[$CURRENT])" ]; then 400 | _describe 'step' steps 401 | else 402 | _arguments ${args[@]} 403 | fi 404 | } 405 | 406 | __zig_exe=$words[1] 407 | 408 | _arguments \ 409 | "1: :{_describe 'command' __zig_commands}" \ 410 | "*:: :->args" 411 | 412 | case $state in 413 | args) 414 | 415 | case $words[1] in 416 | build-exe | build-lib | build-obj | run | translate-c) 417 | _arguments $__zig_general_options $__zig_compile_options $__zig_link_options $__zig_debug_options 418 | ;; 419 | 420 | test) 421 | _arguments $__zig_general_options $__zig_compile_options $__zig_link_options $__zig_debug_options $__zig_test_options 422 | ;; 423 | 424 | fmt) 425 | _arguments \ 426 | '--stdin[Format code from stdin; output to stdout]:' \ 427 | '--color[Enable or disable colored error messages]: :(on off auto)' \ 428 | '--check[List non-conforming files and exit with an error if the list is non-empty]' \ 429 | '--ast-check[Run zig ast-check on every file]' \ 430 | '--exclude[Exclude file or directory from formatting]:path:_files -/' \ 431 | '--zon[Treat all input files as ZON, regardless of file extension]' \ 432 | '*:files:_files -g "*.{zig,zon}"' 433 | ;; 434 | 435 | build) 436 | __zig_build 437 | ;; 438 | 439 | esac 440 | ;; 441 | esac 442 | --------------------------------------------------------------------------------