Improve zsh performance #1

Merged
jonny merged 1 commit from zsh-neue into main 2026-06-26 15:49:38 +02:00
2 changed files with 54 additions and 104 deletions

View file

@ -51,16 +51,15 @@ github = "junegunn/fzf"
use = ["shell/completion.zsh", "shell/key-bindings.zsh"]
apply = ["defer"]
[plugins.fzf-tab]
github = "Aloxaf/fzf-tab"
apply = ["defer"]
[plugins.fzf-completions]
# compinit must run before fzf-tab and before any plugin that calls `compdef`
# (fnm, zoxide). ZLE-wrapping plugins (autosuggestions, syntax-highlighting)
# must be sourced after fzf-tab.
[plugins.compinit]
local = "~/.zsh/plugins"
apply = ["defer"]
[plugins.zsh-substring-search]
github = "zsh-users/zsh-history-substring-search"
[plugins.fzf-tab]
github = "Aloxaf/fzf-tab"
apply = ["defer"]
[plugins.zsh-autosuggestions]
@ -98,11 +97,6 @@ apply = ["defer"]
github = "zsh-users/zsh-syntax-highlighting"
apply = ["defer"]
# This works best if it is placed last.
[plugins.compinit]
local = "~/.zsh/plugins"
apply = ["defer"]
# Loading indicator
# -----------------

180
zshrc.zsh
View file

