Shibuichi

crates.io docs license tests

A custom zsh prompt expander written in rust.

Shibuichi handles a superset of zsh prompt expansions. Standard zsh prompt expansions are left alone, and this just adds several other expansions, substituting them on the fly:

The conditional expansions for o, p, q, and x are extended so that if no number is passed, you can use a conditional of the form %(x.0-text.1-text.2-text...) to make a branch for each possible value. If the integer is larger than the the number of conditionals, the final text will be used.

Finally the directory command is extended in a slightly breaking change, where

Installation

cargo install shibuichi

Usage

The easiest way to use shibuichi is to pass your old prompt through it in your precmd function and then tweak the command with your extensions. For example:

precmd() { PROMPT="$(shibuichi ' %r %# ')" }

creates a simple prompt that shows your git branch.

Alternatively you can pass several "prompts" and store them in psvar for referencing in your main prompt.

PROMPT=' %1v %2v %# ' precmd() { local IFS=$'\0' psvar=($(shibuichi -0 '%r' '%p')) }

Note however that zsh won't further expand any referenced variables, so you should only include custom expansions, but not builtin ones.

Both versions make it possible to be fault tolerant to the existence of shibuishi by either falling back to a default prompt if it fails, or adding branches for the existence of elements of psvar. The latter can be a bit trickier because no expansion happens after taking a string from psvar, so any expansion must be behind conditionals of the form %x(V...).

Detailed Example

My current prompt, inspired by silver, is:

%F{white}%K{black}%(?.%1(j.   .). %1(j..)  ) %n@%m %F{black}%K{blue}%F{black} %/{::$HOME} %F{blue}%(G.%(y.%K{yellow}.%K{green})%F{black} %(o.....ﴃ.)%1(p. .%1(q. .%1(x. .)))%(p....%p)%(q....%q)%(x....%x) %r%(m. .%(s. .))%(m..)%(s..) %(y.%F{yellow}.%F{green}).)%k%f

Design

There were two major design decisions that influenced shibuichi:

  1. zsh prompt expansion should handle everything it can. This shouldn't reimplement terminal colors, exit code checking, timestamps, etc.
  2. This should be agnostic to prompt style. In particular, this shouldn't make any choices about layout preferences, or character choices, and instead seek to provide the same generality as zsh prompt expansion.

Naming

Shibuichi is an alloy of silver and copper because this was inspired by silver.