Dotfiles update 2025-12-22 12:00

This commit is contained in:
Aaron D. Lee
2025-12-22 12:00:32 -05:00
parent 23ee772ac4
commit 9e916c6c54
13 changed files with 646 additions and 1525 deletions

View File

@@ -2,63 +2,38 @@
# ============================================================================
# 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'
# Source shared colors
source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m' DF_CYAN=$'\033[0;36m'
DF_NC=$'\033[0m' DF_GREY=$'\033[38;5;242m' DF_LIGHT_BLUE=$'\033[38;5;39m'
DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m'
}
# ============================================================================
# MOTD-style header
# ============================================================================
_M_WIDTH=66
print_header() {
local user="${USER:-root}"
local hostname="${HOST:-$(hostname -s 2>/dev/null)}"
local script_name="dotfiles-compile"
local datetime=$(date '+%a %b %d %H:%M')
# Colors
local _M_RESET=$'\033[0m'
local _M_BOLD=$'\033[1m'
local _M_DIM=$'\033[2m'
local _M_BLUE=$'\033[38;5;39m'
local _M_GREY=$'\033[38;5;242m'
# Build horizontal line
local hline=""
for ((i=0; i<_M_WIDTH; i++)); do hline+="═"; done
local inner=$((_M_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
echo ""
echo "${_M_GREY}${hline}${_M_RESET}"
echo "${_M_GREY}${_M_RESET} ${_M_BOLD}${_M_BLUE}${h_left}${_M_RESET}${h_spaces}${_M_DIM}${h_center}${h_spaces}${h_right}${_M_RESET} ${_M_GREY}${_M_RESET}"
echo "${_M_GREY}${hline}${_M_RESET}"
echo ""
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-compile"
else
local user="${USER:-root}"
local hostname="${HOST:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local width=66
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
echo ""
echo "${DF_GREY}${hline}${DF_NC}"
echo "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_DIM}dotfiles-compile${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo "${DF_GREY}${hline}${DF_NC}"
echo ""
fi
}
compile_file() {
@@ -66,10 +41,10 @@ compile_file() {
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##*/}"
echo -e "${DF_GREEN}${DF_NC} Compiled: ${file##*/}" || \
echo -e "${DF_YELLOW}${DF_NC} Skipped: ${file##*/}"
else
echo -e "${CYAN}${NC} Current: ${file##*/}"
echo -e "${DF_CYAN}${DF_NC} Current: ${file##*/}"
fi
fi
}
@@ -79,57 +54,46 @@ clean_compiled() {
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"
echo -e "${DF_GREEN}${DF_NC} Removed $count compiled files"
}
compile_all() {
echo -e "${CYAN}Compiling zsh files for faster startup...${NC}"
echo -e "${DF_CYAN}Compiling zsh files for faster startup...${DF_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 -e "${DF_GREEN}${DF_NC} Compilation complete"
echo
echo "To measure startup time:"
echo " time zsh -i -c exit"
@@ -145,9 +109,6 @@ show_help() {
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."
}
# ============================================================================
@@ -157,13 +118,7 @@ show_help() {
print_header
case "${1:-}" in
--clean|-c)
clean_compiled
;;
--help|-h)
show_help
;;
*)
compile_all
;;
--clean|-c) clean_compiled ;;
--help|-h) show_help ;;
*) compile_all ;;
esac