Skip to content

Commit 492cad0

Browse files
gbrlsGabriel Schneider
andauthored
Add zig and zvm completions (#1224)
Hey, I've been using this script for a while. Aside from adding documentation for the commands manually copied from the help, it has custom completions for listing `zvm` versions, and listing `zig build` targets. As an unexpected nice thing, when completing for the `zig build` command, it will rebuild the zig build script automatically, which is a nice _side effect_. --------- Co-authored-by: Gabriel Schneider <gbrls@0x4200.cafe>
1 parent 6860e79 commit 492cad0

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

custom-completions/zig/readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# `zig` custom completions
2+
3+
This script provides custom completions for `zig` and `zvm`.
4+
It can be used by importing its exported commands via:
5+
6+
```
7+
use path/to/zig/zig-completions.nu *
8+
```
9+
10+
With `path/to/` being either the relative path of the file to your current working directory or its absolute path.
11+
12+
The completion for `zig build` has a side-effect of rebuilding the build script to list the configured build steps.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# zvm
2+
def "nu-complete zvm versions" [] {
3+
^zvm list
4+
| lines
5+
}
6+
7+
# switch between versions of Zig
8+
export extern "zvm use" [
9+
--sync #sync your current version of Zig with the repository
10+
--help(-h)
11+
version: string@"nu-complete zvm versions"
12+
]
13+
14+
# download and install a version of Zig
15+
export extern "zvm install" []
16+
# run a command with the given Zig version
17+
export extern "zvm run" []
18+
# list installed Zig versions. Flag `--all` to see remote options
19+
export extern "zvm list" []
20+
# remove an installed version of Zig
21+
export extern "zvm uninstall" []
22+
# remove build artifacts (good if you're a scrub)
23+
export extern "zvm clean" []
24+
# self-upgrade ZVM
25+
export extern "zvm upgrade" []
26+
# set ZVM's mirror list URL for custom Zig distribution servers, or set to "disabled" to download directly from ziglang.org
27+
export extern "zvm mirrorlist" []
28+
# set ZVM's version map URL for custom Zig distribution servers
29+
export extern "zvm vmu" []
30+
# Shows a list of commands or help for one command
31+
export extern "zvm help" []
32+
# =======
33+
34+
# zig
35+
# =======
36+
37+
def "nu-complete zig build" [] {
38+
^zig build -l
39+
| lines
40+
| parse --regex "^ ([a-z]+)"
41+
| get "capture0"
42+
}
43+
44+
# Build project from build.zig
45+
export extern "zig build" [
46+
step: string@"nu-complete zig build"
47+
]
48+
49+
50+
# Copy a package into global cache and print its hash
51+
export extern "zig fetch" []
52+
# Initialize a Zig package in the current directory
53+
export extern "zig init" []
54+
# Create executable from source or object files
55+
export extern "zig build-exe" []
56+
# Create library from source or object files
57+
export extern "zig build-lib" []
58+
# Create object from source or object files
59+
export extern "zig build-obj" []
60+
# Perform unit testing
61+
export extern "zig test" []
62+
# Create object for unit testing
63+
export extern "zig test-obj" []
64+
# Create executable and run immediately
65+
export extern "zig run" []
66+
# Look for simple compile errors in any set of files
67+
export extern "zig ast-check" []
68+
# Reformat Zig source into canonical form
69+
export extern "zig fmt" []
70+
# Minimize a bug report
71+
export extern "zig reduce" []
72+
# Convert C code to Zig code
73+
export extern "zig translate-c" []
74+
# Use Zig as a drop-in archiver
75+
export extern "zig ar" []
76+
# Use Zig as a drop-in C compiler
77+
export extern "zig cc" []
78+
# Use Zig as a drop-in C++ compiler
79+
export extern "zig c++" []
80+
# Use Zig as a drop-in dlltool.exe
81+
export extern "zig dlltool" []
82+
# Use Zig as a drop-in lib.exe
83+
export extern "zig lib" []
84+
# Use Zig as a drop-in ranlib
85+
export extern "zig ranlib" []
86+
# Use Zig as a drop-in objcopy
87+
export extern "zig objcopy" []
88+
# Use Zig as a drop-in rc.exe
89+
export extern "zig rc" []
90+
# Print lib path, std path, cache directory, and version
91+
export extern "zig env" []
92+
# Print this help and exit
93+
export extern "zig help" []
94+
# View standard library documentation in a browser
95+
export extern "zig std" []
96+
# Display native libc paths file or validate one
97+
export extern "zig libc" []
98+
# List available compilation targets
99+
export extern "zig targets" []
100+
# Print version number and exit
101+
export extern "zig version" []
102+
# Print Zen of Zig and exit
103+
export extern "zig zen" []

0 commit comments

Comments
 (0)