Dotfiles update 2025-12-25 12:04

This commit is contained in:
Aaron D. Lee
2025-12-25 12:04:56 -05:00
parent 4695b1e410
commit afb9c78c9b
71 changed files with 8163 additions and 758 deletions

135
zsh/lib/bootstrap.zsh Normal file
View File

@@ -0,0 +1,135 @@
# ============================================================================
# Dotfiles Bootstrap - Single Entry Point
# ============================================================================
# This is the ONE file to source in all scripts and functions.
# It handles loading config, colors, and utils in the correct order with
# proper fallbacks.
#
# Usage in zsh functions:
# source "${0:A:h}/../lib/bootstrap.zsh"
#
# Usage in bash scripts:
# source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.zsh"
#
# After sourcing, you have access to:
# - All DF_* color variables
# - All df_print_* functions
# - All df_* utility functions
# - All config variables from dotfiles.conf
# ============================================================================
# Prevent double-sourcing (works in both bash and zsh)
[[ -n "$_DF_BOOTSTRAP_LOADED" ]] && return 0
# ============================================================================
# Determine Dotfiles Root
# ============================================================================
_df_find_root() {
# Check common locations in order of preference
local locations=(
"${DOTFILES_DIR}"
"${DOTFILES_HOME}"
"$HOME/.dotfiles"
)
for loc in "${locations[@]}"; do
[[ -n "$loc" && -d "$loc" && -f "$loc/dotfiles.conf" ]] && {
echo "$loc"
return 0
}
done
# Fallback: try to find from script location (zsh)
if [[ -n "$ZSH_VERSION" ]]; then
local script_dir="${0:A:h}"
# Walk up looking for dotfiles.conf
while [[ "$script_dir" != "/" ]]; do
[[ -f "$script_dir/dotfiles.conf" ]] && { echo "$script_dir"; return 0; }
script_dir="${script_dir:h}"
done
fi
# Last resort
echo "$HOME/.dotfiles"
}
# Set the root directory
typeset -g _DF_ROOT="$(_df_find_root)"
typeset -g DOTFILES_DIR="$_DF_ROOT"
typeset -g DOTFILES_HOME="$_DF_ROOT"
# ============================================================================
# Source Core Files (in correct order)
# ============================================================================
# 1. Config first (sets DF_WIDTH, MOTD_STYLE, etc.)
if [[ -f "$_DF_ROOT/zsh/lib/config.zsh" ]]; then
source "$_DF_ROOT/zsh/lib/config.zsh"
else
# Minimal fallback config
typeset -g DOTFILES_VERSION="${DOTFILES_VERSION:-1.0.0}"
typeset -g DF_WIDTH="${DF_WIDTH:-66}"
typeset -g MOTD_STYLE="${MOTD_STYLE:-compact}"
typeset -g DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
fi
# 2. Colors second
if [[ -f "$_DF_ROOT/zsh/lib/colors.zsh" ]]; then
source "$_DF_ROOT/zsh/lib/colors.zsh"
else
# Minimal fallback colors
typeset -g DF_RED=$'\033[0;31m'
typeset -g DF_GREEN=$'\033[0;32m'
typeset -g DF_YELLOW=$'\033[1;33m'
typeset -g DF_BLUE=$'\033[0;34m'
typeset -g DF_CYAN=$'\033[0;36m'
typeset -g DF_NC=$'\033[0m'
typeset -g DF_GREY=$'\033[38;5;242m'
typeset -g DF_LIGHT_BLUE=$'\033[38;5;39m'
typeset -g DF_LIGHT_GREEN=$'\033[38;5;82m'
typeset -g DF_BOLD=$'\033[1m'
typeset -g DF_DIM=$'\033[2m'
fi
# 3. Utils last (depends on config and colors)
if [[ -f "$_DF_ROOT/zsh/lib/utils.zsh" ]]; then
source "$_DF_ROOT/zsh/lib/utils.zsh"
fi
# ============================================================================
# Ensure Critical Functions Exist
# ============================================================================
# If utils.zsh failed to load, provide minimal implementations
if ! declare -f df_print_header &>/dev/null; then
df_print_header() {
local name="${1:-script}"
echo ""
echo "=== ${name} ==="
echo ""
}
fi
if ! declare -f df_print_func_name &>/dev/null; then
df_print_func_name() {
echo "--- ${1:-function} ---"
}
fi
if ! declare -f df_print_success &>/dev/null; then
df_print_success() { echo "$1"; }
df_print_error() { echo "$1" >&2; }
df_print_warning() { echo "$1"; }
df_print_info() { echo " $1"; }
df_print_step() { echo "==> $1"; }
fi
# ============================================================================
# Mark as Loaded
# ============================================================================
typeset -g _DF_BOOTSTRAP_LOADED=1
# Export for subshells (bash compatibility)
export DOTFILES_DIR DOTFILES_HOME DOTFILES_VERSION DF_WIDTH

