Clover

June 18, 2024 ยท View on GitHub

๐Ÿ€ a configurable theme for zsh, inspired by zeta-zsh-theme and pure.

screenshot

  • Highlights environment changes

    Username and host changes the style for special environments: root, remote, container

  • Async VCS status

    Background process, don't blocks your workflow

  • Execution time

    Show human readable execution time for long run command

  • Python

    Virtualenv prompt is included

  • Show the error

    Prompt indicator changes whether the last run success (๐Ÿ€/๐Ÿ”ฅ)

  • Configurable

    Read the configuration section below

Installation

oh-my-zsh

clone this repo into $ZSH_CUSTOM:

cd ${ZSH_CUSTOM:-"~/.oh-my-zsh/custom"}/themes
git clone git@github.com:tzing/clover.zsh-theme.git clover

then change the theme:

ZSH_THEME="clover/clover"

zinit

zinit light tzing/clover.zsh-theme

Manual

clone this repo to somewhere you like:

git clone git@github.com:tzing/clover.zsh-theme.git <PATH>

and source the main script in your .zshrc

source <PATH>/clover.zsh-theme

Configurations

This theme reads the configurations from zstyle. All context name must be prefixed with :prompt:clover:. Styles are always configurable, and for some components you could also customized the symbols.

Here's a disgram that shows context names:

   โ”Œ---------------------------------------------------------------------- user
   |    โ”Œ----------------------------------------------------------------- host
   |    |         โ”Œ------------------------------------------------------- path
   |    |         |                   โ”Œ----------------------------------- vcs:branch
   |    |         |                   |    โ”Œ------------------------------ vcs:status (read details below)
   |    |         |                   |    |          โ”Œ------------------- execution-time
   |    |         |                   |    |          |    โ”Œ-------------- current-time
#  user@hostname: ~/clover.zsh-theme <main โœ”โ‡ก>        10s (12:00:00 +0800)
(.venv) ๐Ÿ€
 |      โ””----------------------------------------------------------------- prompt
 โ””------------------------------------------------------------------------ virtualenv

Note

VCS information (:prompt:clover:vcs:*) are evaluated in background process, which is forked in first precmd run. Runtime zstyle settings will not take effect. But you could still change the style in .zshrc.

Styles

Run zstyle command with the key style. And the value could be the visual effect expresssion in zsh prompt expansion.

An example of setting the path to bold cyan:

zstyle :prompt:clover:path style '%B%F{cyan}'

Symbols

Use key symbol for customization.

For example, setting default prompt symbol to $:

zstyle :prompt:clover:prompt:default symbol '$'

Contexts and default styles

context nameusagedefault styledefault symbol
current-timeCurrent timeblue
execution-timeLast execution time242
host:containerHost name when it is inside a containerbold white text in magenta bg
host:defaultHost namebold cyan
host:remoteHost name when it is remote sessionbold white text in blue bg
pathCurrent pathbold yellow
prompt:defaultPrompt colorgreen๐Ÿ€
prompt:failPrompt color when last run failedred๐Ÿ”ฅ
user:defaultUser namebold green
user:rootUser name when current user is rootbold green
vcs:actionCurrent action in VCSred
vcs:branchCurrent branch namebold blue
vcs:status:ahead[Git only] Current branch is ahead of remotecyanโ‡ก
vcs:status:behind[Git only] Current branch is behind of remotemagentaโ‡ฃ
vcs:status:clean[Git only] Work tree is cleangreenโœ”
vcs:status:diverge[Git only] Diverged changes foundredโ‡•
vcs:status:stagedFound staged changes in current repogreenโ‰ก
vcs:status:unstagedFound unstaged changes in current repomagentaโœฑ
vcs:status:untracked[Git only] Found untracked file242?
virtualenvPython virtualenv prompt prefix242

Others

There are some other settings could be changed through zstyle too:

context namekeyusagedefault
current-timeformatFormat for current time. See strftime(3) for more details.%H:%M:%S %z
execution-timemin-display-secondOnly show execution time when last run is longer than this time.5