Auto-sync from catchthesethighs
This commit is contained in:
124
bin/dotfiles-compile.sh
Normal file
124
bin/dotfiles-compile.sh
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# ============================================================================
|
||||||
|
# Dotfiles Compile - Pre-compile zsh files for faster loading
|
||||||
|
# ============================================================================
|
||||||
|
# Compiles .zsh and .zshrc files to .zwc bytecode format
|
||||||
|
# This can speed up shell startup by 20-50ms
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# dotfiles-compile.sh # Compile all
|
||||||
|
# dotfiles-compile.sh --clean # Remove compiled files
|
||||||
|
#
|
||||||
|
# Aliases: dfc-compile
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
compile_file() {
|
||||||
|
local file="$1"
|
||||||
|
if [[ -f "$file" ]]; then
|
||||||
|
if [[ ! -f "${file}.zwc" ]] || [[ "$file" -nt "${file}.zwc" ]]; then
|
||||||
|
zcompile "$file" 2>/dev/null && \
|
||||||
|
echo -e "${GREEN}✓${NC} Compiled: ${file##*/}" || \
|
||||||
|
echo -e "${YELLOW}⚠${NC} Skipped: ${file##*/}"
|
||||||
|
else
|
||||||
|
echo -e "${CYAN}○${NC} Current: ${file##*/}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_compiled() {
|
||||||
|
echo "Removing compiled files..."
|
||||||
|
|
||||||
|
local count=0
|
||||||
|
|
||||||
|
# Dotfiles
|
||||||
|
for zwc in "$DOTFILES_DIR"/**/*.zwc(N); do
|
||||||
|
rm -f "$zwc"
|
||||||
|
((count++))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Home zsh files
|
||||||
|
rm -f ~/.zshrc.zwc ~/.zshenv.zwc ~/.zprofile.zwc 2>/dev/null
|
||||||
|
|
||||||
|
# Oh-my-zsh (optional)
|
||||||
|
# rm -f ~/.oh-my-zsh/**/*.zwc(N) 2>/dev/null
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓${NC} Removed $count compiled files"
|
||||||
|
}
|
||||||
|
|
||||||
|
compile_all() {
|
||||||
|
echo -e "${CYAN}Compiling zsh files for faster startup...${NC}"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Core files
|
||||||
|
echo "Core files:"
|
||||||
|
compile_file ~/.zshrc
|
||||||
|
compile_file ~/.zshenv
|
||||||
|
compile_file ~/.zprofile
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Dotfiles zsh files
|
||||||
|
echo "Dotfiles:"
|
||||||
|
compile_file "$DOTFILES_DIR/zsh/.zshrc"
|
||||||
|
compile_file "$DOTFILES_DIR/zsh/aliases.zsh"
|
||||||
|
|
||||||
|
# Function files
|
||||||
|
for file in "$DOTFILES_DIR/zsh/functions"/*.zsh(N); do
|
||||||
|
compile_file "$file"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Theme
|
||||||
|
for file in "$DOTFILES_DIR/zsh/themes"/*.zsh-theme(N); do
|
||||||
|
compile_file "$file"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Oh-my-zsh core (optional, can save ~10ms)
|
||||||
|
if [[ -d ~/.oh-my-zsh ]]; then
|
||||||
|
echo "Oh-My-Zsh (optional):"
|
||||||
|
compile_file ~/.oh-my-zsh/oh-my-zsh.sh
|
||||||
|
# compile_file ~/.oh-my-zsh/lib/*.zsh # Uncomment for more speed
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓${NC} Compilation complete"
|
||||||
|
echo
|
||||||
|
echo "To measure startup time:"
|
||||||
|
echo " time zsh -i -c exit"
|
||||||
|
echo " hyperfine 'zsh -i -c exit' # More accurate"
|
||||||
|
}
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
echo "Usage: dotfiles-compile.sh [OPTIONS]"
|
||||||
|
echo
|
||||||
|
echo "Compile zsh files to bytecode for faster shell startup."
|
||||||
|
echo
|
||||||
|
echo "Options:"
|
||||||
|
echo " (none) Compile all zsh files"
|
||||||
|
echo " --clean Remove all compiled (.zwc) files"
|
||||||
|
echo " --help Show this help"
|
||||||
|
echo
|
||||||
|
echo "The compiled files (.zwc) are automatically used by zsh"
|
||||||
|
echo "and can speed up shell startup by 20-50ms."
|
||||||
|
}
|
||||||
|
|
||||||
|
case "${1:-}" in
|
||||||
|
--clean|-c)
|
||||||
|
clean_compiled
|
||||||
|
;;
|
||||||
|
--help|-h)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
compile_all
|
||||||
|
;;
|
||||||
|
esac
|
||||||
505
zsh/.zshrc
505
zsh/.zshrc
@@ -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 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
|
# Theme Configuration
|
||||||
@@ -12,37 +49,32 @@ export ZSH="$HOME/.oh-my-zsh"
|
|||||||
ZSH_THEME="adlee"
|
ZSH_THEME="adlee"
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Oh-My-Zsh Settings
|
# Oh-My-Zsh Settings (before sourcing)
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
# Update behavior
|
|
||||||
zstyle ':omz:update' mode reminder
|
zstyle ':omz:update' mode reminder
|
||||||
zstyle ':omz:update' frequency 13
|
zstyle ':omz:update' frequency 13
|
||||||
|
|
||||||
# Display red dots whilst waiting for completion
|
|
||||||
COMPLETION_WAITING_DOTS="true"
|
COMPLETION_WAITING_DOTS="true"
|
||||||
|
|
||||||
# History timestamp format
|
|
||||||
HIST_STAMPS="yyyy-mm-dd"
|
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=(
|
plugins=(
|
||||||
git
|
git
|
||||||
docker
|
|
||||||
docker-compose
|
|
||||||
kubectl
|
|
||||||
sudo
|
sudo
|
||||||
fzf
|
|
||||||
zsh-autosuggestions
|
zsh-autosuggestions
|
||||||
zsh-syntax-highlighting
|
zsh-syntax-highlighting
|
||||||
)
|
)
|
||||||
|
|
||||||
# Note: Install additional plugins with:
|
# Conditionally add plugins only if tools exist
|
||||||
# git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
|
[[ -d "$HOME/.fzf" || -f "/usr/share/fzf/key-bindings.zsh" ]] && plugins+=(fzf)
|
||||||
# git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Load Oh-My-Zsh
|
# Load Oh-My-Zsh
|
||||||
@@ -51,44 +83,15 @@ plugins=(
|
|||||||
source $ZSH/oh-my-zsh.sh
|
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
|
# Navigation
|
||||||
alias ..='cd ..'
|
alias ..='cd ..'
|
||||||
alias ...='cd ../..'
|
alias ...='cd ../..'
|
||||||
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
|
# Git shortcuts
|
||||||
alias g='git'
|
alias g='git'
|
||||||
alias gs='git status'
|
alias gs='git status'
|
||||||
@@ -109,252 +112,238 @@ alias dpa='docker ps -a'
|
|||||||
alias di='docker images'
|
alias di='docker images'
|
||||||
alias dex='docker exec -it'
|
alias dex='docker exec -it'
|
||||||
|
|
||||||
# System shortcuts
|
# System
|
||||||
alias h='history'
|
alias h='history'
|
||||||
alias c='clear'
|
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 rm='rm -i'
|
||||||
alias cp='cp -i'
|
alias cp='cp -i'
|
||||||
alias mv='mv -i'
|
alias mv='mv -i'
|
||||||
|
alias myip='curl -s ifconfig.me'
|
||||||
# Network
|
|
||||||
alias myip='curl ifconfig.me'
|
|
||||||
alias ports='netstat -tulanp'
|
alias ports='netstat -tulanp'
|
||||||
|
|
||||||
# --- Functions ---
|
# ============================================================================
|
||||||
|
# Deferred Alias Setup (runs after prompt displays)
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
# Juuuust puuush it.
|
_setup_tool_aliases() {
|
||||||
push-it() {
|
# eza/ls aliases
|
||||||
git add .
|
if _has_cmd eza; then
|
||||||
git commit -m "$1"
|
alias ls='eza --icons'
|
||||||
git push origin
|
alias ll='eza -lah --icons'
|
||||||
}
|
alias la='eza -a --icons'
|
||||||
|
alias lt='eza --tree --level=2 --icons'
|
||||||
# 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
|
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Quick find file
|
# ============================================================================
|
||||||
ff() {
|
# Functions
|
||||||
find . -type f -iname "*$1*"
|
# ============================================================================
|
||||||
|
|
||||||
|
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() {
|
# Key Bindings
|
||||||
find . -type d -iname "*$1*"
|
# ============================================================================
|
||||||
}
|
|
||||||
|
|
||||||
# Quick backup
|
bindkey "^[[1;5C" forward-word
|
||||||
backup() {
|
bindkey "^[[1;5D" backward-word
|
||||||
cp "$1" "$1.backup-$(date +%Y%m%d-%H%M%S)"
|
bindkey "^[[H" beginning-of-line
|
||||||
}
|
bindkey "^[[F" end-of-line
|
||||||
|
bindkey "^[[3~" delete-char
|
||||||
|
|
||||||
# --- FZF Configuration ---
|
# Alt+R to reload
|
||||||
|
reload-zsh() { source ~/.zshrc; echo "✓ Reloaded"; zle reset-prompt; }
|
||||||
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
|
|
||||||
}
|
|
||||||
zle -N reload-zsh
|
zle -N reload-zsh
|
||||||
bindkey "^[r" reload-zsh
|
bindkey "^[r" reload-zsh
|
||||||
|
|
||||||
# Alt+G to show git status
|
# ============================================================================
|
||||||
git-status-widget() {
|
# FZF Configuration (deferred)
|
||||||
echo
|
# ============================================================================
|
||||||
git status
|
|
||||||
zle reset-prompt
|
_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) ---
|
# NVM
|
||||||
# Only loads when you first use node, npm, nvm, or npx
|
|
||||||
export NVM_DIR="$HOME/.nvm"
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
|
||||||
_load_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() {
|
|
||||||
unfunction nvm node npm npx 2>/dev/null
|
unfunction nvm node npm npx 2>/dev/null
|
||||||
_load_nvm
|
\. "$NVM_DIR/nvm.sh"
|
||||||
nvm "$@"
|
[[ -s "$NVM_DIR/bash_completion" ]] && \. "$NVM_DIR/bash_completion"
|
||||||
}
|
|
||||||
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() { _load_nvm; nvm "$@"; }
|
||||||
|
node() { _load_nvm; node "$@"; }
|
||||||
|
npm() { _load_nvm; npm "$@"; }
|
||||||
|
npx() { _load_nvm; npx "$@"; }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Python virtualenvwrapper (lazy load) ---
|
# Python virtualenvwrapper
|
||||||
export WORKON_HOME=$HOME/.virtualenvs
|
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() {
|
# Rust cargo
|
||||||
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
|
[[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env"
|
||||||
[ -f /usr/local/bin/virtualenvwrapper.sh ] && source /usr/local/bin/virtualenvwrapper.sh
|
|
||||||
|
# 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() {
|
# Background Tasks (truly async, won't block)
|
||||||
unfunction workon mkvirtualenv rmvirtualenv 2>/dev/null
|
# ============================================================================
|
||||||
_load_virtualenvwrapper
|
|
||||||
workon "$@"
|
|
||||||
}
|
|
||||||
mkvirtualenv() {
|
|
||||||
unfunction workon mkvirtualenv rmvirtualenv 2>/dev/null
|
|
||||||
_load_virtualenvwrapper
|
|
||||||
mkvirtualenv "$@"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- Rust cargo (only if exists) ---
|
_background_tasks() {
|
||||||
[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
|
# Check for dotfiles updates
|
||||||
|
if [[ "${DOTFILES_AUTO_SYNC_CHECK:-true}" == "true" ]]; then
|
||||||
# --- OS-Specific Configuration ---
|
dotfiles-sync.sh --auto 2>/dev/null &!
|
||||||
|
fi
|
||||||
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"
|
|
||||||
|
|
||||||
# Show MOTD based on style setting
|
|
||||||
case "${MOTD_STYLE:-compact}" in
|
|
||||||
compact) show_motd ;;
|
|
||||||
mini) show_motd_mini ;;
|
|
||||||
off|false|no) ;;
|
|
||||||
*) show_motd ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- Local Configuration ---
|
|
||||||
|
|
||||||
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# End of Configuration
|
# Initialization Strategy
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
_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
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# OS-Specific
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
[[ "$(uname -s)" == "Darwin"* ]] && export HOMEBREW_NO_ANALYTICS=1
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Local Configuration (always load - user overrides)
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# End - Profiling output (uncomment zprof at top to use)
|
||||||
|
# ============================================================================
|
||||||
|
# zprof
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ alias vls='dotfiles-vault.sh list'
|
|||||||
alias vget='dotfiles-vault.sh get'
|
alias vget='dotfiles-vault.sh get'
|
||||||
alias vset='dotfiles-vault.sh set'
|
alias vset='dotfiles-vault.sh set'
|
||||||
|
|
||||||
|
# Compile - compile zsh files for speed
|
||||||
|
alias dfcompile='dotfiles-compile.sh'
|
||||||
|
|
||||||
# --- Quick Edit Aliases ---
|
# --- Quick Edit Aliases ---
|
||||||
alias zshrc='${EDITOR:-vim} ~/.zshrc'
|
alias zshrc='${EDITOR:-vim} ~/.zshrc'
|
||||||
alias dfconf='${EDITOR:-vim} ~/.dotfiles/dotfiles.conf'
|
alias dfconf='${EDITOR:-vim} ~/.dotfiles/dotfiles.conf'
|
||||||
|
|||||||
Reference in New Issue
Block a user