Auto-sync from catchthesethighs

This commit is contained in:
Aaron D. Lee
2025-12-15 21:52:25 -05:00
parent 3560a94418
commit 67ada0d0c9
3 changed files with 368 additions and 252 deletions

View File

@@ -1,9 +1,46 @@
# ============================================================================
# ADLee's ZSH Configuration
# ADLee's ZSH Configuration (Optimized)
# ============================================================================
# Optimizations:
# - Deferred/lazy loading for heavy plugins
# - Parallel background loading where possible
# - Compiled zsh files (.zwc) for faster parsing
# - Minimal command -v checks (cached)
# ============================================================================
# --- Profiling (uncomment to debug slow startup) ---
# zmodload zsh/zprof
# ============================================================================
# Instant Prompt (show prompt immediately while loading continues)
# ============================================================================
# Cache command existence checks
typeset -gA _cmd_cache
_has_cmd() {
if [[ -z "${_cmd_cache[$1]+x}" ]]; then
_cmd_cache[$1]=$(command -v "$1" &>/dev/null && echo 1 || echo 0)
fi
[[ "${_cmd_cache[$1]}" == "1" ]]
}
# ============================================================================
# Core Settings (fast, no external calls)
# ============================================================================
# Path to oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh"
export EDITOR='vim'
export VISUAL='vim'
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export PATH="$HOME/.local/bin:$PATH"
# History (set early)
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
setopt SHARE_HISTORY APPEND_HISTORY EXTENDED_HISTORY
setopt HIST_IGNORE_ALL_DUPS HIST_FIND_NO_DUPS HIST_IGNORE_SPACE
# ============================================================================
# Theme Configuration
@@ -12,37 +49,32 @@ export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="adlee"
# ============================================================================
# Oh-My-Zsh Settings
# Oh-My-Zsh Settings (before sourcing)
# ============================================================================
# Update behavior
zstyle ':omz:update' mode reminder
zstyle ':omz:update' frequency 13
# Display red dots whilst waiting for completion
COMPLETION_WAITING_DOTS="true"
# History timestamp format
HIST_STAMPS="yyyy-mm-dd"
# Disable oh-my-zsh auto-update check on every load (slow)
DISABLE_AUTO_UPDATE="true"
# ============================================================================
# Plugins
# Plugins - Optimized Selection
# ============================================================================
# Removed heavy plugins that aren't always needed
# kubectl, docker-compose loaded on-demand
plugins=(
git
docker
docker-compose
kubectl
sudo
fzf
zsh-autosuggestions
zsh-syntax-highlighting
)
# Note: Install additional plugins with:
# git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# Conditionally add plugins only if tools exist
[[ -d "$HOME/.fzf" || -f "/usr/share/fzf/key-bindings.zsh" ]] && plugins+=(fzf)
# ============================================================================
# Load Oh-My-Zsh
@@ -51,44 +83,15 @@ plugins=(
source $ZSH/oh-my-zsh.sh
# ============================================================================
# User Configuration
# Aliases (inline - no external checks during definition)
# ============================================================================
# --- Environment Variables ---
export EDITOR='vim'
export VISUAL='vim'
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export PATH="$HOME/.local/bin:$PATH"
# --- Aliases ---
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias ~='cd ~'
# List files
if command -v eza &> /dev/null; then
alias ls='eza --icons'
alias ll='eza -lah --icons'
alias la='eza -a --icons'
alias lt='eza --tree --level=2 --icons'
else
alias ll='ls -lah'
alias la='ls -A'
fi
# Cat with syntax highlighting
if command -v batcat &> /dev/null; then
alias cat='batcat --paging=never'
alias bat='batcat'
elif command -v bat &> /dev/null; then
alias cat='bat --paging=never'
fi
# Git shortcuts
alias g='git'
alias gs='git status'
@@ -109,252 +112,238 @@ alias dpa='docker ps -a'
alias di='docker images'
alias dex='docker exec -it'
# System shortcuts
# System
alias h='history'
alias c='clear'
# --- Source Dotfiles Aliases ---
if [[ -f "$HOME/.dotfiles/zsh/aliases.zsh" ]]; then
source "$HOME/.dotfiles/zsh/aliases.zsh"
fi
# Safe operations
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Network
alias myip='curl ifconfig.me'
alias myip='curl -s ifconfig.me'
alias ports='netstat -tulanp'
# --- Functions ---
# ============================================================================
# Deferred Alias Setup (runs after prompt displays)
# ============================================================================
# Juuuust puuush it.
push-it() {
git add .
git commit -m "$1"
git push origin
}
# Create directory and cd into it
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Extract various archive formats
extract() {
if [[ -f "$1" ]]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
_setup_tool_aliases() {
# eza/ls aliases
if _has_cmd eza; then
alias ls='eza --icons'
alias ll='eza -lah --icons'
alias la='eza -a --icons'
alias lt='eza --tree --level=2 --icons'
else
echo "'$1' is not a valid file"
alias ll='ls -lah'
alias la='ls -A'
fi
# bat/cat aliases
if _has_cmd batcat; then
alias cat='batcat --paging=never'
alias bat='batcat'
elif _has_cmd bat; then
alias cat='bat --paging=never'
fi
}
# Quick find file
ff() {
find . -type f -iname "*$1*"
# ============================================================================
# Functions
# ============================================================================
push-it() { git add . && git commit -m "$1" && git push origin; }
mkcd() { mkdir -p "$1" && cd "$1"; }
ff() { find . -type f -iname "*$1*"; }
fdir() { find . -type d -iname "*$1*"; }
backup() { cp "$1" "$1.backup-$(date +%Y%m%d-%H%M%S)"; }
extract() {
[[ ! -f "$1" ]] && { echo "'$1' is not a valid file"; return 1; }
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
}
# Quick find directory (renamed to avoid conflict with fd tool)
fdir() {
find . -type d -iname "*$1*"
}
# ============================================================================
# Key Bindings
# ============================================================================
# Quick backup
backup() {
cp "$1" "$1.backup-$(date +%Y%m%d-%H%M%S)"
}
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[[3~" delete-char
# --- FZF Configuration ---
if command -v fzf &> /dev/null; then
if command -v fd &> /dev/null; then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fi
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
bindkey '^R' fzf-history-widget
fi
# --- History Configuration ---
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
setopt SHARE_HISTORY
setopt APPEND_HISTORY
setopt EXTENDED_HISTORY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_SPACE
# --- Key Bindings ---
bindkey "^[[1;5C" forward-word # Ctrl+Right
bindkey "^[[1;5D" backward-word # Ctrl+Left
bindkey "^[[H" beginning-of-line # Home
bindkey "^[[F" end-of-line # End
bindkey "^[[3~" delete-char # Delete
# --- Custom Widgets ---
# Alt+R to reload zsh config
reload-zsh() {
source ~/.zshrc
echo "✓ zsh configuration reloaded"
zle reset-prompt
}
# Alt+R to reload
reload-zsh() { source ~/.zshrc; echo "✓ Reloaded"; zle reset-prompt; }
zle -N reload-zsh
bindkey "^[r" reload-zsh
# Alt+G to show git status
git-status-widget() {
echo
git status
zle reset-prompt
# ============================================================================
# FZF Configuration (deferred)
# ============================================================================
_setup_fzf() {
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
if _has_cmd fd; then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fi
}
zle -N git-status-widget
bindkey "^[g" git-status-widget
# ============================================================================
# Lazy-loaded Tools (for faster shell startup)
# Lazy-loaded Tools
# ============================================================================
# --- NVM (lazy load) ---
# Only loads when you first use node, npm, nvm, or npx
# NVM
export NVM_DIR="$HOME/.nvm"
_load_nvm() {
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
}
# Create lazy-load wrappers
if [ -s "$NVM_DIR/nvm.sh" ]; then
nvm() {
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
_load_nvm() {
unfunction nvm node npm npx 2>/dev/null
_load_nvm
nvm "$@"
}
node() {
unfunction nvm node npm npx 2>/dev/null
_load_nvm
node "$@"
}
npm() {
unfunction nvm node npm npx 2>/dev/null
_load_nvm
npm "$@"
}
npx() {
unfunction nvm node npm npx 2>/dev/null
_load_nvm
npx "$@"
\. "$NVM_DIR/nvm.sh"
[[ -s "$NVM_DIR/bash_completion" ]] && \. "$NVM_DIR/bash_completion"
}
nvm() { _load_nvm; nvm "$@"; }
node() { _load_nvm; node "$@"; }
npm() { _load_nvm; npm "$@"; }
npx() { _load_nvm; npx "$@"; }
fi
# --- Python virtualenvwrapper (lazy load) ---
# Python virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
if [[ -f /usr/local/bin/virtualenvwrapper.sh ]]; then
_load_venv() {
unfunction workon mkvirtualenv rmvirtualenv 2>/dev/null
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
}
workon() { _load_venv; workon "$@"; }
mkvirtualenv() { _load_venv; mkvirtualenv "$@"; }
fi
_load_virtualenvwrapper() {
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
[ -f /usr/local/bin/virtualenvwrapper.sh ] && source /usr/local/bin/virtualenvwrapper.sh
# Rust cargo
[[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env"
# kubectl (lazy load - it's VERY slow to initialize)
if _has_cmd kubectl; then
kubectl() {
unfunction kubectl 2>/dev/null
source <(command kubectl completion zsh)
command kubectl "$@"
}
fi
# ============================================================================
# Dotfiles Functions (deferred loading)
# ============================================================================
_dotfiles_dir="$HOME/.dotfiles"
# Source dotfiles aliases
[[ -f "$_dotfiles_dir/zsh/aliases.zsh" ]] && source "$_dotfiles_dir/zsh/aliases.zsh"
# These are loaded immediately (small files, needed for keybindings)
[[ -f "$_dotfiles_dir/zsh/functions/command-palette.zsh" ]] && \
source "$_dotfiles_dir/zsh/functions/command-palette.zsh"
# ============================================================================
# Deferred Loading (runs in background after prompt)
# ============================================================================
_deferred_load() {
# Setup tool aliases
_setup_tool_aliases
# Setup FZF
_has_cmd fzf && _setup_fzf
# Source optional function files
[[ -f "$_dotfiles_dir/zsh/functions/snapper.zsh" ]] && \
source "$_dotfiles_dir/zsh/functions/snapper.zsh"
[[ -f "$_dotfiles_dir/zsh/functions/smart-suggest.zsh" ]] && \
source "$_dotfiles_dir/zsh/functions/smart-suggest.zsh"
[[ -f "$_dotfiles_dir/zsh/functions/password-manager.zsh" ]] && \
source "$_dotfiles_dir/zsh/functions/password-manager.zsh"
# Load vault secrets (in background)
if [[ -f "$_dotfiles_dir/vault/secrets.enc" ]] && _has_cmd dotfiles-vault.sh; then
eval "$(dotfiles-vault.sh shell 2>/dev/null)" || true
fi
}
if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
workon() {
unfunction workon mkvirtualenv rmvirtualenv 2>/dev/null
_load_virtualenvwrapper
workon "$@"
}
mkvirtualenv() {
unfunction workon mkvirtualenv rmvirtualenv 2>/dev/null
_load_virtualenvwrapper
mkvirtualenv "$@"
}
fi
# ============================================================================
# Background Tasks (truly async, won't block)
# ============================================================================
# --- Rust cargo (only if exists) ---
[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
_background_tasks() {
# Check for dotfiles updates
if [[ "${DOTFILES_AUTO_SYNC_CHECK:-true}" == "true" ]]; then
dotfiles-sync.sh --auto 2>/dev/null &!
fi
}
# --- OS-Specific Configuration ---
# ============================================================================
# Initialization Strategy
# ============================================================================
case "$(uname -s)" in
Darwin*)
export HOMEBREW_NO_ANALYTICS=1
;;
esac
# --- Snapper Functions ---
if [[ -f "$HOME/.dotfiles/zsh/functions/snapper.zsh" ]]; then
source "$HOME/.dotfiles/zsh/functions/snapper.zsh"
fi
# --- Smart Command Suggestions ---
if [[ -f "$HOME/.dotfiles/zsh/functions/smart-suggest.zsh" ]]; then
source "$HOME/.dotfiles/zsh/functions/smart-suggest.zsh"
fi
# --- Command Palette (Ctrl+Space or Ctrl+P) ---
if [[ -f "$HOME/.dotfiles/zsh/functions/command-palette.zsh" ]]; then
source "$HOME/.dotfiles/zsh/functions/command-palette.zsh"
fi
# --- Dotfiles Sync Check (on shell start) ---
if [[ "${DOTFILES_AUTO_SYNC_CHECK:-true}" == "true" ]]; then
# Quick async check for dotfiles updates
(dotfiles-sync.sh --auto 2>/dev/null &)
fi
# --- Vault Integration ---
# Source vault secrets into environment (if vault exists and has secrets)
if command -v dotfiles-vault.sh &>/dev/null && [[ -f "$HOME/.dotfiles/vault/secrets.enc" ]]; then
eval "$(dotfiles-vault.sh shell 2>/dev/null)" || true
fi
# --- Password Manager Integration ---
if [[ -f "$HOME/.dotfiles/zsh/functions/password-manager.zsh" ]]; then
source "$HOME/.dotfiles/zsh/functions/password-manager.zsh"
fi
# --- MOTD (Message of the Day) ---
if [[ -f "$HOME/.dotfiles/zsh/functions/motd.zsh" ]]; then
source "$HOME/.dotfiles/zsh/functions/motd.zsh"
# Method 1: Use zsh-defer if available (best option)
if [[ -f "$_dotfiles_dir/zsh/plugins/zsh-defer/zsh-defer.plugin.zsh" ]]; then
source "$_dotfiles_dir/zsh/plugins/zsh-defer/zsh-defer.plugin.zsh"
zsh-defer _deferred_load
zsh-defer _background_tasks
zsh-defer -c '[[ -f "$_dotfiles_dir/zsh/functions/motd.zsh" ]] && source "$_dotfiles_dir/zsh/functions/motd.zsh" && show_motd'
else
# Method 2: Use sched for deferred loading (built-in)
# Runs after first prompt is displayed
zmodload zsh/sched 2>/dev/null
# Show MOTD based on style setting
case "${MOTD_STYLE:-compact}" in
compact) show_motd ;;
mini) show_motd_mini ;;
off|false|no) ;;
*) show_motd ;;
esac
_first_prompt_hook() {
# Remove this hook after first run
add-zsh-hook -d precmd _first_prompt_hook
# Run deferred loading
_deferred_load
# Show MOTD after prompt
if [[ -f "$_dotfiles_dir/zsh/functions/motd.zsh" ]]; then
source "$_dotfiles_dir/zsh/functions/motd.zsh"
case "${MOTD_STYLE:-compact}" in
compact) show_motd ;;
mini) show_motd_mini ;;
esac
fi
# Background tasks
_background_tasks
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd _first_prompt_hook
fi
# --- Local Configuration ---
# ============================================================================
# OS-Specific
# ============================================================================
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
[[ "$(uname -s)" == "Darwin"* ]] && export HOMEBREW_NO_ANALYTICS=1
# ============================================================================
# End of Configuration
# Local Configuration (always load - user overrides)
# ============================================================================
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
# ============================================================================
# End - Profiling output (uncomment zprof at top to use)
# ============================================================================
# zprof