diff --git a/Zsh/.zsh_completion b/Zsh/.zsh_completion index 6b714f0..74eeabd 100644 --- a/Zsh/.zsh_completion +++ b/Zsh/.zsh_completion @@ -4,7 +4,16 @@ autoload -Uz add-zsh-hook if ! whence -w compdef >/dev/null 2>&1; then autoload -Uz compinit - compinit -i >/dev/null 2>&1 + if [ -n "${ZSH_COMPDUMP:-}" ]; then + mkdir -p "${ZSH_COMPDUMP:h}" + if [ -f "$ZSH_COMPDUMP" ]; then + compinit -C -d "$ZSH_COMPDUMP" >/dev/null 2>&1 + else + compinit -i -d "$ZSH_COMPDUMP" >/dev/null 2>&1 + fi + else + compinit -i >/dev/null 2>&1 + fi fi zmodload zsh/complist 2>/dev/null || true @@ -12,6 +21,7 @@ zmodload zsh/complist 2>/dev/null || true zstyle ':completion:*' menu select zstyle ':completion:*' verbose yes zstyle ':completion:*' list-grouped yes +zstyle ':completion:*' use-cache yes zstyle ':completion:*:descriptions' format '%F{240}%B%d%b%f' typeset -ga DOTZSH_USED_COMMANDS diff --git a/Zsh/.zsh_prompt b/Zsh/.zsh_prompt index fbd6728..b4b9a64 100644 --- a/Zsh/.zsh_prompt +++ b/Zsh/.zsh_prompt @@ -8,6 +8,7 @@ zstyle ':vcs_info:git:*' formats ' %b' typeset -g PROMPT_SHOW_SPACER=0 typeset -gA PROMPT_PROJECT_MATCH_CACHE typeset -gA PROMPT_VERSION_CACHE +typeset -gA PROMPT_SEPARATOR_CACHE typeset -g PROMPT_FIRST_RENDER=1 typeset -g PROMPT_PROJECT_ROOT_CACHE_PWD='' typeset -g PROMPT_PROJECT_ROOT_CACHE='' @@ -153,11 +154,17 @@ build_git_status_segment() { build_prompt_separator_line() { local last_status="$1" local line_width="${COLUMNS:-80}" + local cache_key="${line_width}:${last_status}" local separator_line="" local color_prefix="" local color_suffix="" local i=0 + if [[ -n ${PROMPT_SEPARATOR_CACHE[$cache_key]+x} ]]; then + print -r -- "${PROMPT_SEPARATOR_CACHE[$cache_key]}" + return 0 + fi + if [ "$line_width" -lt 1 ]; then line_width=1 fi @@ -172,7 +179,8 @@ build_prompt_separator_line() { ((i++)) done - print -r -- "${color_prefix}${separator_line}${color_suffix}" + PROMPT_SEPARATOR_CACHE[$cache_key]="${color_prefix}${separator_line}${color_suffix}" + print -r -- "${PROMPT_SEPARATOR_CACHE[$cache_key]}" } build_prompt() { diff --git a/Zsh/.zshrc b/Zsh/.zshrc index 97c0f06..8c65b03 100644 --- a/Zsh/.zshrc +++ b/Zsh/.zshrc @@ -2,15 +2,20 @@ # Zsh Configuration export ZSH="$HOME/.oh-my-zsh" +export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh" +export ZSH_COMPDUMP="${ZSH_CACHE_DIR}/.zcompdump-${HOST}-${ZSH_VERSION}" + +mkdir -p "$ZSH_CACHE_DIR" + +export DOTZSH_GIT_PLUGIN="$ZSH/plugins/git/git.plugin.zsh" +export DOTZSH_SUDO_PLUGIN="$ZSH/plugins/sudo/sudo.plugin.zsh" +export DOTZSH_RCLONE_PLUGIN="$ZSH/plugins/rclone/rclone.plugin.zsh" +export DOTZSH_AUTOSUGGESTIONS_PLUGIN="$ZSH/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" +export DOTZSH_SYNTAX_HIGHLIGHTING_PLUGIN="$ZSH/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh" # Programming Languages Root export PROG_DIR="$HOME/.programming" -# Plugins -plugins=(git zsh-syntax-highlighting zsh-autosuggestions sudo rclone) - -source $ZSH/oh-my-zsh.sh - # Go and GVM (Black Box) export GOPATH="$PROG_DIR/go" export GVM_ROOT="$GOPATH" @@ -29,7 +34,6 @@ gofmt() { gvm_load gofmt "$@"; } export NVM_DIR="$PROG_DIR/node" nvm_load() { - echo "💤 Waking up NVM..." unset -f nvm node npm npx [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" "$@" @@ -72,9 +76,13 @@ if [ -d "$RIG_HOME/bin" ]; then export PATH="$RIG_HOME/bin:$PATH" fi -is_wsl() { - [ -f /proc/version ] && grep -qEi "(Microsoft|WSL)" /proc/version -} +if [ -n "${WSL_DISTRO_NAME:-}" ] || [ -n "${WSL_INTEROP:-}" ]; then + typeset -gr DOTZSH_IS_WSL=1 +elif [ -r /proc/sys/kernel/osrelease ] && grep -qiE '(microsoft|wsl)' /proc/sys/kernel/osrelease 2>/dev/null; then + typeset -gr DOTZSH_IS_WSL=1 +else + typeset -gr DOTZSH_IS_WSL=0 +fi # Zoxide if command -v zoxide >/dev/null 2>&1; then @@ -89,7 +97,7 @@ fi export PATH="$HOME/.local/bin:$CARGO_HOME/bin:$GOPATH/bin:$PATH" # opencode -if is_wsl && command -v openchamber >/dev/null 2>&1 && ! pgrep -f "openchamber.*7891" > /dev/null; then +if [ "$DOTZSH_IS_WSL" -eq 1 ] && command -v openchamber >/dev/null 2>&1 && ! pgrep -f "openchamber.*7891" >/dev/null 2>&1; then openchamber --port 7891 >/dev/null 2>&1 &! fi @@ -101,5 +109,14 @@ fi # Completion Styling [ -f ~/.zsh_completion ] && source ~/.zsh_completion +# Plugin Scripts (lighter than loading full Oh My Zsh) +[ -f "$DOTZSH_GIT_PLUGIN" ] && source "$DOTZSH_GIT_PLUGIN" +[ -f "$DOTZSH_SUDO_PLUGIN" ] && source "$DOTZSH_SUDO_PLUGIN" +[ -f "$DOTZSH_RCLONE_PLUGIN" ] && source "$DOTZSH_RCLONE_PLUGIN" + # Prompt Styling [ -f ~/.zsh_prompt ] && source ~/.zsh_prompt + +# Interactive Enhancements +[ -f "$DOTZSH_AUTOSUGGESTIONS_PLUGIN" ] && source "$DOTZSH_AUTOSUGGESTIONS_PLUGIN" +[ -f "$DOTZSH_SYNTAX_HIGHLIGHTING_PLUGIN" ] && source "$DOTZSH_SYNTAX_HIGHLIGHTING_PLUGIN"