View File

@@ -4,7 +4,7 @@
# Source this file in scripts and functions to get consistent color support.
#
# Usage in zsh functions:
# source "${0:A:h}/../lib/colors.zsh" 2>/dev/null || source "$HOME/.dotfiles/zsh/lib/colors.zsh"
# source "${0:A:h}/../lib/colors.zsh"
#
# Usage in bash scripts:
# source "$HOME/.dotfiles/zsh/lib/colors.zsh"

View File

@@ -3,10 +3,10 @@
# ============================================================================
# Common helper functions used across multiple function files.
#
# This file sources config.zsh (which sources dotfiles.conf) and colors.zsh,
# so sourcing this single file gives you access to everything.
# This file is typically sourced via bootstrap.zsh, which handles loading
# config.zsh and colors.zsh first.
#
# Source this file in function files:
# Direct usage (if needed):
# source "${0:A:h}/../lib/utils.zsh"
# ============================================================================
@@ -15,65 +15,52 @@
typeset -g _DF_UTILS_LOADED=1
# ============================================================================
# Source Configuration and Colors
# Source Dependencies (if not already loaded via bootstrap)
# ============================================================================
# Order matters: config first (sets DF_WIDTH, etc.), then colors
# Find lib directory
_df_lib_dir="${0:A:h}"
[[ ! -d "$_df_lib_dir" ]] && _df_lib_dir="$HOME/.dotfiles/zsh/lib"
# Source config (provides all settings from dotfiles.conf)
source "${_df_lib_dir}/config.zsh" 2>/dev/null || \
source "$HOME/.dotfiles/zsh/lib/config.zsh" 2>/dev/null || {
# Fallback: set critical defaults if config.zsh not found
typeset -g DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
typeset -g DOTFILES_HOME="${DOTFILES_HOME:-$DOTFILES_DIR}"
typeset -g DOTFILES_VERSION="${DOTFILES_VERSION:-unknown}"
typeset -g DF_WIDTH="${DF_WIDTH:-66}"
# Source config if not already loaded
[[ -z "$_DF_CONFIG_LOADED" ]] && {
source "${_df_lib_dir}/config.zsh" 2>/dev/null || \
source "$HOME/.dotfiles/zsh/lib/config.zsh" 2>/dev/null || {
typeset -g DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
typeset -g DOTFILES_HOME="${DOTFILES_HOME:-$DOTFILES_DIR}"
typeset -g DOTFILES_VERSION="${DOTFILES_VERSION:-unknown}"
typeset -g DF_WIDTH="${DF_WIDTH:-66}"
}
}
# Source colors
source "${_df_lib_dir}/colors.zsh" 2>/dev/null || \
source "$HOME/.dotfiles/zsh/lib/colors.zsh" 2>/dev/null || {
# Fallback colors if colors.zsh not found
typeset -g DF_RED=$'\033[0;31m' DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m'
typeset -g DF_BLUE=$'\033[0;34m' DF_CYAN=$'\033[0;36m' DF_NC=$'\033[0m'
typeset -g DF_GREY=$'\033[38;5;242m' DF_LIGHT_BLUE=$'\033[38;5;39m'
typeset -g DF_LIGHT_GREEN=$'\033[38;5;82m' DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m'
# Source colors if not already loaded
[[ -z "$_DF_COLORS_LOADED" ]] && {
source "${_df_lib_dir}/colors.zsh" 2>/dev/null || \
source "$HOME/.dotfiles/zsh/lib/colors.zsh" 2>/dev/null || {
typeset -g DF_RED=$'\033[0;31m' DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m'
typeset -g DF_BLUE=$'\033[0;34m' DF_CYAN=$'\033[0;36m' DF_NC=$'\033[0m'
typeset -g DF_GREY=$'\033[38;5;242m' DF_LIGHT_BLUE=$'\033[38;5;39m'
typeset -g DF_LIGHT_GREEN=$'\033[38;5;82m' DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m'
}
}
unset _df_lib_dir
# ============================================================================
# MOTD-Style Header Functions
# Header Box Drawing (Centralized Implementation)
# ============================================================================
# These functions eliminate header duplication across all scripts.
# Prints a standardized header box for functions
# Usage: df_print_func_name "Function Name"
df_print_func_name() {
local func_name="${1:-func}"
local datetime=$(date '+%a %b %d %H:%M')
local width="${DF_WIDTH:-66}"
# Build horizontal line
local hline=""
for ((i=0; i<width; i++)); do hline+="═"; done
local inner=$((width - 2))
# Header content
local h_left="${func_name}"
local h_right="${datetime}"
local h_pad=$((inner - ${#h_left} - ${#h_right}))
local h_spaces=""
for ((i=0; i<h_pad; i++)); do h_spaces+=" "; done
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${h_left}${DF_NC}${h_spaces}${DF_NC}${DF_BOLD}${h_right}${DF_NC} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
# Build a horizontal line of specified character and width
# Usage: _df_hline "═" 66
_df_hline() {
local char="${1:-}"
local width="${2:-$DF_WIDTH}"
local line=""
for ((i=0; i<width; i++)); do line+="$char"; done
echo "$line"
}
# Prints a standardized header box for scripts
# Print a MOTD-style header box for scripts
# Usage: df_print_header "script-name"
df_print_header() {
local script_name="${1:-script}"
@@ -83,29 +70,68 @@ df_print_header() {
local width="${DF_WIDTH:-66}"
# Build horizontal line
local hline=""
for ((i=0; i<width; i++)); do hline+="═"; done
local hline=$(_df_hline "═" "$width")
local inner=$((width - 2))
# Header content
local h_left="${user}@${hostname}"
local h_center="${script_name}"
local h_right="${datetime}"
local h_pad=$(((inner - ${#h_left} - ${#h_center} - ${#h_right}) / 2))
local h_spaces=""
for ((i=0; i<h_pad; i++)); do h_spaces+=" "; done
# Calculate padding (distribute space evenly)
local content_len=$((${#h_left} + ${#h_center} + ${#h_right}))
local total_padding=$((inner - content_len))
local left_pad=$((total_padding / 2))
local right_pad=$((total_padding - left_pad))
# Build padding strings
local left_spaces="" right_spaces=""
for ((i=0; i<left_pad; i++)); do left_spaces+=" "; done
for ((i=0; i<right_pad; i++)); do right_spaces+=" "; done
# Use red for root, light blue for normal users
local user_color="${DF_LIGHT_BLUE}"
[[ "$EUID" -eq 0 ]] && user_color="${DF_RED}"
[[ "${EUID:-$(id -u)}" -eq 0 ]] && user_color="${DF_RED}"
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${user_color}${h_left}${DF_NC}${h_spaces}${DF_LIGHT_GREEN}${h_center}${h_spaces}${DF_NC}${DF_BOLD}${h_right}${DF_NC} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${user_color}${h_left}${DF_NC}${left_spaces}${DF_LIGHT_GREEN}${h_center}${right_spaces}${DF_NC}${DF_BOLD}${h_right}${DF_NC} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
}
# Print a header box for functions (simpler, no user@host)
# Usage: df_print_func_name "Function Name"
df_print_func_name() {
local func_name="${1:-func}"
local datetime=$(date '+%a %b %d %H:%M')
local width="${DF_WIDTH:-66}"
# Build horizontal line
local hline=$(_df_hline "═" "$width")
local inner=$((width - 2))
# Header content (function name on left, datetime on right)
local h_left="${func_name}"
local h_right="${datetime}"
local h_pad=$((inner - ${#h_left} - ${#h_right}))
local h_spaces=""
for ((i=0; i<h_pad; i++)); do h_spaces+=" "; done
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${h_left}${DF_NC}${h_spaces}${DF_BOLD}${h_right}${DF_NC} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
}
# Print a simple section divider line
# Usage: df_print_divider
df_print_divider() {
local width="${DF_WIDTH:-66}"
local line=$(_df_hline "─" "$width")
echo -e "${DF_CYAN}${line}${DF_NC}"
}
# ============================================================================
# Output Formatting Functions
# ============================================================================
@@ -142,9 +168,16 @@ df_require_cmd() {
df_confirm() {
local prompt="$1"
read -q "REPLY?$prompt [y/N]: "
echo
[[ "$REPLY" =~ ^[Yy]$ ]]
local response
if [[ -n "$ZSH_VERSION" ]]; then
read -q "response?$prompt [y/N]: "
echo
[[ "$response" =~ ^[Yy]$ ]]
else
read -p "$prompt [y/N]: " response
[[ "$response" =~ ^[Yy]$ ]]
fi
}
df_confirm_warning() {