Author: "A Zsh-Zinit annex that installs rust and cargo packages locally inside the plugin or snippet directories."
Go to file
2019-10-19 19:24:42 +02:00
images images: z-a-rust.png 2019-10-17 08:47:17 +02:00
.gitignore .gitignore: Include Zsh template 2019-10-17 04:30:08 +02:00
.za-rust-bin-or-src-function-body *ion-body: .za-rust-bin-or-src-function-body 2019-10-02 01:05:10 +00:00
:za-rust-atclone-handler *atclone-handler: Correctly update the crates 2019-10-19 19:24:08 +02:00
:za-rust-atdelete-handler *atdelete-handler: Silence a warncreateglobal 2019-10-19 19:24:42 +02:00
:za-rust-atload-handler *at{load,pull,delete}-handler: Add empty stubs for the remaining hooks 2019-10-02 01:08:21 +00:00
:za-rust-atpull-handler *at{load,pull,delete}-handler: Add empty stubs for the remaining hooks 2019-10-02 01:08:21 +00:00
:za-rust-help-handler :za-rust-help-handler 2019-10-17 08:48:27 +02:00
LICENSE Initial commit 2019-09-28 05:41:34 +02:00
README.md Updated README.md 2019-10-17 12:18:23 +02:00
z-a-rust.plugin.zsh plugin.zsh,*atclone-handler: Change rustup ice to a no-value ice 2019-10-17 06:20:13 +02:00

z-a-rust

A Zsh-Zplugin 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/.zplugin/plugins/zdharma---null/bin"
    local -x PATH="/root/.zplugin/plugins/zdharma---null"/bin:"$PATH" # -x means export
    local -x RUSTUP_HOME="/root/.zplugin/plugins/zdharma---null"/rustup \
            CARGO_HOME="/root/.zplugin/plugins/zdharma---null"

    "$bindir"/"lsd" "$@"
}

lsd "$@"

As it can be seen shim ultimately provides the binary to the command line.

Usage

The Zplugin 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}]'

Example uses are:

# Installs rust and then the `lsd' crate and creates
# the `lsd' shim exposing the binary
zplugin ice rustup cargo'!lsd'
zplugin load zdharma/null

# Installs rust and then the `exa' crate and creates
# the `ls' shim exposing the `exa' binary
zplugin ice rustup cargo'!exa -> ls'
zplugin load zdharma/null

# Installs rust and then the `exa' and `lsd' crates
zplugin ice rustup cargo'exa;lsd'
zplugin load zdharma/null

# Installs rust and then the `exa' and `lsd' crates
# and exposes their binaries by altering $PATH
zplugin ice rustup cargo'exa;lsd' as"command" pick"bin/(exa|lsd)"
zplugin load zdharma/null

# Installs rust and then the `exa' crate and creates
# its shim with standard error redirected to /dev/null
zplugin ice rustup cargo'!E:exa'
zplugin load zdharma/null

# Just install rust and make it available globally in the system
zplugin ice id-as"rust" wait"0" lucid rustup as"command" \
            pick"bin/rustc" atload="export RUSTUP_HOME=\$PWD/rustup"
zplugin load zdharma/null

Flags meanings:

  • 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.

Installation

Simply load like a regular plugin, i.e.:

zplugin light zplugin/z-a-rust

This installs the annex and makes the rustup and cargo'' ices available.

Example

example z-a-rust
use