Zigのcompletionを利用する
先日から試している zig ですが Zsh 用に completion が用意されていたので導入しました。
fpath を確認する
自分は .zshrc にて以下のように設定しています。
# completionを追加
fpath=($(brew --prefix)/share/zsh/site-functions $fpath)
echo して確認してみます。
$ echo $fpath
/usr/local/share/zsh/site-functions /usr/local/share/zsh/site-functions /usr/local/Cellar/zsh/5.8_1/share/zsh/functions
このようになっていました。先頭の /usr/local/share/zsh/site-functions が被ってますがひとまず気にせずに行きます。
公式のスクリプトを導入
zig 公式に用意されているのでダウンロードします。
リポジトリ: ziglang/shell-completions: Shell completions for the Zig compiler.
$ curl -s -O https://raw.githubusercontent.com/ziglang/shell-completions/master/_zig
$ sudo mv _zig /usr/local/share/zsh/site-functions
completion 用のスクリプトは実行権限は必要ないのでこれで完了です。
確認
zig と入力して TAB を入力してみたら以下のように補完されました。
$ zig
build        -- Build project from build.zig
build-exe    -- Create executable from source or object files
build-lib    -- Create library from source or object files
build-obj    -- Create object from source or assembly
c++          -- Use Zig as a drop-in C++ compiler
cc           -- Use Zig as a drop-in C compiler
env          -- Print lib path, std path, compiler id and version
fmt          -- Parse file and render in canonical zig format
init-exe     -- Initialize a `zig build` application in the cwd
init-lib     -- Initialize a `zig build` library in the cwd
libc         -- Display native libc paths file or validate one
run          -- Create executable and run immediately
targets      -- List available compilation targets
test         -- Create and run a test build
translate-c  -- Convert C code to Zig code
version      -- Print version number and exit
zen          -- Print zen of zig and exit