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

View File

@@ -5,48 +5,29 @@
set -e
DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
# Source shared colors and utils (provides DF_WIDTH)
source "$DOTFILES_DIR/zsh/lib/utils.zsh" 2>/dev/null || \
source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
# Source bootstrap
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.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'
DF_NC=$'\033[0m'
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
df_print_header() { echo "=== $1 ==="; }
df_print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
}
# Use DF_WIDTH from utils.zsh or default to 66
typeset -g WIDTH="${DF_WIDTH:-66}"
# ============================================================================
# MOTD-style header
# Functions
# ============================================================================
print_header() {
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 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() {
local file="$1"
if [[ -f "$file" ]]; then
if [[ ! -f "${file}.zwc" ]] || [[ "$file" -nt "${file}.zwc" ]]; then
zcompile "$file" 2>/dev/null && \
echo -e "${DF_GREEN}${DF_NC} Compiled: ${file##*/}" || \
if zcompile "$file" 2>/dev/null; then
echo -e "${DF_GREEN}${DF_NC} Compiled: ${file##*/}"
else
echo -e "${DF_YELLOW}${DF_NC} Skipped: ${file##*/}"
fi
else
echo -e "${DF_CYAN}${DF_NC} Current: ${file##*/}"
fi
@@ -55,54 +36,60 @@ compile_file() {
clean_compiled() {
echo "Removing compiled files..."
local count=0
for zwc in "$DOTFILES_DIR"/**/*.zwc(N); do
# Remove .zwc files in dotfiles directory
for zwc in "$DOTFILES_HOME"/**/*.zwc(N); do
rm -f "$zwc"
((count++))
done
# Remove home directory compiled files
rm -f ~/.zshrc.zwc ~/.zshenv.zwc ~/.zprofile.zwc 2>/dev/null
echo -e "${DF_GREEN}${DF_NC} Removed $count compiled files"
}
compile_all() {
echo -e "${DF_CYAN}Compiling zsh files for faster startup...${DF_NC}"
echo
echo ""
echo "Core files:"
compile_file ~/.zshrc
compile_file ~/.zshenv
compile_file ~/.zprofile
echo
echo ""
echo "Dotfiles:"
compile_file "$DOTFILES_DIR/zsh/.zshrc"
compile_file "$DOTFILES_DIR/zsh/aliases.zsh"
for file in "$DOTFILES_DIR/zsh/lib"/*.zsh(N); do
compile_file "$DOTFILES_HOME/zsh/.zshrc"
compile_file "$DOTFILES_HOME/zsh/aliases.zsh"
# Lib files
for file in "$DOTFILES_HOME/zsh/lib"/*.zsh(N); do
compile_file "$file"
done
for file in "$DOTFILES_DIR/zsh/functions"/*.zsh(N); do
# Function files
for file in "$DOTFILES_HOME/zsh/functions"/*.zsh(N); do
compile_file "$file"
done
for file in "$DOTFILES_DIR/zsh/themes"/*.zsh-theme(N); do
# Theme files
for file in "$DOTFILES_HOME/zsh/themes"/*.zsh-theme(N); do
compile_file "$file"
done
echo
echo ""
# Oh-My-Zsh (optional)
if [[ -d ~/.oh-my-zsh ]]; then
echo "Oh-My-Zsh (optional):"
compile_file ~/.oh-my-zsh/oh-my-zsh.sh
echo
echo ""
fi
echo -e "${DF_GREEN}${DF_NC} Compilation complete"
echo
echo ""
echo "To measure startup time:"
echo " time zsh -i -c exit"
echo " hyperfine 'zsh -i -c exit' # More accurate"
@@ -110,9 +97,9 @@ compile_all() {
show_help() {
echo "Usage: dotfiles-compile.sh [OPTIONS]"
echo
echo ""
echo "Compile zsh files to bytecode for faster shell startup."
echo
echo ""
echo "Options:"
echo " (none) Compile all zsh files"
echo " --clean Remove all compiled (.zwc) files"
@@ -123,7 +110,7 @@ show_help() {
# Main
# ============================================================================
print_header
df_print_header "dotfiles-compile"
case "${1:-}" in
--clean|-c) clean_compiled ;;

View File

@@ -8,39 +8,25 @@
# dotfiles-doctor.sh --quick # Quick essential checks only
# ============================================================================
# ============================================================================
# Source Configuration
# ============================================================================
# utils.zsh sources config.zsh which sources dotfiles.conf
# This gives us access to all settings including DF_WIDTH, DOTFILES_VERSION, etc.
_df_source_config() {
local locations=(
"${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/utils.zsh"
"$HOME/.dotfiles/zsh/lib/utils.zsh"
)
for loc in "${locations[@]}"; do
[[ -f "$loc" ]] && { source "$loc"; return 0; }
done
# Fallback defaults if utils.zsh not found
# Source bootstrap (provides colors, config, and utility functions)
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.zsh" 2>/dev/null || {
echo "Warning: bootstrap.zsh not found, using fallbacks"
DF_RED=$'\033[0;31m' DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m'
DF_BLUE=$'\033[0;34m' 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' DF_LIGHT_GREEN=$'\033[38;5;82m'
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
DOTFILES_VERSION="${DOTFILES_VERSION:-unknown}"
DF_WIDTH="${DF_WIDTH:-66}"
df_print_header() { echo "=== $1 ==="; }
df_print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
df_print_error() { echo -e "${DF_RED}${DF_NC} $1" >&2; }
df_print_warning() { echo -e "${DF_YELLOW}${DF_NC} $1"; }
}
_df_source_config
# ============================================================================
# Parse Arguments
# ============================================================================
DO_FIX=false
QUICK_MODE=false
for arg in "$@"; do
case "$arg" in
--fix) DO_FIX=true ;;
@@ -57,7 +43,10 @@ for arg in "$@"; do
esac
done
# Track results
# ============================================================================
# Tracking Variables
# ============================================================================
TOTAL_CHECKS=0
PASSED_CHECKS=0
FAILED_CHECKS=0
@@ -65,39 +54,41 @@ WARNING_CHECKS=0
FIXED_CHECKS=0
# ============================================================================
# Header (uses DF_WIDTH from config)
# Check Helper Functions
# ============================================================================
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-doctor"
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local width="${DF_WIDTH:-66}"
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
print_section() { echo -e "\n${DF_BLUE}${DF_NC} $1"; }
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-doctor${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
fi
check_pass() {
((PASSED_CHECKS++))
((TOTAL_CHECKS++))
echo -e " ${DF_GREEN}${DF_NC} $1"
}
check_fail() {
((FAILED_CHECKS++))
((TOTAL_CHECKS++))
echo -e " ${DF_RED}${DF_NC} $1"
}
check_warn() {
((WARNING_CHECKS++))
((TOTAL_CHECKS++))
echo -e " ${DF_YELLOW}${DF_NC} $1"
}
check_fixed() {
((FIXED_CHECKS++))
echo -e " ${DF_CYAN}${DF_NC} Fixed: $1"
}
# ============================================================================
# Check Functions
# ============================================================================
print_section() { echo -e "\n${DF_BLUE}${DF_NC} $1"; }
check_pass() { PASSED_CHECKS=$((PASSED_CHECKS + 1)); TOTAL_CHECKS=$((TOTAL_CHECKS + 1)); echo -e " ${DF_GREEN}${DF_NC} $1"; }
check_fail() { FAILED_CHECKS=$((FAILED_CHECKS + 1)); TOTAL_CHECKS=$((TOTAL_CHECKS + 1)); echo -e " ${DF_RED}${DF_NC} $1"; }
check_warn() { WARNING_CHECKS=$((WARNING_CHECKS + 1)); TOTAL_CHECKS=$((TOTAL_CHECKS + 1)); echo -e " ${DF_YELLOW}${DF_NC} $1"; }
check_fixed() { FIXED_CHECKS=$((FIXED_CHECKS + 1)); echo -e " ${DF_CYAN}${DF_NC} Fixed: $1"; }
check_os() {
print_section "Operating System"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if grep -qi "cachyos" /etc/os-release 2>/dev/null; then
check_pass "Running CachyOS"
@@ -109,60 +100,135 @@ check_os() {
else
check_fail "Not running on Linux"
fi
check_pass "Kernel: $(uname -r)"
}
check_shell() {
print_section "Shell Configuration"
[[ -f "$HOME/.zshrc" ]] && check_pass "Zsh configuration exists" || check_fail "Zsh configuration missing"
[[ "$SHELL" == *"zsh"* ]] && check_pass "Zsh is default shell" || check_warn "Zsh is not default shell"
command -v zsh &>/dev/null && check_pass "Zsh version: $(zsh --version | awk '{print $2}')"
if command -v zsh &>/dev/null; then
check_pass "Zsh version: $(zsh --version | awk '{print $2}')"
fi
}
check_symlinks() {
print_section "Symlinks"
for symlink in ~/.zshrc ~/.gitconfig ~/.vimrc ~/.tmux.conf; do
local symlinks=(
"$HOME/.zshrc"
"$HOME/.gitconfig"
"$HOME/.vimrc"
"$HOME/.tmux.conf"
)
for symlink in "${symlinks[@]}"; do
if [[ -L "$symlink" ]]; then
[[ -e "$symlink" ]] && check_pass "$(basename $symlink)$(readlink $symlink)" || check_fail "$(basename $symlink) is broken"
if [[ -e "$symlink" ]]; then
check_pass "$(basename "$symlink")$(readlink "$symlink")"
else
check_fail "$(basename "$symlink") is broken symlink"
if [[ "$DO_FIX" == true ]]; then
rm "$symlink"
check_fixed "Removed broken symlink: $(basename "$symlink")"
fi
fi
elif [[ -f "$symlink" ]]; then
check_warn "$(basename $symlink) is regular file (not symlink)"
check_warn "$(basename "$symlink") is regular file (not symlink)"
fi
done
}
check_pacman() {
print_section "Package Manager"
command -v pacman &>/dev/null && check_pass "Pacman available" || { check_fail "Pacman not found"; return; }
command -v paru &>/dev/null && check_pass "AUR helper: paru" || \
command -v yay &>/dev/null && check_pass "AUR helper: yay" || check_warn "No AUR helper installed"
if ! command -v pacman &>/dev/null; then
check_fail "Pacman not found"
return
fi
check_pass "Pacman available"
if command -v paru &>/dev/null; then
check_pass "AUR helper: paru"
elif command -v yay &>/dev/null; then
check_pass "AUR helper: yay"
else
check_warn "No AUR helper installed (paru or yay recommended)"
fi
}
check_optional_tools() {
print_section "Optional Tools"
command -v fzf &>/dev/null && check_pass "fzf" || check_warn "fzf not installed"
command -v bat &>/dev/null && check_pass "bat" || check_warn "bat not installed"
command -v eza &>/dev/null && check_pass "eza" || check_warn "eza not installed"
command -v tmux &>/dev/null && check_pass "tmux" || check_warn "tmux not installed"
local tools=("fzf" "bat" "eza" "tmux" "nvim")
for tool in "${tools[@]}"; do
command -v "$tool" &>/dev/null && check_pass "$tool" || check_warn "$tool not installed"
done
}
check_dotfiles_dir() {
print_section "Dotfiles Directory"
[[ -d "$DOTFILES_HOME" ]] && check_pass "Dotfiles: $DOTFILES_HOME" || { check_fail "Dotfiles not found"; return; }
if [[ ! -d "$DOTFILES_HOME" ]]; then
check_fail "Dotfiles not found"
return
fi
check_pass "Dotfiles: $DOTFILES_HOME"
[[ -f "$DOTFILES_HOME/dotfiles.conf" ]] && check_pass "Config file exists" || check_warn "Config file missing"
[[ -d "$DOTFILES_HOME/.git" ]] && check_pass "Git repo initialized" || check_warn "Not a git repository"
check_pass "Version: $DOTFILES_VERSION"
check_pass "Display width: $DF_WIDTH"
check_pass "Version: ${DOTFILES_VERSION:-unknown}"
check_pass "Display width: ${DF_WIDTH:-66}"
}
check_bin_scripts() {
print_section "Bin Scripts"
local scripts=(
"dotfiles-doctor.sh"
"dotfiles-sync.sh"
"dotfiles-update.sh"
"dotfiles-version.sh"
)
for script in "${scripts[@]}"; do
if [[ -x "$HOME/.local/bin/$script" ]]; then
check_pass "$script"
elif [[ -f "$HOME/.local/bin/$script" ]]; then
check_warn "$script exists but not executable"
if [[ "$DO_FIX" == true ]]; then
chmod +x "$HOME/.local/bin/$script"
check_fixed "Made executable: $script"
fi
else
check_fail "$script not linked"
fi
done
}
# ============================================================================
# Summary
# ============================================================================
print_summary() {
local width="${DF_WIDTH:-66}"
echo ""
printf "${DF_CYAN}─%.0s${DF_NC}" $(seq 1 $width); echo ""
printf "${DF_CYAN}─%.0s${DF_NC}" $(seq 1 "$width")
echo ""
if [[ $FAILED_CHECKS -eq 0 ]]; then
echo -e "${DF_GREEN}${DF_NC} All checks passed ($PASSED_CHECKS/$TOTAL_CHECKS)"
else
echo -e "${DF_RED}${DF_NC} Issues found: $FAILED_CHECKS failed, $WARNING_CHECKS warnings"
fi
[[ $FIXED_CHECKS -gt 0 ]] && echo -e "${DF_CYAN}${DF_NC} Auto-fixed: $FIXED_CHECKS issues"
echo ""
}
@@ -171,13 +237,19 @@ print_summary() {
# ============================================================================
main() {
print_header
df_print_header "dotfiles-doctor"
check_os
check_pacman
check_shell
check_dotfiles_dir
check_symlinks
[[ "$QUICK_MODE" != true ]] && check_optional_tools
if [[ "$QUICK_MODE" != true ]]; then
check_optional_tools
check_bin_scripts
fi
print_summary
}

View File

@@ -5,41 +5,18 @@
set -e
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
# Source shared colors and utils (provides DF_WIDTH)
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null || \
source "$DOTFILES_HOME/zsh/lib/colors.zsh" 2>/dev/null || {
# Source bootstrap
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.zsh" 2>/dev/null || {
DF_RED=$'\033[0;31m' DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m'
DF_BLUE=$'\033[0;34m' DF_CYAN=$'\033[0;36m' DF_MAGENTA=$'\033[0;35m'
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' DF_LIGHT_GREEN=$'\033[38;5;82m'
DF_NC=$'\033[0m'
df_print_header() { echo "=== $1 ==="; }
}
# Use DF_WIDTH from utils.zsh or default to 66
readonly WIDTH="${DF_WIDTH:-66}"
# ============================================================================
# MOTD-style header
# Helper Functions
# ============================================================================
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-stats "
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local hline="" && for ((i=0; i<WIDTH; i++)); do hline+="═"; done
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-stats${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
fi
}
print_section() {
echo ""
echo -e "${DF_BLUE}${DF_NC} $1"
@@ -48,32 +25,85 @@ print_section() {
get_history() {
if [[ -f "$HOME/.zsh_history" ]]; then
grep -I "^:" "$HOME/.zsh_history" | cut -d';' -f2 || cat "$HOME/.zsh_history"
# Handle zsh extended history format
grep -I "^:" "$HOME/.zsh_history" 2>/dev/null | cut -d';' -f2 || cat "$HOME/.zsh_history"
elif [[ -f "$HOME/.bash_history" ]]; then
cat "$HOME/.bash_history"
fi
}
# ============================================================================
# Analytics Functions
# ============================================================================
show_dashboard() {
print_section "Command History Dashboard"
local total=$(get_history | wc -l)
local unique=$(get_history | sort | uniq | wc -l)
local unique=$(get_history | sort -u | wc -l)
echo -e " ${DF_CYAN}Total Commands:${DF_NC} $total"
echo -e " ${DF_CYAN}Unique Commands:${DF_NC} $unique"
echo ""
print_section "Top 15 Commands"
get_history | awk '{print $1}' | sort | uniq -c | sort -rn | head -15 | while read count cmd; do
printf " %-20s ${DF_GREEN}%5d${DF_NC}\n" "$cmd" "$count"
printf " %-25s ${DF_GREEN}%5d${DF_NC}\n" "$cmd" "$count"
done
echo ""
}
show_top() {
local count="${1:-20}"
print_section "Top $count Commands"
get_history | awk '{print $1}' | sort | uniq -c | sort -rn | head -"$count" | while read cnt cmd; do
printf " %-25s ${DF_GREEN}%5d${DF_NC}\n" "$cmd" "$cnt"
done
}
show_git_stats() {
print_section "Git Command Breakdown"
get_history | grep "^git " | awk '{print $2}' | sort | uniq -c | sort -rn | head -10 | while read count subcmd; do
printf " git %-20s ${DF_GREEN}%5d${DF_NC}\n" "$subcmd" "$count"
done
}
show_dirs() {
print_section "Most Visited Directories"
get_history | grep "^cd " | awk '{print $2}' | sort | uniq -c | sort -rn | head -10 | while read count dir; do
printf " %-30s ${DF_GREEN}%5d${DF_NC}\n" "$dir" "$count"
done
}
show_help() {
echo "Usage: dotfiles-stats.sh [COMMAND]"
echo ""
echo "Commands:"
echo " dashboard Full analytics dashboard (default)"
echo " top [n] Top N commands (default: 20)"
echo " git Git command breakdown"
echo " dirs Most visited directories"
echo " help Show this help"
}
# ============================================================================
# Main
# ============================================================================
main() {
print_header
df_print_header "dotfiles-stats"
case "${1:-dashboard}" in
dashboard) show_dashboard ;;
top) get_history | awk '{print $1}' | sort | uniq -c | sort -rn | head -"${2:-20}" ;;
*) echo "Usage: $0 {dashboard|top [n]}"; exit 1 ;;
top) show_top "${2:-20}" ;;
git) show_git_stats ;;
dirs) show_dirs ;;
help|--help|-h) show_help ;;
*)
echo "Unknown command: $1"
show_help
exit 1
;;
esac
}

View File

@@ -5,50 +5,15 @@
set -e
# ============================================================================
# Source Configuration
# ============================================================================
_df_source_config() {
local locations=(
"${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/utils.zsh"
"$HOME/.dotfiles/zsh/lib/utils.zsh"
)
for loc in "${locations[@]}"; do
[[ -f "$loc" ]] && { source "$loc"; return 0; }
done
# Fallback defaults
# Source bootstrap (provides colors, config, and utility functions)
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.zsh" 2>/dev/null || {
DF_RED=$'\033[0;31m' DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m'
DF_BLUE=$'\033[0;34m' 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_LIGHT_GREEN=$'\033[38;5;82m'
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
DF_WIDTH="${DF_WIDTH:-66}"
}
_df_source_config
# ============================================================================
# Header
# ============================================================================
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-sync"
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local width="${DF_WIDTH:-66}"
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-sync${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
fi
df_print_header() { echo "=== $1 ==="; }
df_print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
df_print_error() { echo -e "${DF_RED}${DF_NC} $1" >&2; }
df_print_warning() { echo -e "${DF_YELLOW}${DF_NC} $1"; }
}
# ============================================================================
@@ -56,9 +21,6 @@ print_header() {
# ============================================================================
print_status() { echo -e "${DF_CYAN}${DF_NC} $1"; }
print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
print_error() { echo -e "${DF_RED}${DF_NC} $1" >&2; }
print_warning() { echo -e "${DF_YELLOW}${DF_NC} $1"; }
print_section() { echo ""; echo -e "${DF_BLUE}${DF_NC} $1"; }
# ============================================================================
@@ -66,7 +28,10 @@ print_section() { echo ""; echo -e "${DF_BLUE}▶${DF_NC} $1"; }
# ============================================================================
check_git_repo() {
git -C "$DOTFILES_HOME" rev-parse --git-dir > /dev/null 2>&1 || { print_error "Not a git repository: $DOTFILES_HOME"; exit 1; }
if ! git -C "$DOTFILES_HOME" rev-parse --git-dir > /dev/null 2>&1; then
df_print_error "Not a git repository: $DOTFILES_HOME"
exit 1
fi
}
get_sync_status() {
@@ -79,6 +44,7 @@ get_sync_status() {
show_status() {
print_section "Sync Status"
cd "$DOTFILES_HOME"
print_status "Local branch: $(git rev-parse --abbrev-ref HEAD)"
print_status "Last commit: $(git log -1 --pretty=format:'%h - %s' 2>/dev/null || echo 'N/A')"
@@ -87,9 +53,9 @@ show_status() {
local remote_commits="${status#*:}"
echo ""
[[ $local_commits -gt 0 ]] && print_warning "$local_commits commit(s) ahead of remote"
[[ $remote_commits -gt 0 ]] && print_warning "$remote_commits commit(s) behind remote"
[[ $local_commits -eq 0 && $remote_commits -eq 0 ]] && print_success "In sync with remote"
[[ $local_commits -gt 0 ]] && df_print_warning "$local_commits commit(s) ahead of remote"
[[ $remote_commits -gt 0 ]] && df_print_warning "$remote_commits commit(s) behind remote"
[[ $local_commits -eq 0 && $remote_commits -eq 0 ]] && df_print_success "In sync with remote"
}
show_status_short() {
@@ -111,9 +77,15 @@ show_status_short() {
pull_changes() {
print_section "Pulling Changes"
cd "$DOTFILES_HOME"
print_status "Fetching from remote..."
git fetch origin
git pull origin && print_success "Changes pulled" || print_success "Already up to date"
if git pull origin; then
df_print_success "Changes pulled"
else
df_print_success "Already up to date"
fi
}
push_changes() {
@@ -122,7 +94,7 @@ push_changes() {
cd "$DOTFILES_HOME"
if ! git status --porcelain | grep -q .; then
print_warning "No local changes to push"
df_print_warning "No local changes to push"
return
fi
@@ -131,12 +103,12 @@ push_changes() {
if [[ -z "$commit_msg" ]]; then
read -p "Commit message: " commit_msg
[[ -z "$commit_msg" ]] && { print_error "Commit cancelled"; return 1; }
[[ -z "$commit_msg" ]] && { df_print_error "Commit cancelled"; return 1; }
fi
git commit -m "$commit_msg"
git push origin
print_success "Changes pushed"
df_print_success "Changes pushed"
}
# ============================================================================
@@ -148,19 +120,40 @@ main() {
case "${1:-status}" in
status)
[[ "$2" == "-s" || "$2" == "--short" ]] && show_status_short || { print_header; show_status; }
if [[ "$2" == "-s" || "$2" == "--short" ]]; then
show_status_short
else
df_print_header "dotfiles-sync"
show_status
fi
;;
push)
print_header; shift; push_changes "$*"
df_print_header "dotfiles-sync"
shift
push_changes "$*"
;;
pull)
print_header; pull_changes
df_print_header "dotfiles-sync"
pull_changes
;;
-s|--short)
show_status_short
;;
--help|-h)
echo "Usage: dotfiles-sync.sh [COMMAND]"
echo ""
echo "Commands:"
echo " status [-s] Show sync status (default)"
echo " push [message] Push changes to remote"
echo " pull Pull changes from remote"
echo ""
echo "Options:"
echo " -s, --short Short status output"
echo " --help Show this help"
;;
*)
echo "Usage: $0 {status [-s]|push [message]|pull}"
echo "Unknown command: $1"
echo "Use --help for usage information"
exit 1
;;
esac

View File

@@ -5,6 +5,10 @@
set -e
# ============================================================================
# Parse Arguments First (before sourcing, in case we need --help)
# ============================================================================
SKIP_DEPS=true
PULL_ONLY=false
@@ -26,86 +30,50 @@ for arg in "$@"; do
esac
done
# Load Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOTFILES_CONF="${SCRIPT_DIR}/../dotfiles.conf"
[[ -f "$DOTFILES_CONF" ]] || DOTFILES_CONF="$HOME/.dotfiles/dotfiles.conf"
# ============================================================================
# Source Bootstrap
# ============================================================================
if [[ -f "$DOTFILES_CONF" ]]; then
source "$DOTFILES_CONF"
else
DOTFILES_DIR="$HOME/.dotfiles"
DOTFILES_BRANCH="main"
DOTFILES_RAW_URL="https://raw.githubusercontent.com/adlee-was-taken/dotfiles/main"
fi
# Source shared colors and utils (provides DF_WIDTH)
source "$DOTFILES_DIR/zsh/lib/utils.zsh" 2>/dev/null || \
source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.zsh" 2>/dev/null || {
DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m' DF_RED=$'\033[0;31m'
DF_BLUE=$'\033[0;34m' 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' DF_LIGHT_GREEN=$'\033[38;5;82m'
DF_CYAN=$'\033[0;36m' DF_NC=$'\033[0m'
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
df_print_header() { echo "=== $1 ==="; }
df_print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
df_print_error() { echo -e "${DF_RED}${DF_NC} $1" >&2; }
df_print_warning() { echo -e "${DF_YELLOW}${DF_NC} $1"; }
df_print_step() { echo -e "${DF_GREEN}==>${DF_NC} $1"; }
}
# Use DF_WIDTH from utils.zsh or default to 66
readonly WIDTH="${DF_WIDTH:-66}"
# ============================================================================
# MOTD-style header
# ============================================================================
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-update"
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local hline="" && for ((i=0; i<WIDTH; i++)); do hline+="═"; done
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-update${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
fi
}
print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
print_warning() { echo -e "${DF_YELLOW}${DF_NC} $1"; }
print_error() { echo -e "${DF_RED}${DF_NC} $1"; }
print_step() { echo -e "${DF_GREEN}==>${DF_NC} $1"; }
# ============================================================================
# Main
# ============================================================================
print_header
df_print_header "dotfiles-update"
if [ ! -d "$DOTFILES_DIR" ]; then
print_error "Dotfiles directory not found: $DOTFILES_DIR"
if [[ ! -d "$DOTFILES_HOME" ]]; then
df_print_error "Dotfiles directory not found: $DOTFILES_HOME"
exit 1
fi
cd "$DOTFILES_DIR"
cd "$DOTFILES_HOME"
print_step "Updating dotfiles from repository..."
git pull origin "$DOTFILES_BRANCH"
if [ $? -eq 0 ]; then
print_success "Dotfiles updated successfully"
df_print_step "Updating dotfiles from repository..."
if git pull origin "${DOTFILES_BRANCH:-main}"; then
df_print_success "Dotfiles updated successfully"
if [[ "$PULL_ONLY" == true ]]; then
echo
print_success "Pull complete (--pull-only mode)"
echo ""
df_print_success "Pull complete (--pull-only mode)"
exit 0
fi
echo
print_success "Update complete!"
echo ""
df_print_success "Update complete!"
echo -e "Reload your shell: ${DF_CYAN}reload${DF_NC} or ${DF_CYAN}source ~/.zshrc${DF_NC}"
else
print_error "Failed to update dotfiles"
df_print_error "Failed to update dotfiles"
exit 1
fi

View File

@@ -5,85 +5,133 @@
set -e
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
readonly VAULT_DIR="${HOME}/.dotfiles/vault"
readonly VAULT_FILE="${VAULT_DIR}/secrets.enc"
# Source shared colors and utils (provides DF_WIDTH)
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null || \
source "$DOTFILES_HOME/zsh/lib/colors.zsh" 2>/dev/null || {
# Source bootstrap
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.zsh" 2>/dev/null || {
DF_RED=$'\033[0;31m' DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m'
DF_BLUE=$'\033[0;34m' 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' DF_LIGHT_GREEN=$'\033[38;5;82m'
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
df_print_header() { echo "=== $1 ==="; }
df_print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
df_print_error() { echo -e "${DF_RED}${DF_NC} $1" >&2; }
}
# Use DF_WIDTH from utils.zsh or default to 66
readonly WIDTH="${DF_WIDTH:-66}"
# ============================================================================
# MOTD-style header
# Configuration
# ============================================================================
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-vault "
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local hline="" && for ((i=0; i<WIDTH; i++)); do hline+="═"; done
readonly VAULT_DIR="${DOTFILES_HOME}/vault"
readonly VAULT_FILE="${VAULT_DIR}/secrets.enc"
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-vault${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
fi
}
# ============================================================================
# Helper Functions
# ============================================================================
print_success() { echo -e "${DF_GREEN}${DF_NC} $1"; }
print_error() { echo -e "${DF_RED}${DF_NC} $1" >&2; }
print_section() { echo ""; echo -e "${DF_BLUE}${DF_NC} $1"; }
get_cipher() {
command -v age &> /dev/null && echo "age" || \
command -v gpg &> /dev/null && echo "gpg" || \
{ print_error "No encryption tool available"; exit 1; }
if command -v age &>/dev/null; then
echo "age"
elif command -v gpg &>/dev/null; then
echo "gpg"
else
df_print_error "No encryption tool available (install 'age' or 'gpg')"
exit 1
fi
}
# ============================================================================
# Vault Functions
# ============================================================================
init_vault() {
print_section "Initializing Vault"
mkdir -p "$VAULT_DIR"
chmod 700 "$VAULT_DIR"
[[ ! -f "$VAULT_FILE" ]] && { echo "{}" > "$VAULT_FILE"; print_success "Vault initialized"; } || print_success "Vault exists"
if [[ ! -f "$VAULT_FILE" ]]; then
echo "{}" > "$VAULT_FILE"
df_print_success "Vault initialized at $VAULT_DIR"
else
df_print_success "Vault already exists"
fi
}
vault_list() {
print_section "Secrets"
[[ -f "$VAULT_FILE" ]] && cat "$VAULT_FILE" | grep -o '"[^"]*":' | sed 's/"//g;s/:$//' | while read key; do
echo -e " ${DF_CYAN}${DF_NC} $key"
done || print_error "No vault file"
print_section "Stored Secrets"
if [[ ! -f "$VAULT_FILE" ]]; then
df_print_error "No vault file found. Run: vault init"
return 1
fi
local keys=$(cat "$VAULT_FILE" | grep -o '"[^"]*":' | sed 's/"//g;s/:$//')
if [[ -z "$keys" ]]; then
echo " (no secrets stored)"
else
echo "$keys" | while read key; do
echo -e " ${DF_CYAN}${DF_NC} $key"
done
fi
echo ""
}
vault_status() {
print_section "Vault Status"
[[ -d "$VAULT_DIR" ]] || { echo -e " ${DF_YELLOW}${DF_NC} Vault not initialized"; return; }
[[ -f "$VAULT_FILE" ]] || { echo -e " ${DF_YELLOW}${DF_NC} Vault file not found"; return; }
if [[ ! -d "$VAULT_DIR" ]]; then
echo -e " ${DF_YELLOW}${DF_NC} Vault not initialized"
echo " Run: vault init"
return
fi
if [[ ! -f "$VAULT_FILE" ]]; then
echo -e " ${DF_YELLOW}${DF_NC} Vault file not found"
return
fi
local cipher=$(get_cipher)
local key_count=$(cat "$VAULT_FILE" | grep -o '"[^"]*":' | wc -l)
echo -e " ${DF_CYAN}Location:${DF_NC} $VAULT_FILE"
echo -e " ${DF_CYAN}Encryption:${DF_NC} $(get_cipher)"
echo -e " ${DF_CYAN}Encryption:${DF_NC} $cipher"
echo -e " ${DF_CYAN}Secrets:${DF_NC} $key_count"
echo ""
}
show_help() {
echo "Usage: dotfiles-vault.sh [COMMAND]"
echo ""
echo "Commands:"
echo " init Initialize the vault"
echo " list, ls List all secret keys"
echo " status Show vault status"
echo " help Show this help"
echo ""
echo "The vault uses 'age' or 'gpg' for encryption."
}
# ============================================================================
# Main
# ============================================================================
main() {
print_header
df_print_header "dotfiles-vault"
# Auto-init if vault doesn't exist
[[ ! -d "$VAULT_DIR" ]] && init_vault
case "${1:-list}" in
init) init_vault ;;
list|ls) vault_list ;;
status) vault_status ;;
*) echo "Usage: $0 {init|list|status}"; exit 1 ;;
help|--help|-h) show_help ;;
*)
echo "Unknown command: $1"
show_help
exit 1
;;
esac
}

View File

@@ -4,74 +4,58 @@
# ============================================================================
# ============================================================================
# Source Configuration
# ============================================================================
_df_source_config() {
local locations=(
"${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/utils.zsh"
"$HOME/.dotfiles/zsh/lib/utils.zsh"
)
for loc in "${locations[@]}"; do
[[ -f "$loc" ]] && { source "$loc"; return 0; }
done
# Fallback defaults
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_LIGHT_GREEN=$'\033[38;5;82m'
DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
DOTFILES_VERSION="${DOTFILES_VERSION:-unknown}"
DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
DF_WIDTH="${DF_WIDTH:-66}"
}
_df_source_config
# ============================================================================
# Parse Arguments
# Parse Arguments First
# ============================================================================
CHECK_ONLY=false
for arg in "$@"; do
case "$arg" in
--check|-c) CHECK_ONLY=true ;;
--help|-h) echo "Usage: dotfiles-version.sh [--check]"; exit 0 ;;
--help|-h)
echo "Usage: dotfiles-version.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --check, -c Output version only (for scripts)"
echo " --help Show this help"
exit 0
;;
esac
done
# ============================================================================
# Header
# Source Bootstrap
# ============================================================================
print_header() {
if declare -f df_print_header &>/dev/null; then
df_print_header "dotfiles-version "
else
local user="${USER:-root}"
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
local datetime=$(date '+%a %b %d %H:%M')
local width="${DF_WIDTH:-66}"
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
echo ""
echo -e "${DF_GREY}${hline}${DF_NC}"
echo -e "${DF_GREY}${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-version${DF_NC} ${datetime} ${DF_GREY}${DF_NC}"
echo -e "${DF_GREY}${hline}${DF_NC}"
echo ""
fi
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.zsh" 2>/dev/null || {
DF_GREEN=$'\033[0;32m' DF_CYAN=$'\033[0;36m' DF_NC=$'\033[0m'
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
DOTFILES_VERSION="${DOTFILES_VERSION:-unknown}"
DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
DF_WIDTH="${DF_WIDTH:-66}"
df_print_header() { echo "=== $1 ==="; }
}
# ============================================================================
# Version Info
# Version Info Functions
# ============================================================================
get_local_commit() {
[[ -d "${DOTFILES_DIR}/.git" ]] && { cd "$DOTFILES_DIR"; git rev-parse --short HEAD 2>/dev/null || echo "unknown"; } || echo "not a git repo"
if [[ -d "${DOTFILES_HOME}/.git" ]]; then
cd "$DOTFILES_HOME"
git rev-parse --short HEAD 2>/dev/null || echo "unknown"
else
echo "not a git repo"
fi
}
get_local_date() {
[[ -d "${DOTFILES_DIR}/.git" ]] && { cd "$DOTFILES_DIR"; git log -1 --format="%ci" 2>/dev/null | cut -d' ' -f1 || echo "unknown"; } || echo "unknown"
if [[ -d "${DOTFILES_HOME}/.git" ]]; then
cd "$DOTFILES_HOME"
git log -1 --format="%ci" 2>/dev/null | cut -d' ' -f1 || echo "unknown"
else
echo "unknown"
fi
}
# ============================================================================
@@ -82,21 +66,23 @@ main() {
local local_commit=$(get_local_commit)
local local_date=$(get_local_date)
# Short output for scripts
if [[ "$CHECK_ONLY" == true ]]; then
echo "Version: $DOTFILES_VERSION ($local_commit)"
echo "Version: ${DOTFILES_VERSION} (${local_commit})"
exit 0
fi
print_header
# Full output
df_print_header "dotfiles-version"
echo -e "${DF_CYAN}Local:${DF_NC}"
echo -e " Version: ${DF_GREEN}${DOTFILES_VERSION}${DF_NC}"
echo -e " Commit: ${local_commit}"
echo -e " Date: ${local_date}"
echo -e " Path: ${DOTFILES_DIR}"
echo -e " Path: ${DOTFILES_HOME}"
echo -e " Branch: ${DOTFILES_BRANCH}"
echo -e " Width: ${DF_WIDTH}"
echo
echo ""
}
main "$@"