Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for evalcache Demo and .zshrc Usage Example #11

Open
laleoarrow opened this issue Oct 26, 2024 · 1 comment
Open

Request for evalcache Demo and .zshrc Usage Example #11

laleoarrow opened this issue Oct 26, 2024 · 1 comment

Comments

@laleoarrow
Copy link

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!

@mroth
Copy link
Owner

mroth commented Feb 13, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants