---
title: 🌀 Eval
description: Annex - Eval documentation.
canonical_url: https://wiki.zshell.dev/ecosystem/annexes/eval
markdown_url: https://wiki.zshell.dev/ecosystem/annexes/eval/index.md
locale: en
source_path: ecosystem/annexes/19_eval.mdx
---

<!-- Generated from the canonical Z-Shell Wiki build. The linked human-facing page remains the editorial source of truth. -->

# 🌀 Eval

The output of a slow initialization command is redirected to a file located within the plugin or snippets directory and sourced while loading. The next time the plugin or snippet is loaded, this file will be sourced skipping the need to run the initialization command.

The ice-modifier `eval'…'` provided and handled by this annex creates a `cache` in the plugin or snippets directory which stores the output of the command and the cache is regenerated when:

1.  The plugin or snippet is updated.
2.  The cache file is removed.
3.  When running `zi recache`.

note

The optional preceding `!` flag means to store command output regardless of exit code. Otherwise `eval'…'` will avoid caching the output of code which returns a non-zero exit code.

<a id="example-invocations"></a>

## Example invocations

-   No Eval + Zi
-   Eval + Zi

```zi
zi ice as"command" from"gh-r" \
  atclone"./zoxide init --cmd x zsh > init.zsh" \
  atpull"%atclone" src"init.zsh" nocompile'!'
zi light ajeetdsouza/zoxide
```

```zi
zi ice atclone"dircolors -b LS_COLORS > init.zsh" \
  atpull"%atclone" pick"init.zsh" nocompile'!' \
  atload'zstyle ":completion:*" list-colors ${(s.:.)LS_COLORS}'
zi light trapd00r/LS_COLORS
```

```zi
zi ice as"command" from"gh-r" \
  eval"./zoxide init --cmd x zsh"
zi light ajeetdsouza/zoxide
```

```zi
zi ice eval"dircolors -b LS_COLORS" \
  atload'zstyle ":completion:*" list-colors ${(s.:.)LS_COLORS}'
zi light trapd00r/LS_COLORS
```

-   No Zi + Eval
-   Zi + Eval

```zsh
if [[ "${+commands[kubectl]}" == 1 ]]; then
  eval $(kubectl completion zsh)
fi
```

```zi
zi ice id-as"kubectl_completion" has"kubectl" \
  eval"kubectl completion zsh" run-atpull
zi light z-shell/null
```

<a id="install-eval"></a>

## Install eval

Source

-   [
    
    z-shell/z-a-eval
    
    ](https://github.com/z-shell/z-a-eval)

-   Default
-   Enable Completion

Add the following snippet in the `.zshrc` file:

```zi
zi light z-shell/z-a-eval
```

Add the following snippet in the `.zshrc` file:

> Set value `Z_A_USECOMP=1` to enable <kbd>TAB</kbd> completion for subcommand `recache`.

```zi
zi ice atinit'Z_A_USECOMP=1'
zi light z-shell/z-a-eval
```

This will register subcommand `recache` and `eval'…'` ice-modifier.