@ -14,21 +14,59 @@ export LANG=en_GB.UTF-8
# Preferred editor for local and remote sessions
export EDITOR=nvim
# Auto-add to PATH (needed for MacTex)
# It prepends to $PATH, so we do it first then add our own
if [[ -f /usr/libexec/path_helper ]]; then
eval $(/usr/libexec/path_helper)
fi
# Add our own dirs to the $PATH
if [[ -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if [[ -f /usr/local/bin/brew ]]; then
elif [[ -f /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
export PATH="$HOME/.local/bin:$PATH"
# Go Lang stuff
export GOPATH=$HOME/go
# Homebrew-managed tools
if (( ${+commands[brew]} )); then
# GNU functions - prepend so they override any system installed versions
export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/findutils/libexec/gnubin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/grep/libexec/gnubin:$PATH"
# Homebrew cURL if we have it
test -d $HOMEBREW_PREFIX/opt/curl && export PATH="$HOMEBREW_PREFIX/opt/curl/bin:$PATH"
# Go
export PATH="$PATH:$HOMEBREW_PREFIX/go/bin:$HOMEBREW_PREFIX/opt/go/libexec/bin:$GOPATH/bin"
# Ruby
export PATH="$PATH:$HOMEBREW_PREFIX/opt/ruby/bin"
# PostgreSQL binaries
test -d $HOMEBREW_PREFIX/pgsql && export PATH="$PATH:$HOMEBREW_PREFIX/pgsql/bin"
fi
# Add Obsidian CLI
export PATH="$PATH:/Applications/Obsidian.app/Contents/MacOS"
# Add Totara Docker helper functions
export PATH="$PATH:$HOME/git/totara-docker-dev/bin"
# phpactor installed manually
export PATH="$PATH:$HOME/git/phpactor/bin"
# rust/cargo bin PATH
export PATH="$PATH:$HOME/.cargo/bin"
# PHP binaries
test -d $HOME/.php/bin && export PATH="$PATH:$HOME/.php/bin"
# JetBrains Toolbox scripts
test -d "$HOME/Library/Application Support/JetBrains/Toolbox/scripts" && export PATH="$PATH:$HOME/Library/Application Support/JetBrains/Toolbox/scripts"
# Local Docker if set up that way
test -d $HOME/.docker/bin && export PATH="$HOME/.docker/bin:$PATH"
# credit Paul Irish: https://github.com/paulirish/dotfiles/blob/606d85f083eb53853789ce9dcaf31a49756471bd/.zshrc#L80
# Automatically list directory contents on `cd`.
# Switched to using `eza` instead of `ls`.
@ -44,103 +82,14 @@ if [[ ${chpwd_functions[(ie)ezacd]} -gt ${#chpwd_functions} ]]; then
chpwd_functions=(${chpwd_functions[@]} "ezacd")
fi
# Go Lang stuff
export GOPATH=$HOME/go
if (( ${+commands[brew]} )); then
export PATH="$PATH:$HOMEBREW_PREFIX/go/bin:$HOMEBREW_PREFIX/opt/go/libexec/bin:$GOPATH/bin"
fi
# Add various GNU functions
# Prepend them to the PATH so they override any system installed versions
if (( ${+commands[brew]} )); then
export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/findutils/libexec/gnubin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="$HOMEBREW_PREFIX/opt/grep/libexec/gnubin:$PATH"
fi
# Add Obsidian CLI
export PATH="$PATH:/Applications/Obsidian.app/Contents/MacOS"
# Add Totara Docker helper functions
export PATH="$PATH:$HOME/git/totara-docker-dev/bin"
# Set the rip (Rm ImProved) graveyard
export GRAVEYARD="$HOME/.local/share/Trash"
# composer global
export PATH="$PATH:$HOME/.composer/vendor/bin"
# phpactor installed manually
export PATH="$PATH:$HOME/git/phpactor/bin"
# rust/cargo bin PATH
export PATH="$PATH:$HOME/.cargo/bin"
# Ruby PATH
if (( ${+commands[brew]} )); then
export PATH="$PATH:$HOMEBREW_PREFIX/opt/ruby/bin"
fi
# PostgreSQL binaries
if (( ${+commands[brew]} )); then
test -d $HOMEBREW_PREFIX/pgsql && export PATH="$PATH:$HOMEBREW_PREFIX/pgsql/bin"
fi
# PHP binaries
test -d $HOME/.php/bin && export PATH="$PATH:$HOME/.php/bin"
# JetBrains Toolbox scripts
test -d "$HOME/Library/Application Support/JetBrains/Toolbox/scripts" && export PATH="$PATH:$HOME/Library/Application Support/JetBrains/Toolbox/scripts"
# Homebrew cURL if we have it
if (( ${+commands[brew]} )); then
test -d $HOMEBREW_PREFIX/opt/curl && export PATH="$HOMEBREW_PREFIX/opt/curl/bin:$PATH"
fi
# Local Docker if set up that way
test -d $HOME/.docker/bin && export PATH="$HOME/.docker/bin:$PATH"
# Rainfrog config
export RAINFROG_CONFIG=~/.config/rainfrog
# Detect system appearance
function get-system-appearance() {
if ! type defaults &>/dev/null; then
echo ""
fi
local darkMode=true;
if [[ $(defaults read -g AppleInterfaceStyle 2> /dev/null) != 'Dark' ]]; then
darkMode=false
fi
if [[ $darkMode == true ]]; then
echo "dark"
else
echo "light"
fi
}
export MACOS_APPEARANCE=`get-system-appearance`
# Colourised output for `ls`
# vivid Dark mode ayu
# vivid Light mode catppuccin-latte
if type vivid &>/dev/null; then
local vividTheme="ayu"
if [[ $MACOS_APPEARANCE == "light" ]]; then
vividTheme="catppuccin-latte"
fi
export LS_COLORS="$(vivid generate $vividTheme)"
fi
## Set env vars for configuration purposes
# Set colour scheme for bat
export BAT_THEME_LIGHT="GitHub"
export BAT_THEME_DARK="Sublime Snazzy"
# Rainfrog config
export RAINFROG_CONFIG=~/.config/rainfrog
# Source the untracked `extra` file
test -e $HOME/.extra && source $HOME/.extra
@ -148,9 +97,19 @@ test -e $HOME/.extra && source $HOME/.extra
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
# Load plugins via Sheldon
# Load plugins via Sheldon, caching the generated source to avoid forking
# sheldon on every startup. Regenerate when the config (plugins.toml) or the
# lock file (touched by `sheldon update`/`--lock`) is newer than the cache.
if (( ${+commands[sheldon]} )); then
eval "$(sheldon source)"
sheldon_cache="$HOME/.cache/sheldon/source.zsh"
sheldon_toml="$HOME/.config/sheldon/plugins.toml"
sheldon_lock="$HOME/.local/share/sheldon/plugins.lock"
if [[ ! -r "$sheldon_cache" || "$sheldon_toml" -nt "$sheldon_cache" || "$sheldon_lock" -nt "$sheldon_cache" ]]; then
mkdir -p "${sheldon_cache:h}"
sheldon source > "$sheldon_cache"
fi
source "$sheldon_cache"
unset sheldon_cache sheldon_toml sheldon_lock
fi
# Set the prompt
@ -167,22 +126,18 @@ add-zsh-hook precmd vcs_info
# Style the vcs_info message
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git*' formats '⎇ %b%u%c'
zstyle ':vcs_info:git*' formats '⎇ %b'
# Format when the repo is in an action (merge, rebase, etc)
zstyle ':vcs_info:git*' actionformats '%F{14}⏱ %*%f'
zstyle ':vcs_info:git*' unstagedstr '*'
zstyle ':vcs_info:git*' stagedstr '+'
# This enables %u and %c (unstaged/staged changes) to work,
# but can be slow on large repos
zstyle ':vcs_info:*:*' check-for-changes true
# First show the Loading indicator in the right prompt if shell plugins are still loading
RPROMPT='%F{8}$(if [[ -n $SHELL_LOADING ]]; then echo "Loading... "; fi)'
# First show the Loading indicator in the right prompt if shell plugins are
# still loading. `${SHELL_LOADING:+...}` expands inline with no subshell fork.
RPROMPT='%F{8}${SHELL_LOADING:+Loading... }'
# Then we can also show the git branch
RPROMPT+='${vcs_info_msg_0_}'
# First set a dot that changes colour on success/fail or previous command
# First set a dot that changes colour on success/fail of the previous command
PROMPT='%(?.%F{blue}⏺.%F{red}⏺)%f '
# Show a symbol for the OS
# First we set the os_symbol variable we will use in the prompt
@ -203,3 +158,4 @@ PROMPT+='%(!.#.$) '
# Finally we can have zsh auto source this rc file on command
# attribution: https://www.reddit.com/r/commandline/comments/12g76v/
trap "source $HOME/.zshrc" USR1