Improve zsh startup
This commit is contained in:
@@ -4,7 +4,16 @@ autoload -Uz add-zsh-hook
|
|||||||
|
|
||||||
if ! whence -w compdef >/dev/null 2>&1; then
|
if ! whence -w compdef >/dev/null 2>&1; then
|
||||||
autoload -Uz compinit
|
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
|
fi
|
||||||
|
|
||||||
zmodload zsh/complist 2>/dev/null || true
|
zmodload zsh/complist 2>/dev/null || true
|
||||||
@@ -12,6 +21,7 @@ zmodload zsh/complist 2>/dev/null || true
|
|||||||
zstyle ':completion:*' menu select
|
zstyle ':completion:*' menu select
|
||||||
zstyle ':completion:*' verbose yes
|
zstyle ':completion:*' verbose yes
|
||||||
zstyle ':completion:*' list-grouped yes
|
zstyle ':completion:*' list-grouped yes
|
||||||
|
zstyle ':completion:*' use-cache yes
|
||||||
zstyle ':completion:*:descriptions' format '%F{240}%B%d%b%f'
|
zstyle ':completion:*:descriptions' format '%F{240}%B%d%b%f'
|
||||||
|
|
||||||
typeset -ga DOTZSH_USED_COMMANDS
|
typeset -ga DOTZSH_USED_COMMANDS
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ zstyle ':vcs_info:git:*' formats ' %b'
|
|||||||
typeset -g PROMPT_SHOW_SPACER=0
|
typeset -g PROMPT_SHOW_SPACER=0
|
||||||
typeset -gA PROMPT_PROJECT_MATCH_CACHE
|
typeset -gA PROMPT_PROJECT_MATCH_CACHE
|
||||||
typeset -gA PROMPT_VERSION_CACHE
|
typeset -gA PROMPT_VERSION_CACHE
|
||||||
|
typeset -gA PROMPT_SEPARATOR_CACHE
|
||||||
typeset -g PROMPT_FIRST_RENDER=1
|
typeset -g PROMPT_FIRST_RENDER=1
|
||||||
typeset -g PROMPT_PROJECT_ROOT_CACHE_PWD=''
|
typeset -g PROMPT_PROJECT_ROOT_CACHE_PWD=''
|
||||||
typeset -g PROMPT_PROJECT_ROOT_CACHE=''
|
typeset -g PROMPT_PROJECT_ROOT_CACHE=''
|
||||||
@@ -153,11 +154,17 @@ build_git_status_segment() {
|
|||||||
build_prompt_separator_line() {
|
build_prompt_separator_line() {
|
||||||
local last_status="$1"
|
local last_status="$1"
|
||||||
local line_width="${COLUMNS:-80}"
|
local line_width="${COLUMNS:-80}"
|
||||||
|
local cache_key="${line_width}:${last_status}"
|
||||||
local separator_line=""
|
local separator_line=""
|
||||||
local color_prefix=""
|
local color_prefix=""
|
||||||
local color_suffix=""
|
local color_suffix=""
|
||||||
local i=0
|
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
|
if [ "$line_width" -lt 1 ]; then
|
||||||
line_width=1
|
line_width=1
|
||||||
fi
|
fi
|
||||||
@@ -172,7 +179,8 @@ build_prompt_separator_line() {
|
|||||||
((i++))
|
((i++))
|
||||||
done
|
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() {
|
build_prompt() {
|
||||||
|
|||||||
37
Zsh/.zshrc
37
Zsh/.zshrc
@@ -2,15 +2,20 @@
|
|||||||
|
|
||||||
# Zsh Configuration
|
# Zsh Configuration
|
||||||
export ZSH="$HOME/.oh-my-zsh"
|
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
|
# Programming Languages Root
|
||||||
export PROG_DIR="$HOME/.programming"
|
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)
|
# Go and GVM (Black Box)
|
||||||
export GOPATH="$PROG_DIR/go"
|
export GOPATH="$PROG_DIR/go"
|
||||||
export GVM_ROOT="$GOPATH"
|
export GVM_ROOT="$GOPATH"
|
||||||
@@ -29,7 +34,6 @@ gofmt() { gvm_load gofmt "$@"; }
|
|||||||
export NVM_DIR="$PROG_DIR/node"
|
export NVM_DIR="$PROG_DIR/node"
|
||||||
|
|
||||||
nvm_load() {
|
nvm_load() {
|
||||||
echo "💤 Waking up NVM..."
|
|
||||||
unset -f nvm node npm npx
|
unset -f nvm node npm npx
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
[ -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"
|
export PATH="$RIG_HOME/bin:$PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_wsl() {
|
if [ -n "${WSL_DISTRO_NAME:-}" ] || [ -n "${WSL_INTEROP:-}" ]; then
|
||||||
[ -f /proc/version ] && grep -qEi "(Microsoft|WSL)" /proc/version
|
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
|
# Zoxide
|
||||||
if command -v zoxide >/dev/null 2>&1; then
|
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"
|
export PATH="$HOME/.local/bin:$CARGO_HOME/bin:$GOPATH/bin:$PATH"
|
||||||
|
|
||||||
# opencode
|
# 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 &!
|
openchamber --port 7891 >/dev/null 2>&1 &!
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -101,5 +109,14 @@ fi
|
|||||||
# Completion Styling
|
# Completion Styling
|
||||||
[ -f ~/.zsh_completion ] && source ~/.zsh_completion
|
[ -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
|
# Prompt Styling
|
||||||
[ -f ~/.zsh_prompt ] && source ~/.zsh_prompt
|
[ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user