Improve Zshell completion (#19354)

This commit is contained in:
Andrey Makarov 2022-01-18 23:58:18 +03:00 • committed by GitHub
commit d7869a8009
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,150 +1,120 @@
#compdef nim #compdef nim
# Installation note:
# Please name this file as _nim (with underscore!) and copy it to a
# completions directory, either:
# - system wide one, like /usr/share/zsh/functions/Completion/Unix/ on Linux
# - or to a user directory like ~/scripts. Then you also need to add
# that directory in your ~/.zshrc to `fpath` array like so:
# fpath=( ~/scripts "${fpath[@]}" )
_nim() { _nim() {
_arguments -C \ local -a nimCommands=(
':command:(( {compile,c}:'compile project with default code generator C'
{compile,c}\:compile\ project\ with\ default\ code\ generator\ C {compileToC,cc}:'compile project with C code generator'
doc\:generate\ the\ documentation\ for\ inputfile {compileToCpp,cpp}:'compile project to C++ code'
{compileToC,cc}\:compile\ project\ with\ C\ code\ generator {compileToOC,objc}:'compile project to Objective C code'
{compileToCpp,cpp}\:compile\ project\ to\ C++\ code 'js:compile project to Javascript'
{compileToOC,objc}\:compile\ project\ to\ Objective\ C\ code 'e:run a Nimscript file'
js\:compile\ project\ to\ Javascript 'doc:generate the HTML documentation for inputfile'
e\:run\ a\ Nimscript\ file 'rst2html:convert a reStructuredText file to HTML'
rst2html\:convert\ a\ reStructuredText\ file\ to\ HTML 'doc2tex:generate the documentation for inputfile to LaTeX'
rst2tex\:convert\ a\ reStructuredText\ file\ to\ TeX 'rst2tex:convert a reStructuredText file to TeX'
jsondoc\:extract\ the\ documentation\ to\ a\ json\ file 'jsondoc:extract the documentation to a json file'
buildIndex\:build\ an\ index\ for\ the\ whole\ documentation 'buildIndex:build an index for the whole documentation'
genDepend\:generate\ a\ DOT\ file\ containing\ the\ module\ dependency\ graph 'genDepend:generate a DOT file containing the module dependency graph'
dump\:dump\ all\ defined\ conditionals\ and\ search\ paths 'dump:dump all defined conditionals and search paths'
check\:checks\ the\ project\ for\ syntax\ and\ semantic 'check:checks the project for syntax and semantic'
))' \ {--help,-h}:'basic help'
'*-r[run the application]' \ '--fullhelp:show all switches'
'*--run[run the application]' \ {-v,--version}:'show version'
'*-p=[add path to search paths]' \ )
'*--path=[add path to search paths]' \
'*-d=[define a conditional symbol]' \ _arguments '*:: :->anyState' && return 0
'*--define=[define a conditional symbol]' \
'*-u=[undefine a conditional symbol]' \ if (( CURRENT == 1 )); then
'*--undef=[undefine a conditional symbol]' \ _describe -t commands "Nim commands" nimCommands -V1
'*-f[force rebuilding of all modules]' \ return
'*--forceBuild[force rebuilding of all modules]' \ fi
'*--stackTrace=on[turn stack tracing on]' \
'*--stackTrace=off[turn stack tracing off]' \ local -a conditionalSymbols=(
'*--lineTrace=on[turn line tracing on]' \ release danger mingw androidNDK useNimRtl useMalloc noSignalHandler ssl
'*--lineTrace=off[turn line tracing off]' \ debug leanCompiler gcDestructors)
'*--threads=on[turn support for multi-threading on]' \ local -a sharedOpts=(
'*--threads=off[turn support for multi-threading off]' \ {--define\\:-,-d\\:-}'[define a conditional symbol]:x:($conditionalSymbols)'
'*-x=on[turn all runtime checks on]' \ {--undef\\:-,-u\\:-}'[undefine a conditional symbol]:x:($conditionalSymbols)'
'*-x=off[turn all runtime checks off]' \ {--path\\:-,-p\\:-}'[add path to search paths]:x:_files'
'*--checks=on[turn all runtime checks on]' \ '--verbosity\:-[set verbosity level (default\: 1)]:x:(0 1 2 3)'
'*--checks=off[turn all runtime checks off]' \ '--hints\:-[print compilation hints? (or `list`)]:x:(on off list)'
'*--objChecks=on[turn obj conversion checks on]' \ )
'*--objChecks=off[turn obj conversion checks off]' \ local runOpts=(
'*--fieldChecks=on[turn case variant field checks on]' \ {--run,-r}'[run the application]'
'*--fieldChecks=off[turn case variant field checks off]' \ )
'*--rangeChecks=on[turn range checks on]' \ local docOpts=(
'*--rangeChecks=off[turn range checks off]' \ '--index\:-[enable index .idx files?]:x:(on off)'
'*--boundChecks=on[turn bound checks on]' \ '--project\:-[output any dependency for doc?]:x:(on off)'
'*--boundChecks=off[turn bound checks off]' \ '--docInternal\:-[generate module-private documentation?]:x:(on off)'
'*--overflowChecks=on[turn int over-/underflow checks on]' \ )
'*--overflowChecks=off[turn int over-/underflow checks off]' \ local -a codeOpts=(
'*-a[turn assertions on]' \ {--forceBuild,-f}'[force rebuilding of all modules]'
'*-a[turn assertions off]' \ '--stackTrace\:-[enable stack tracing?]:x:(on off)'
'*--assertions=on[turn assertions on]' \ '--lineTrace\:-[enable line tracing?]:x:(on off)'
'*--assertions=off[turn assertions off]' \ '--threads\:-[enable support for multi-threading?]:x:(on off)'
'*--floatChecks=on[turn all floating point (NaN/Inf) checks on]' \ {--checks\\:-,-x\\:-}'[enable/disable all runtime checks?]:x:(on off)'
'*--floatChecks=off[turn all floating point (NaN/Inf) checks off]' \ '--objChecks\:-[enable obj conversion checks]:x:(on off)'
'*--nanChecks=on[turn NaN checks on]' \ '--fieldChecks\:-[enable case variant field checks?]:x:(on off)'
'*--nanChecks=off[turn NaN checks off]' \ '--rangeChecks\:-[enable range checks?]:x:(on off)'
'*--infChecks=on[turn Inf checks on]' \ '--boundChecks\:-[enable bound checks?]:x:(on off)'
'*--infChecks=off[turn Inf checks off]' \ '--overflowChecks\:-[enable integer over-/underflow checks?]:x:(on off)'
'*--nilChecks=on[turn nil checks on]' \ {--assertions\\:-,-a\\:-}'[enable assertions?]:x:(on off)'
'*--nilChecks=off[turn nil checks off]' \ '--floatChecks\:-[enable floating point (NaN/Inf) checks?]:x:(on off)'
'*--opt=none[do not optimize]' \ '--nanChecks\:-[enable NaN checks?]:x:(on off)'
'*--opt=speed[optimize for speed|size - use -d:release for a release build]' \ '--infChecks\:-[enable Inf checks?]:x:(on off)'
'*--opt=size[optimize for size]' \ '--nilChecks\:-[enable nil checks?]:x:(on off)'
'*--debugger:native[use native debugger (gdb)]' \ '--expandArc\:-[show how given proc looks before final backend pass]'
'*--app=console[generate a console app]' \ '--expandMacro\:-[dump every generated AST from given macro]'
'*--app=gui[generate a GUI app]' \ )
'*--app=lib[generate a dynamic library]' \ local -a nativeOpts=(
'*--app=staticlib[generate a static library]' \ '--opt\:-[optimization mode]:x:(none speed size)'
'*--cpu=alpha[compile for Alpha architecture]' \ '--debugger\:native[use native debugger (gdb)]'
'*--cpu=amd64[compile for x86_64 architecture]' \ '--app\:-[generate this type of app (lib=dynamic)]:x:(console gui lib staticlib)'
'*--cpu=arm[compile for ARM architecture]' \ '--cpu\:-[target architecture]:x:(alpha amd64 arm arm64 avr e2k esp hppa i386 ia64 js loongarch64 m68k mips mipsel mips64 mips64el msp430 nimvm powerpc powerpc64 powerpc64el riscv32 riscv64 sparc sparc64 vm wasm32)'
'*--cpu=arm64[compile for ARM64 architecture]' \ '--gc\:-[memory management algorithm to use (default\: refc)]:x:(refc arc orc markAndSweep boehm go regions none)'
'*--cpu=avr[compile for AVR architecture]' \ '--os\:-[operating system to compile for]:x:(AIX Amiga Android Any Atari DOS DragonFly FreeBSD FreeRTOS Genode Haiku iOS Irix JS Linux MacOS MacOSX MorphOS NetBSD Netware NimVM NintendoSwitch OS2 OpenBSD PalmOS Standalone QNX SkyOS Solaris VxWorks Windows)'
'*--cpu=esp[compile for ESP architecture]' \ '--panics\:-[turn panics into process termination (default\: off)]:x:(off on)'
'*--cpu=e2k[compile for Elbrus 2000 architecture]' \ )
'*--cpu=hppa[compile for HPPA architecture]' \
'*--cpu=i386[compile for i386 architecture]' \ case "$words[1]" in
'*--cpu=ia64[compile for ia64 architecture]' \ compile|c|compileToC|cpp|compileToCpp|compileToOC|objc)
'*--cpu=js[compile to JavaScript]' \ _arguments $codeOpts $runOpts $sharedOpts $nativeOpts \
'*--cpu=m68k[compile for m68k architecture]' \ '*:filename:_files -g"*.nim"'
'*--cpu=mips[compile for MIPS architecture]' \ ;;
'*--cpu=mipsel[compile for MIPS EL architecture]' \ js)
'*--cpu=mips64[compile for MIPS64 architecture]' \ _arguments $codeOpts $runOpts $sharedOpts \
'*--cpu=mips64el[compile for MIPS64 EL architecture]' \ '*:filename:_files -g"*.nim"'
'*--cpu=msp430[compile for msp430 architecture]' \ ;;
'*--cpu=nimvm[compile for Nim VM]' \ e)
'*--cpu=powerpc[compile for PowerPC architecture]' \ _arguments $codeOpts $runOpts $sharedOpts \
'*--cpu=powerpc64[compile for PowerPC64 architecture]' \ '*:filename:_files -g"*.nims"'
'*--cpu=powerpc64el[compile for PowerPC64 EL architecture]' \ ;;
'*--cpu=riscv32[compile for RISC-V 32 architecture]' \ doc|doc2tex|jsondoc)
'*--cpu=riscv64[compile for RISC-V 64 architecture]' \ _arguments $runOpts $sharedOpts '*:filename:_files -g"*.nim"'
'*--cpu=sparc[compile for SPARC architecture]' \ ;;
'*--cpu=sparc64[compile for SPARC64 architecture]' \ rst2html|rst2tex)
'*--cpu=vm[compile for Nim VM]' \ _arguments $runOpts $sharedOpts $docOpts '*:filename:_files -g"*.rst"'
'*--cpu=wasm32[compile to WASM 32]' \ ;;
'*--cpu=loongarch64[compile for LoongArch64 architecture]' \ buildIndex|genDepend|check)
'*--gc=refc[use reference counting garbage collection]' \ _arguments $sharedOpts '*:filename:_files -g"*.nim"'
'*--gc=arc[use ARC garbage collection]' \ ;;
'*--gc=orc[use ORC garbage collection]' \ dump)
'*--gc=markAndSweep[use mark-and-sweep garbage collection]' \ _arguments $sharedOpts
'*--gc=boehm[use Boehm garbage collection]' \ ;;
'*--gc=go[use Go garbage collection]' \ *)
'*--gc=regions[use region-based memory management]' \ _arguments '*:filename:_files -g"*"'
'*--gc=none[disable garbage collection]' \ ;;
'*--os=Standalone[generate a stand-alone executable]' \ esac
'*--os=AIX[compile for AIX]' \
'*--os=Amiga[compile for Amiga OS]' \ return 1
'*--os=Android[compile for Android]' \
'*--os=Any[compile for any OS]' \
'*--os=Atari[compile for Atari]' \
'*--os=DOS[compile for DOS]' \
'*--os=DragonFly[compile for DragonFly]' \
'*--os=FreeBSD[compile for FreeBSD]' \
'*--os=FreeRTOS[compile for FreeRTOS]' \
'*--os=Genode[compile for Genode]' \
'*--os=Haiku[compile for Haiku]' \
'*--os=iOS[compile for iOS]' \
'*--os=Irix[compile for Irix]' \
'*--os=Linux[compile for Linux]' \
'*--os=MacOS[compile for MacOS]' \
'*--os=MacOSX[compile for MacOSX]' \
'*--os=MorphOS[compile for MorphOS]' \
'*--os=NetBSD[compile for NetBSD]' \
'*--os=Netware[compile for Netware]' \
'*--os=NimVM[compile for NimVM]' \
'*--os=NintendoSwitch[compile for NintendoSwitch]' \
'*--os=OS2[compile for OS2]' \
'*--os=OpenBSD[compile for OpenBSD]' \
'*--os=PalmOS[compile for PalmOS]' \
'*--os=QNX[compile for QNX]' \
'*--os=SkyOS[compile for SkyOS]' \
'*--os=Solaris[compile for Solaris]' \
'*--os=VxWorks[compile for VxWorks]' \
'*--os=Windows[compile for Windows]' \
'*--os=JS[generate javascript]' \
'*--panics=off[turn panics into process terminations: off by default]' \
'*--panics=on[turn panics into process terminations]' \
'*--verbosity=0[set verbosity to 0]' \
'*--verbosity=1[set verbosity to 1 (default)]' \
'*--verbosity=2[set verbosity to 2]' \
'*--verbosity=3[set verbosity to 3]' \
'*--hints=on[print compilation hints]' \
'*--hints=off[disable compilation hints]' \
'*--hints=list[print compilation hints list]' \
':filename:_files -g"*.nim"'
} }
_nim "$@" _nim "$@"