marlonrichert / zsh-snap

⚡️ Znap! Fast, easy-to-use tools for Zsh dotfiles & plugins, plus git repos
MIT License
1.32k stars 38 forks source link

Cache command output for `znap fpath` #266

Closed vhdirk closed 9 months ago

vhdirk commented 11 months ago

Describe the bug

znap fpath does not cache the result of the function it evaluates, causing it to run everytime a new terminal is openened.
While the prompt renders immediately, the first command then takes some time.

Steps To Reproduce

In .zshrc:


REPOS_DIR=$HOME/.dotfiles/repos
[[ -r $REPOS_DIR/zsh-snap/znap.zsh ]] || git clone --depth 1 -- https://github.com/marlonrichert/zsh-snap.git $REPOS_DIR/zsh-snap
source $REPOS_DIR/zsh-snap/znap.zsh  # Start Znap

_has() {
  command -v "$1" 1>/dev/null 2>&1
}

if _has helm; then
  znap fpath _helm 'echo `date` >> /tmp/shouldnottouch && helm completion zsh'
fi

Then open a new terminal. Then open another one.

Expected behavior

If the output of helm completion zsh is cached, /tmp/shouldnottouch should only contain a single line

Observed behavior

/tmp/shouldnottouch contains 2 lines, meaning that the command ran twice

Environment:

Additional context

vhdirk commented 11 months ago

After reading the docs once again, I must admit I was mistaken. It doesn't mention caching for fpath anywhere. So this is actually more of a feature request

marlonrichert commented 9 months ago

I'm going to replace built-in caching of znap commands with a dedicated znap cache command. So, I will close this issue, but you'll be able to use that instead. 🙂