evalcache icon indicating copy to clipboard operation
evalcache copied to clipboard

Request for evalcache Demo and .zshrc Usage Example

Open laleoarrow opened this issue 1 year ago • 1 comments

Hello,

Thank you for developing evalcache! I’m trying to improve my zsh startup time using your plugin but am struggling with setting it up correctly in my .zshrc. Specifically, I’d like to cache some commands that slow down the shell load time.

I’ve installed evalcache using oh-my-zsh by cloning it into the custom plugins folder and adding evalcache to my plugin list. However, I’m unsure how to modify my .zshrc to make full use of _evalcache.

Would it be possible for you to provide a demo or example configuration showing how to apply _evalcache to typical commands? Here’s an example of my current setup:

# Enable Powerlevel10k instant prompt
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Path to oh-my-zsh
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"

# Plugins
plugins=(git sudo zsh-syntax-highlighting zsh-autosuggestions evalcache)

# Load oh-my-zsh
source $ZSH/oh-my-zsh.sh

# Conda initialize (example of slow-loading command)
__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
  eval "$__conda_setup"
else
  if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
    . "/opt/anaconda3/etc/profile.d/conda.sh"
  else
    export PATH="/opt/anaconda3/bin:$PATH"
  fi
fi
unset __conda_setup

# Custom paths
export PATH="/path/to/software/bin:$PATH"

Questions:

  1. How should I apply _evalcache to commands like conda initialization to ensure they’re cached?
  2. Could you provide a basic demo of evalcache usage in .zshrc for common scenarios like initializing conda, Powerlevel10k, or other plugins?

Thank you for any guidance, and for a tool that could greatly improve my workflow!

laleoarrow avatar Oct 26 '24 12:10 laleoarrow

Hi sorry I just saw this.

Unless I'm misreading, in your case the eval line that is slow is effectively: eval "$(/opt/anaconda3/bin/conda shell.zsh hook 2> /dev/null)"

I'm not sure if/how the redirecting stderr to /dev/null/ in your example changes things, but in a typical case you would simply rewrite as: _evalcache /opt/anaconda3/bin/conda shell.zsh hook 2> /dev/null

LMK if that works or if the redirection breaks it.

mroth avatar Feb 13 '25 15:02 mroth