Cleaned up some duplicate logic, shaved some timee of loading prompt.
This commit is contained in:
117
zsh/.zshrc
117
zsh/.zshrc
@@ -2,16 +2,6 @@
|
||||
# ADLee's ZSH Configuration
|
||||
# ============================================================================
|
||||
|
||||
# Force proper initialization in tmux
|
||||
if [[ -n "$TMUX" ]]; then
|
||||
# Ensure oh-my-zsh paths are set
|
||||
export ZSH="$HOME/.oh-my-zsh"
|
||||
fi
|
||||
|
||||
# Path to oh-my-zsh installation
|
||||
export ZSH="$HOME/.oh-my-zsh"
|
||||
|
||||
|
||||
# Path to oh-my-zsh installation
|
||||
export ZSH="$HOME/.oh-my-zsh"
|
||||
|
||||
@@ -68,12 +58,8 @@ source $ZSH/oh-my-zsh.sh
|
||||
|
||||
export EDITOR='vim'
|
||||
export VISUAL='vim'
|
||||
|
||||
# Language environment
|
||||
export LANG=en_US.UTF-8
|
||||
export LC_ALL=en_US.UTF-8
|
||||
|
||||
# Add local bin to PATH
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
|
||||
# --- Aliases ---
|
||||
@@ -140,7 +126,7 @@ alias myip='curl ifconfig.me'
|
||||
alias ports='netstat -tulanp'
|
||||
|
||||
# --- Functions ---
|
||||
#
|
||||
|
||||
# Juuuust puuush it.
|
||||
push-it() {
|
||||
git add .
|
||||
@@ -155,7 +141,7 @@ mkcd() {
|
||||
|
||||
# Extract various archive formats
|
||||
extract() {
|
||||
if [ -f "$1" ]; then
|
||||
if [[ -f "$1" ]]; then
|
||||
case "$1" in
|
||||
*.tar.bz2) tar xjf "$1" ;;
|
||||
*.tar.gz) tar xzf "$1" ;;
|
||||
@@ -180,8 +166,8 @@ ff() {
|
||||
find . -type f -iname "*$1*"
|
||||
}
|
||||
|
||||
# Quick find directory
|
||||
fd() {
|
||||
# Quick find directory (renamed to avoid conflict with fd tool)
|
||||
fdir() {
|
||||
find . -type d -iname "*$1*"
|
||||
}
|
||||
|
||||
@@ -193,16 +179,11 @@ backup() {
|
||||
# --- FZF Configuration ---
|
||||
|
||||
if command -v fzf &> /dev/null; then
|
||||
# Use fd if available for better performance
|
||||
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
|
||||
|
||||
# FZF color scheme
|
||||
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
|
||||
|
||||
# CTRL-R for history search
|
||||
bindkey '^R' fzf-history-widget
|
||||
fi
|
||||
|
||||
@@ -212,7 +193,6 @@ HISTSIZE=10000
|
||||
SAVEHIST=10000
|
||||
HISTFILE=~/.zsh_history
|
||||
|
||||
# Share history between sessions
|
||||
setopt SHARE_HISTORY
|
||||
setopt APPEND_HISTORY
|
||||
setopt EXTENDED_HISTORY
|
||||
@@ -222,18 +202,13 @@ setopt HIST_IGNORE_SPACE
|
||||
|
||||
# --- Key Bindings ---
|
||||
|
||||
# Bind Ctrl+Left/Right to move by word
|
||||
bindkey "^[[1;5C" forward-word
|
||||
bindkey "^[[1;5D" backward-word
|
||||
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
|
||||
|
||||
# Bind Home/End keys
|
||||
bindkey "^[[H" beginning-of-line
|
||||
bindkey "^[[F" end-of-line
|
||||
|
||||
# Bind Delete key
|
||||
bindkey "^[[3~" delete-char
|
||||
|
||||
# --- Custom Key Bindings ---
|
||||
# --- Custom Widgets ---
|
||||
|
||||
# Alt+R to reload zsh config
|
||||
reload-zsh() {
|
||||
@@ -242,7 +217,7 @@ reload-zsh() {
|
||||
zle reset-prompt
|
||||
}
|
||||
zle -N reload-zsh
|
||||
bindkey "^[r" reload-zsh # Alt+R
|
||||
bindkey "^[r" reload-zsh
|
||||
|
||||
# Alt+G to show git status
|
||||
git-status-widget() {
|
||||
@@ -251,45 +226,85 @@ git-status-widget() {
|
||||
zle reset-prompt
|
||||
}
|
||||
zle -N git-status-widget
|
||||
bindkey "^[g" git-status-widget # Alt+G
|
||||
bindkey "^[g" git-status-widget
|
||||
|
||||
# --- Application-Specific Settings ---
|
||||
# ============================================================================
|
||||
# Lazy-loaded Tools (for faster shell startup)
|
||||
# ============================================================================
|
||||
|
||||
# Node Version Manager (if installed)
|
||||
# --- NVM (lazy load) ---
|
||||
# Only loads when you first use node, npm, nvm, or npx
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
||||
|
||||
# Python virtual environment
|
||||
_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
|
||||
_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 "$@"
|
||||
}
|
||||
fi
|
||||
|
||||
# --- Python virtualenvwrapper (lazy load) ---
|
||||
export WORKON_HOME=$HOME/.virtualenvs
|
||||
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
|
||||
[ -f /usr/local/bin/virtualenvwrapper.sh ] && source /usr/local/bin/virtualenvwrapper.sh
|
||||
|
||||
# Rust cargo
|
||||
_load_virtualenvwrapper() {
|
||||
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
|
||||
[ -f /usr/local/bin/virtualenvwrapper.sh ] && source /usr/local/bin/virtualenvwrapper.sh
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
# --- Rust cargo (only if exists) ---
|
||||
[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
|
||||
|
||||
# --- OS-Specific Configuration ---
|
||||
|
||||
case "$(uname -s)" in
|
||||
Darwin*)
|
||||
# macOS specific settings
|
||||
export HOMEBREW_NO_ANALYTICS=1
|
||||
;;
|
||||
Linux*)
|
||||
# Linux specific settings
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Snapper Functions ---
|
||||
|
||||
# Source snapper snapshot management functions
|
||||
if [[ -f "$HOME/.dotfiles/zsh/functions/snapper.zsh" ]]; then
|
||||
source "$HOME/.dotfiles/zsh/functions/snapper.zsh"
|
||||
fi
|
||||
|
||||
# --- Local Configuration ---
|
||||
|
||||
# Load local configuration if it exists (for machine-specific settings)
|
||||
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
|
||||
|
||||
# ============================================================================
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#!/usr/bin/env zsh
|
||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
# % ~/.oh-my-zsh/themes/adlee.zsh-theme
|
||||
# === ADLee's zsh (oh-my-zsh) Theme ===
|
||||
# =====================================
|
||||
# ============================================================================
|
||||
# ADLee's zsh Theme for oh-my-zsh
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# CONFIGURATION & CONSTANTS
|
||||
# OPTIONS
|
||||
# ============================================================================
|
||||
|
||||
setopt PROMPT_SUBST
|
||||
@@ -13,13 +12,16 @@ setopt PROMPT_CR
|
||||
setopt PROMPT_SP
|
||||
setopt TYPESET_SILENT
|
||||
export PROMPT_EOL_MARK=''
|
||||
export KEYTIMEOUT=1
|
||||
|
||||
# Force color loading (critical for tmux)
|
||||
autoload -U colors && colors
|
||||
|
||||
export KEYTIMEOUT=1
|
||||
# ============================================================================
|
||||
# CONFIGURATION
|
||||
# ============================================================================
|
||||
|
||||
# Color definitions - always set these
|
||||
# Colors
|
||||
typeset -g COLOR_GREY='%{$FG[239]%}'
|
||||
typeset -g COLOR_YELLOW='%{$FG[179]%}'
|
||||
typeset -g COLOR_BLUE='%{$FG[069]%}'
|
||||
@@ -32,105 +34,54 @@ typeset -g COLOR_BRIGHT_GREEN='%{$FG[010]%}'
|
||||
typeset -g COLOR_RESET='%{$reset_color%}'
|
||||
typeset -g COLOR_BOLD='%{$FX[bold]%}'
|
||||
|
||||
# Path truncation threshold
|
||||
# Thresholds
|
||||
typeset -g PATH_TRUNCATE_LENGTH=32
|
||||
|
||||
# Timer threshold (seconds)
|
||||
typeset -g TIMER_THRESHOLD=10
|
||||
|
||||
# ============================================================================
|
||||
# GIT PROMPT CONFIGURATION
|
||||
# GIT PROMPT
|
||||
# ============================================================================
|
||||
|
||||
# Force load git library for git_prompt_info
|
||||
if [[ -f "$ZSH/lib/git.zsh" ]]; then
|
||||
source "$ZSH/lib/git.zsh"
|
||||
fi
|
||||
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg_bold[green]%}⎇ "
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color$FG[239]%}"
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}*"
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN=""
|
||||
|
||||
# ============================================================================
|
||||
# HELPER FUNCTIONS
|
||||
# COMMAND TIMER
|
||||
# ============================================================================
|
||||
|
||||
# Get shortened path (last two directories if path is too long)
|
||||
_adlee_get_short_path() {
|
||||
local full_path="$(pwd | sed -e 's/\/Users\/alee/~/g')"
|
||||
local path_len=$(echo -n "$full_path" | wc -m | tr -d ' ')
|
||||
|
||||
if [ "$path_len" -gt "$PATH_TRUNCATE_LENGTH" ]; then
|
||||
local short_path=$(pwd | awk -F '/' '{print $(NF - 1)"/"$NF}')
|
||||
echo "${COLOR_YELLOW}⋯${COLOR_RESET}${COLOR_GREY}${COLOR_YELLOW}/${short_path}${COLOR_RESET}${COLOR_GREY}"
|
||||
else
|
||||
echo "${COLOR_YELLOW}%~${COLOR_RESET}${COLOR_GREY}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Format user@host section
|
||||
_adlee_format_user_host() {
|
||||
echo "${COLOR_GREEN}%n@%m${COLOR_RESET}${COLOR_GREY}"
|
||||
}
|
||||
|
||||
# Format current directory with git info
|
||||
_adlee_format_directory() {
|
||||
local short_path="$(_adlee_get_short_path)"
|
||||
# Remove the single quotes so it gets evaluated in the prompt
|
||||
echo "${short_path}\$(git_prompt_info)${COLOR_GREY}"
|
||||
}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# COMMAND TIMER FUNCTIONS
|
||||
# ============================================================================
|
||||
|
||||
# Format elapsed time based on duration
|
||||
_adlee_format_elapsed_time() {
|
||||
local elapsed=$1
|
||||
local timestamp="%D{%Y-%m-%d %I:%M:%S}"
|
||||
|
||||
if [[ $elapsed -ge 3600 ]]; then
|
||||
# Hours
|
||||
if (( elapsed >= 3600 )); then
|
||||
local hours=$((elapsed / 3600))
|
||||
local remainder=$((elapsed % 3600))
|
||||
local minutes=$((remainder / 60))
|
||||
local seconds=$((remainder % 60))
|
||||
print -P "${COLOR_RED}•••[ completed in: %b%B${COLOR_RED}${hours}h${minutes}m${seconds}s%b${COLOR_RED} at: %b%B${COLOR_RED}${timestamp}%b${COLOR_RED} ]•••%b"
|
||||
elif [[ $elapsed -ge 60 ]]; then
|
||||
# Minutes
|
||||
elif (( elapsed >= 60 )); then
|
||||
local minutes=$((elapsed / 60))
|
||||
local seconds=$((elapsed % 60))
|
||||
print -P "${COLOR_ORANGE}••[ completed in: %b%B${COLOR_LIGHT_ORANGE}${minutes}m${seconds}s%b${COLOR_ORANGE} at: %b%B${COLOR_LIGHT_ORANGE}${timestamp}%b${COLOR_ORANGE} ]••%b"
|
||||
else
|
||||
# Seconds only
|
||||
print -P "${COLOR_LIGHT_GREEN}•[ completed in: %b%B${COLOR_BRIGHT_GREEN}${elapsed}s%b${COLOR_BRIGHT_GREEN} at: %b%B${COLOR_LIGHT_GREEN}${timestamp}%b${COLOR_LIGHT_GREEN} ]•%b"
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# PROMPT BUILDING
|
||||
# PROMPT
|
||||
# ============================================================================
|
||||
|
||||
|
||||
# Ensure git prompt function is available
|
||||
if ! (( $+functions[git_prompt_info] )); then
|
||||
# Git lib not loaded yet, source it manually
|
||||
source "$ZSH/lib/git.zsh" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
_adlee_build_prompt() {
|
||||
# Prompt character: blue for users, red for root
|
||||
# %(#.TRUE.FALSE) - if privileged (root), use TRUE, else FALSE
|
||||
# %(#.TRUE.FALSE) - red for root, blue for users
|
||||
PROMPT='%{$FG[239]%}┌[%{$FG[118]%}%n@%m%{$reset_color$FG[239]%}]─[%{$FG[179]%}%~%{$reset_color$FG[239]%}$(git_prompt_info)%{$FG[239]%}]
|
||||
%{$FG[239]%}└%{$FX[bold]%}%(#.%{$FG[196]%}.%{$FG[069]%})%#%{$reset_color%} '
|
||||
}
|
||||
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# ZSH HOOKS
|
||||
# HOOKS
|
||||
# ============================================================================
|
||||
|
||||
adlee_preexec() {
|
||||
@@ -139,34 +90,24 @@ adlee_preexec() {
|
||||
}
|
||||
|
||||
adlee_precmd() {
|
||||
# Handle command timer
|
||||
if [[ -n $cmd_start_time ]]; then
|
||||
local elapsed=$((SECONDS - cmd_start_time))
|
||||
if [[ $elapsed -gt $TIMER_THRESHOLD ]]; then
|
||||
_adlee_format_elapsed_time $elapsed
|
||||
fi
|
||||
(( elapsed > TIMER_THRESHOLD )) && _adlee_format_elapsed_time $elapsed
|
||||
unset cmd_start_time
|
||||
fi
|
||||
|
||||
# Configure ZLE highlighting
|
||||
zle_highlight=( default:fg=white )
|
||||
|
||||
# Rebuild prompt
|
||||
_adlee_build_prompt
|
||||
}
|
||||
|
||||
TRAPALRM() {
|
||||
_adlee_build_prompt
|
||||
if [[ "$WIDGET" != "expand-or-complete" ]]; then
|
||||
zle reset-prompt
|
||||
fi
|
||||
[[ "$WIDGET" != "expand-or-complete" ]] && zle reset-prompt
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# UTILITY FUNCTIONS
|
||||
# UTILITIES
|
||||
# ============================================================================
|
||||
|
||||
# Search command history
|
||||
histsearch() {
|
||||
fc -lim "$@" 1
|
||||
}
|
||||
@@ -175,15 +116,7 @@ histsearch() {
|
||||
# INITIALIZATION
|
||||
# ============================================================================
|
||||
|
||||
# Load required functions
|
||||
autoload -Uz add-zsh-hook
|
||||
|
||||
# Force initial prompt build for tmux
|
||||
if [[ -n "$TMUX" ]]; then
|
||||
_adlee_build_prompt
|
||||
fi
|
||||
|
||||
# Register hooks
|
||||
add-zsh-hook preexec adlee_preexec
|
||||
add-zsh-hook precmd adlee_precmd
|
||||
|
||||
@@ -191,44 +124,28 @@ add-zsh-hook precmd adlee_precmd
|
||||
zle -N zle-line-init
|
||||
zle -N zle-keymap-select
|
||||
|
||||
# Define zshrc reload function and widget
|
||||
# Initial prompt build (critical for tmux)
|
||||
_adlee_build_prompt
|
||||
|
||||
# ============================================================================
|
||||
# CUSTOM WIDGETS
|
||||
# ============================================================================
|
||||
|
||||
reload-zshrc() {
|
||||
echo -n "Re-sourcing \`~/.zshrc.\` ... "
|
||||
echo -n "Re-sourcing ~/.zshrc ... "
|
||||
source ~/.zshrc
|
||||
echo "Completed."
|
||||
echo "Done."
|
||||
_adlee_build_prompt
|
||||
zle reset-prompt
|
||||
}
|
||||
zle -N reload-zshrc # Register as a widget
|
||||
bindkey "^X@s^[^R" reload-zshrc # Bind to Ctrl+Super+Alt+R
|
||||
zle -N reload-zshrc
|
||||
bindkey "^X@s^[^R" reload-zshrc # Ctrl+Super+Alt+R
|
||||
|
||||
# Function.
|
||||
grab-fastfetch() {
|
||||
echo "fastfetch"
|
||||
fastfetch
|
||||
_adlee_build_prompt
|
||||
zle reset-prompt
|
||||
}
|
||||
zle -N grab-fastfetch # Register as a widget
|
||||
bindkey "^X@s^[^F" grab-fastfetch # Bind to Ctrl+Super+Alt+F
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# DEPLOYMENT NOTES
|
||||
# ============================================================================
|
||||
# For system-wide deployment, use one of these approaches:
|
||||
#
|
||||
# OPTION 1: Symlink (Recommended)
|
||||
# Master location: /usr/local/share/zsh/themes/adlee.zsh-theme
|
||||
# User symlinks:
|
||||
# ln -sf /usr/local/share/zsh/themes/adlee.zsh-theme ~/.oh-my-zsh/themes/adlee.zsh-theme
|
||||
# sudo ln -sf /usr/local/share/zsh/themes/adlee.zsh-theme /root/.oh-my-zsh/themes/adlee.zsh-theme
|
||||
#
|
||||
# OPTION 2: Source from shared location
|
||||
# In each user's ~/.zshrc (before oh-my-zsh initialization):
|
||||
# source /usr/local/share/zsh/themes/adlee.zsh-theme
|
||||
#
|
||||
# OPTION 3: Custom oh-my-zsh location
|
||||
# Set in ~/.zshrc:
|
||||
# export ZSH_CUSTOM="/usr/local/share/oh-my-zsh-custom"
|
||||
# Then place theme in: /usr/local/share/oh-my-zsh-custom/themes/adlee.zsh-theme
|
||||
zle -N grab-fastfetch
|
||||
bindkey "^X@s^[^F" grab-fastfetch # Ctrl+Super+Alt+F
|
||||
|
||||
Reference in New Issue
Block a user