Switch to Zim's semi-native eval snippet cache :)

This commit is contained in:
Danielle McLean 2024-03-06 13:22:56 +11:00
parent 30f0f56c4e
commit 7f4cfbcca4
Signed by: 00dani
GPG key ID: 52C059C3B22A753E

View file

@ -1,19 +1,16 @@
# Rather than writing eval "$(something init)" and having it called on every # Rather than writing eval "$(something init)" and having it called on every
# shell initialisation, zeval will use Zim's --on-pull hook to run the command # shell initialisation, zmodule-eval will run the given command once and
# once and cache the output, as well as zcompile it. Pass a descriptive, unique # zcompile its output, which is then sourced. Naturally this is vastly more
# name as the first argument and the Zsh command you'd normally write inside # efficient. Pass the external command's name as the first argument and the
# $() as the second. For example, to hook Direnv into your shell: # full Zsh commandline you'd normally write inside $() as the second. For
# zeval direnv 'direnv hook zsh' # example, to hook Direnv into your shell:
zeval() { # zmodule-eval direnv 'direnv hook zsh'
zmodule https://git.00dani.me/00dani/null --name zeval-$1 --on-pull "$2 >! init.zsh" # https://github.com/zimfw/zimfw/issues/528#issuecomment-1949609155
} zmodule-eval() {
local -r ztarget=${2//[^[:alnum:]]/-}.zsh
# Hook a command into Zsh, only if that command is installed. Pass the zmodule custom-${1} --use mkdir --if-command ${1} \
# command's name as the first argument and the commandline you want to evaluate --cmd "if [[ ! {}/${ztarget} -nt \${commands[${1}]} ]]; then ${2} >! {}/${ztarget}; zcompile -UR {}/${ztarget}; fi" \
# as the second. Works in the same way as zeval, but silently omits the module --source ${ztarget}
# from your setup if the necessary command is not installed.
zeval-if-installed() {
(( ${+commands[$1]} )) && zeval "$@"
} }
zmodule willghatch/zsh-saneopt --source saneopt.plugin.zsh zmodule willghatch/zsh-saneopt --source saneopt.plugin.zsh
@ -32,7 +29,7 @@ zmodule termtitle
zmodule utility zmodule utility
zmodule romkatv/powerlevel10k --use degit zmodule romkatv/powerlevel10k --use degit
zeval-if-installed vivid 'echo export LS_COLORS=${(qqq)"$(vivid generate catppuccin-mocha)"}' zmodule-eval vivid 'echo export LS_COLORS=${(qqq)"$(vivid generate catppuccin-mocha)"}'
zmodule fzf --name zimfw-fzf zmodule fzf --name zimfw-fzf
zmodule junegunn/fzf --root shell --use degit --source completion.zsh --source key-bindings.zsh zmodule junegunn/fzf --root shell --use degit --source completion.zsh --source key-bindings.zsh
@ -44,9 +41,9 @@ zmodule xPMo/zsh-toggle-command-prefix
zmodule zsh-users/zsh-autosuggestions zmodule zsh-users/zsh-autosuggestions
(( ${+commands[brew]} )) && zmodule homebrew (( ${+commands[brew]} )) && zmodule homebrew
zeval-if-installed atuin 'atuin init zsh --disable-up-arrow' zmodule-eval atuin 'atuin init zsh --disable-up-arrow'
zeval-if-installed direnv 'direnv hook zsh' zmodule-eval direnv 'direnv hook zsh'
zeval-if-installed scmpuff 'scmpuff init --shell=zsh' zmodule-eval scmpuff 'scmpuff init --shell=zsh'
# Additional completion definitions for Zsh. # Additional completion definitions for Zsh.
zmodule zsh-users/zsh-completions --fpath src zmodule zsh-users/zsh-completions --fpath src
@ -55,11 +52,11 @@ zmodule zsh-users/zsh-completions --fpath src
zmodule completion zmodule completion
# Initialise Zoxide after compinit, because it calls compdef if available. # Initialise Zoxide after compinit, because it calls compdef if available.
zeval-if-installed zoxide 'zoxide init zsh' zmodule-eval zoxide 'zoxide init zsh'
# Fish-style syntax highlighting as you type, making the Zsh experience much more friendly! # Fish-style syntax highlighting as you type, making the Zsh experience much more friendly!
zmodule zdharma-continuum/fast-syntax-highlighting zmodule zdharma-continuum/fast-syntax-highlighting
# Hacks! The fast-theme function provides its own caching, so we only want to call it when the theme actually updates. # Hacks! The fast-theme function provides its own caching, so we only want to call it when the theme actually updates.
zmodule catppuccin/zsh-fsh --name 'catppuccin-for-fsh' --on-pull 'echo "fast-theme $PWD/themes/catppuccin-mocha.ini && echo >! $PWD/init.zsh" >! init.zsh' zmodule catppuccin/zsh-fsh --name 'catppuccin-for-fsh' --on-pull 'echo "fast-theme $PWD/themes/catppuccin-mocha.ini && echo >! $PWD/init.zsh" >! init.zsh'
unfunction zeval zeval-if-installed unfunction zmodule-eval