Awesome
zinit-annex-rust<a name="zinit-annex-rust"></a>
A Zsh-Zinit annex that installs rust and cargo packages locally inside the plugin or snippet directories. The crate can
then have a so called shim created (name borrowed from rbenv
) – a script that's located in the standard $PATH
entry "$ZPFX/bin
" of following contents (example):
#!/usr/bin/env zsh
function lsd {
local bindir="/root/.zinit/plugins/zdharma-continuum---null/bin"
local -x PATH="/root/.zinit/plugins/zdharma-continuum---null"/bin:"$PATH" # -x means export
local -x RUSTUP_HOME="/root/.zinit/plugins/zdharma-continuum---null"/rustup CARGO_HOME="/root/.zinit/plugins/zdharma-continuum---null"
"$bindir"/"lsd" "$@"
}
lsd "$@"
As it can be seen shim ultimately provides the binary to the command line.
<!-- mdformat-toc start --slug=github --maxlevel=6 --minlevel=2 -->- Installation
- Usage
- Examples
- Install rust, the
lsd
crate, and alsd
shim exposing the binary - Install rust, the
exa
crate, and als
shim exposing theexa
binary - Install rust and then the
exa
andlsd
crates - Installs rust and then the
exa' and
lsd' crates and exposes their binaries by altering $PATH - Installs rust and then the
exa
crate and creates its shim with standard error redirected to /dev/null - Install Rust and make it available globally in the system
- Use Bin-Gem-Node annex to install the cargo completion provided with rustup
- Install rust, the
Installation<a name="installation"></a>
Load like a regular plugin, i.e.,:
zi light zdharma-continuum/zinit-annex-rust
This installs the annex and makes the rustup
and cargo''
ices available.
Usage<a name="usage"></a>
The Zinit annex provides two new ices: rustup
and cargo''
. The first one installs rust inside the plugin's folder
using the official rustup
installer. The second one has the following syntax:
cargo"[name-of-the-binary-or-path <-] [[!][c|N|E|O]:]{crate-name} [-> {shim-script-name}]'
Options<a name="options"></a>
Flag | description |
---|---|
N | redirect both standard output and error to /dev/null |
E | redirect standard error to /dev/null |
O | redirect standard output to /dev/null |
c | change the current directory to the plugin's or snippet's directory before executing the command |
As the examples showed, the name of the binary to run and the shim name are by default equal to the name of the crate.
Specifying {binary-name} <- …
and/or … -> {shim-name}
allows to override them.
Examples<a name="examples"></a>
Install rust, the lsd
crate, and a lsd
shim exposing the binary<a name="install-rust-the-lsd-crate-and-a-lsd-shim-exposing-the-binary"></a>
zinit ice rustup cargo'!lsd'
zinit load zdharma-continuum/null
Install rust, the exa
crate, and a ls
shim exposing the exa
binary<a name="install-rust-the-exa-crate-and-a-ls-shim-exposing-the-exa-binary"></a>
zi ice rustup cargo'!exa -> ls'
zi load zdharma-continuum/null
Install rust and then the exa
and lsd
crates<a name="install-rust-and-then-the-exa-and-lsd-crates"></a>
zinit ice rustup cargo'exa;lsd'
zinit load zdharma-continuum/null
Installs rust and then the exa' and
lsd' crates and exposes their binaries by altering $PATH<a name="installs-rust-and-then-the-exa-and-lsd-crates-and-exposes-their-binaries-by-altering-path"></a>
zinit ice rustup cargo'exa;lsd' as"command" pick"bin/(exa|lsd)"
zinit load zdharma-continuum/null
Installs rust and then the exa
crate and creates its shim with standard error redirected to /dev/null<a name="installs-rust-and-then-the-exa-crate-and-creates-its-shim-with-standard-error-redirected-to-devnull"></a>
zinit ice rustup cargo'!E:exa'
zinit load zdharma-continuum/null
Install Rust and make it available globally in the system<a name="install-rust-and-make-it-available-globally-in-the-system"></a>
zi ice \
id-as"rust" \
wait"0" \
lucid \
rustup \
as"command" \
pick"bin/rustc" \
atload='export CARGO_HOME=$PWD RUSTUP_HOME=$PWD/rustup'
zi load zdharma-continuum/null
Use Bin-Gem-Node annex to install the cargo completion provided with rustup<a name="use-bin-gem-node-annex-to-install-the-cargo-completion-provided-with-rustup"></a>
zi for \
atload='
[[ ! -f ${ZINIT[COMPLETIONS_DIR]}/_cargo ]] && zi creinstall rust
export CARGO_HOME=\$PWD RUSTUP_HOME=$PWD/rustup' \
as=null \
id-as=rust \
lucid \
rustup \
sbin="bin/*" \
wait=1 \
zdharma-continuum/null
When using a global installation of rust in turbo mode, cargos need to omit the rustup ice, and wait on $CARGO_HOME
and $RUSTUP_HOME
environment variables to be available
zi for \
wait='[[ -v CARGO_HOME && -v RUSTUP_HOME ]]' \
id-as'rust-exa' \
cargo'!exa' \
zdharma-continuum/null
<!-- vim:set ft=markdown -->