Dotfiles update 2025-12-25 11:21
This commit is contained in:
@@ -14,26 +14,28 @@
|
||||
# Only run in interactive shells
|
||||
[[ -o interactive ]] || return 0
|
||||
|
||||
# Source shared colors (with fallback)
|
||||
source "${0:A:h}/../lib/colors.zsh" 2>/dev/null || \
|
||||
source "$HOME/.dotfiles/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
# ============================================================================
|
||||
# Source Configuration
|
||||
# ============================================================================
|
||||
# utils.zsh sources config.zsh which sources dotfiles.conf
|
||||
# This gives us DF_WIDTH, MOTD_STYLE, colors, and all other settings
|
||||
|
||||
source "${0:A:h}/../lib/utils.zsh" 2>/dev/null || \
|
||||
source "$HOME/.dotfiles/zsh/lib/utils.zsh" 2>/dev/null || {
|
||||
# Fallback if utils.zsh not available
|
||||
typeset -g DF_RESET=$'\033[0m' DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m'
|
||||
typeset -g DF_BLUE=$'\033[38;5;39m' DF_CYAN=$'\033[38;5;51m'
|
||||
typeset -g DF_GREEN=$'\033[38;5;82m' DF_YELLOW=$'\033[38;5;220m'
|
||||
typeset -g DF_RED=$'\033[38;5;196m' DF_GREY=$'\033[38;5;242m' DF_NC=$'\033[0m'
|
||||
typeset -g DF_LIGHT_BLUE=$'\033[38;5;39m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
typeset -g DF_WIDTH="${DF_WIDTH:-66}"
|
||||
typeset -g MOTD_STYLE="${MOTD_STYLE:-compact}"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# MOTD Width
|
||||
# Optimized Info Gathering (using /proc directly)
|
||||
# ============================================================================
|
||||
|
||||
typeset -g _M_WIDTH=66
|
||||
|
||||
# ============================================================================
|
||||
# Optimized Info Gathering (using /proc directly - faster than spawning processes)
|
||||
# ============================================================================
|
||||
|
||||
# Uptime from /proc (no subprocess)
|
||||
_motd_uptime() {
|
||||
local uptime_seconds=$(cut -d. -f1 /proc/uptime 2>/dev/null)
|
||||
[[ -z "$uptime_seconds" ]] && { echo "?"; return; }
|
||||
@@ -51,87 +53,43 @@ _motd_uptime() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Load from /proc (no subprocess)
|
||||
_motd_load() {
|
||||
cut -d' ' -f1 /proc/loadavg 2>/dev/null || echo "?"
|
||||
}
|
||||
_motd_load() { cut -d' ' -f1 /proc/loadavg 2>/dev/null || echo "?"; }
|
||||
|
||||
# Memory from /proc (single awk call)
|
||||
_motd_mem() {
|
||||
awk '/MemTotal/ {total=$2} /MemAvailable/ {avail=$2} END {
|
||||
if (total > 0) {
|
||||
used=(total-avail)/1024/1024
|
||||
total_gb=total/1024/1024
|
||||
printf "%.1fG/%.0fG", used, total_gb
|
||||
} else {
|
||||
print "N/A"
|
||||
}
|
||||
} else { print "N/A" }
|
||||
}' /proc/meminfo 2>/dev/null || echo "N/A"
|
||||
}
|
||||
|
||||
# Disk usage (single df call)
|
||||
_motd_disk() {
|
||||
df -h / 2>/dev/null | awk 'NR==2 {print $3 "/" $2}' || echo "N/A"
|
||||
}
|
||||
_motd_disk() { df -h / 2>/dev/null | awk 'NR==2 {print $3 "/" $2}' || echo "N/A"; }
|
||||
|
||||
# CPU governor (Arch-specific, direct file read)
|
||||
_motd_governor() {
|
||||
local gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null)
|
||||
[[ -n "$gov" ]] && echo "$gov"
|
||||
}
|
||||
|
||||
# Kernel version (simplified)
|
||||
_motd_kernel() {
|
||||
local kernel=$(uname -r)
|
||||
# Strip architecture suffix for cleaner display
|
||||
echo "${kernel%%-*}"
|
||||
}
|
||||
|
||||
# CachyOS scheduler detection
|
||||
_motd_scheduler() {
|
||||
if grep -q "cachyos" /proc/version 2>/dev/null; then
|
||||
if grep -q "bore" /proc/version 2>/dev/null; then
|
||||
echo "BORE"
|
||||
elif grep -q "eevdf" /proc/version 2>/dev/null; then
|
||||
echo "EEVDF"
|
||||
else
|
||||
echo "CachyOS"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Failed systemd services count (cached)
|
||||
_motd_failed_services() {
|
||||
# Use cache to avoid slow systemctl calls on every prompt
|
||||
local cache_file="/tmp/.motd-failed-${UID}"
|
||||
local cache_age=300 # 5 minutes
|
||||
|
||||
local cache_age=300
|
||||
if [[ -f "$cache_file" ]]; then
|
||||
local file_age=$(($(date +%s) - $(stat -c %Y "$cache_file" 2>/dev/null || echo 0)))
|
||||
if (( file_age < cache_age )); then
|
||||
cat "$cache_file"
|
||||
return
|
||||
fi
|
||||
(( file_age < cache_age )) && { cat "$cache_file"; return; }
|
||||
fi
|
||||
|
||||
local count=$(systemctl --failed --no-pager --no-legend 2>/dev/null | wc -l)
|
||||
echo "$count" > "$cache_file" 2>/dev/null
|
||||
echo "$count"
|
||||
}
|
||||
|
||||
# Package updates (from environment, set by aliases.zsh)
|
||||
_motd_updates() {
|
||||
echo "${UPDATE_PKG_COUNT:-0}"
|
||||
}
|
||||
_motd_updates() { echo "${UPDATE_PKG_COUNT:-0}"; }
|
||||
|
||||
# ============================================================================
|
||||
# Box Drawing - Fixed Width
|
||||
# Box Drawing - Uses DF_WIDTH from config
|
||||
# ============================================================================
|
||||
|
||||
_motd_line() {
|
||||
local char="$1"
|
||||
local width="${DF_WIDTH:-66}"
|
||||
local line=""
|
||||
for ((i=0; i<_M_WIDTH; i++)); do line+="$char"; done
|
||||
for ((i=0; i<width; i++)); do line+="$char"; done
|
||||
echo "$line"
|
||||
}
|
||||
|
||||
@@ -143,6 +101,7 @@ show_motd() {
|
||||
[[ -n "$_MOTD_SHOWN" && "$1" != "--force" ]] && return 0
|
||||
typeset -g _MOTD_SHOWN=1
|
||||
|
||||
local width="${DF_WIDTH:-66}"
|
||||
local hostname="${HOST:-$(hostname -s 2>/dev/null)}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local uptime=$(_motd_uptime)
|
||||
@@ -150,54 +109,40 @@ show_motd() {
|
||||
local mem=$(_motd_mem)
|
||||
local disk=$(_motd_disk)
|
||||
local hline=$(_motd_line '═')
|
||||
local inner=$((_M_WIDTH - 2))
|
||||
local inner=$((width - 2))
|
||||
|
||||
echo ""
|
||||
|
||||
# Top border
|
||||
echo "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
|
||||
# Header: hostname + datetime
|
||||
local h_left="✦ ${hostname}"
|
||||
local h_center=$(hostname -i | awk -F" " '{print $1}')
|
||||
local h_center=$(hostname -i 2>/dev/null | awk -F" " '{print $1}')
|
||||
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
|
||||
|
||||
if [ "$EUID" -ne 0 ];then
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${h_left}${DF_NC}${h_spaces}${DF_YELLOW}${h_center}${h_spaces}${DF_NC}${DF_BOLD}${h_right}${DF_NC} ${DF_GREY}│${DF_NC}"
|
||||
else
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_RED}${h_left}${DF_NC}${h_spaces}${DF_YELLOW}${h_center}${h_spaces}${DF_NC}${DF_BOLD}${h_right}${DF_NC} ${DF_GREY}│${DF_NC}"
|
||||
fi
|
||||
# Separator
|
||||
|
||||
echo "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
|
||||
# Stats line
|
||||
local s1="${DF_GREY}「${DF_YELLOW}▲ ${DF_NC}${uptime}${DF_GREY}」"
|
||||
local s2="${DF_GREY}「${DF_CYAN}◆ ${DF_NC}${load}${DF_GREY}」"
|
||||
local s3="${DF_GREY}「${DF_GREEN}◇ ${DF_NC}${mem}${DF_GREY}」"
|
||||
local s4="${DF_GREY}「${DF_BLUE}⊡ ${DF_NC}${disk}${DF_GREY}」"
|
||||
echo " ${s1}─${s2}─${s3}─${s4}"
|
||||
local s3="${DF_GREY}「${DF_GREEN}▪ ${DF_NC}${mem}${DF_GREY}」"
|
||||
local s4="${DF_GREY}「${DF_BLUE}● ${DF_NC}${disk}${DF_GREY}」"
|
||||
|
||||
echo " ${s1} ${s2} ${s3} ${s4}"
|
||||
|
||||
# Alerts line (if any issues)
|
||||
local alerts=""
|
||||
|
||||
# Check for failed services
|
||||
local failed=$(_motd_failed_services)
|
||||
if (( failed > 0 )); then
|
||||
alerts+="${DF_RED}⚠ ${failed} failed service(s)${DF_NC} "
|
||||
# Failed services warning
|
||||
if [[ "${MOTD_SHOW_FAILED_SERVICES:-true}" == "true" ]]; then
|
||||
local failed=$(_motd_failed_services)
|
||||
(( failed > 0 )) && echo " ${DF_RED}⚠${DF_NC} ${failed} failed service(s)"
|
||||
fi
|
||||
|
||||
# Check for updates
|
||||
local updates=$(_motd_updates)
|
||||
if (( updates > 0 )); then
|
||||
alerts+="${DF_YELLOW}⇑ ${updates} update(s)${DF_NC}"
|
||||
fi
|
||||
|
||||
[[ -n "$alerts" ]] && echo " $alerts"
|
||||
|
||||
#echo ""
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -205,32 +150,10 @@ show_motd() {
|
||||
# ============================================================================
|
||||
|
||||
show_motd_mini() {
|
||||
[[ -n "$_MOTD_SHOWN" && "$1" != "--force" ]] && return 0
|
||||
typeset -g _MOTD_SHOWN=1
|
||||
|
||||
local hostname="${HOST:-$(hostname -s 2>/dev/null)}"
|
||||
local uptime=$(_motd_uptime)
|
||||
local mem=$(_motd_mem)
|
||||
local load=$(_motd_load)
|
||||
local disk=$(_motd_disk)
|
||||
local hline=$(_motd_line '═')
|
||||
local failed=$(_motd_failed_services)
|
||||
|
||||
local alert=""
|
||||
(( failed > 0 )) && alert=" ${DF_RED}[${failed} failed]${DF_NC}"
|
||||
|
||||
|
||||
# Stats line
|
||||
local s1="${DF_GREY}「${DF_YELLOW}▲ ${DF_NC}${uptime}${DF_GREY}」"
|
||||
local s2="${DF_GREY}「${DF_CYAN}◆ ${DF_NC}${load}${DF_GREY}」"
|
||||
local s3="${DF_GREY}「${DF_GREEN}◇ ${DF_NC}${mem}${DF_GREY}」"
|
||||
local s4="${DF_GREY}「${DF_BLUE}⊡ ${DF_NC}${disk}${DF_GREY}」"
|
||||
|
||||
if [ "$EUID" -ne 0 ];then
|
||||
echo "${DF_GREY}──${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}${hostname} ${DF_NC}${DF_GREY}─${DF_NC}${s1}─${s2}─${s3}─${s4}${DF_GREY}──${DF_NC}"
|
||||
else
|
||||
echo "${DF_GREY}──${DF_NC} ${DF_BOLD}${DF_RED}${hostname} ${DF_NC}${DF_GREY}─${DF_NC}${s1}─${s2}─${s3}─${s4}${DF_GREY}──${DF_NC}"
|
||||
fi
|
||||
echo "${DF_LIGHT_BLUE}${hostname}${DF_NC} │ up ${uptime} │ load ${load}"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -238,82 +161,41 @@ show_motd_mini() {
|
||||
# ============================================================================
|
||||
|
||||
show_motd_full() {
|
||||
[[ -n "$_MOTD_SHOWN" && "$1" != "--force" ]] && return 0
|
||||
typeset -g _MOTD_SHOWN=1
|
||||
|
||||
local hostname="${HOST:-$(hostname -s 2>/dev/null)}"
|
||||
local datetime=$(date '+%A, %B %d %Y %H:%M:%S')
|
||||
local uptime=$(_motd_uptime)
|
||||
local load=$(_motd_load)
|
||||
local mem=$(_motd_mem)
|
||||
local disk=$(_motd_disk)
|
||||
local kernel=$(_motd_kernel)
|
||||
local governor=$(_motd_governor)
|
||||
local scheduler=$(_motd_scheduler)
|
||||
local hline=$(_motd_line '═')
|
||||
|
||||
# echo ""
|
||||
echo "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_BLUE}✦ ${hostname}${DF_NC}"
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_DIM}${datetime}${DF_NC}"
|
||||
echo "${DF_GREY}├$(_motd_line '─')┤${DF_NC}"
|
||||
show_motd --force
|
||||
|
||||
# System info
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_CYAN}Kernel:${DF_NC} ${kernel}"
|
||||
[[ -n "$scheduler" ]] && echo "${DF_GREY}│${DF_NC} ${DF_CYAN}Scheduler:${DF_NC} ${scheduler}"
|
||||
[[ -n "$governor" ]] && echo "${DF_GREY}│${DF_NC} ${DF_CYAN}Governor:${DF_NC} ${governor}"
|
||||
local width="${DF_WIDTH:-66}"
|
||||
|
||||
echo "${DF_GREY}├$(_motd_line '─')┤${DF_NC}"
|
||||
echo "${DF_CYAN}System Details${DF_NC}"
|
||||
printf "${DF_GREY}─%.0s${DF_NC}" $(seq 1 $width); echo ""
|
||||
|
||||
# Resources
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_YELLOW}▲ Uptime:${DF_NC} ${uptime}"
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_CYAN}◆ Load:${DF_NC} ${load}"
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_GREEN}◇ Memory:${DF_NC} ${mem}"
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_BLUE}⊡ Disk:${DF_NC} ${disk}"
|
||||
echo " ${DF_DIM}Kernel:${DF_NC} $(uname -r)"
|
||||
echo " ${DF_DIM}Shell:${DF_NC} ${SHELL##*/} ${ZSH_VERSION:-}"
|
||||
|
||||
# Alerts section
|
||||
local failed=$(_motd_failed_services)
|
||||
local updates=$(_motd_updates)
|
||||
|
||||
if (( failed > 0 || updates > 0 )); then
|
||||
echo "${DF_GREY}├$(_motd_line '─')┤${DF_NC}"
|
||||
(( failed > 0 )) && echo "${DF_GREY}│${DF_NC} ${DF_RED}⚠ ${failed} failed systemd service(s)${DF_NC}"
|
||||
(( updates > 0 )) && echo "${DF_GREY}│${DF_NC} ${DF_YELLOW}⇑ ${updates} package update(s) available${DF_NC}"
|
||||
if [[ -f /etc/os-release ]]; then
|
||||
local distro=$(grep '^PRETTY_NAME=' /etc/os-release | cut -d'"' -f2)
|
||||
echo " ${DF_DIM}OS:${DF_NC} ${distro}"
|
||||
fi
|
||||
|
||||
echo "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
#echo ""
|
||||
if command -v pacman &>/dev/null; then
|
||||
local pkg_count=$(pacman -Q 2>/dev/null | wc -l)
|
||||
echo " ${DF_DIM}Packages:${DF_NC} ${pkg_count}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Aliases
|
||||
# Auto-display based on MOTD_STYLE from config
|
||||
# ============================================================================
|
||||
|
||||
alias motd='show_motd --force'
|
||||
alias motd-mini='show_motd_mini --force'
|
||||
alias motd-full='show_motd_full --force'
|
||||
|
||||
# ============================================================================
|
||||
# Quick System Overview (callable anytime)
|
||||
# ============================================================================
|
||||
|
||||
sysbrief() {
|
||||
echo -e "${DF_CYAN}Uptime:${DF_NC} $(_motd_uptime)"
|
||||
echo -e "${DF_CYAN}Load:${DF_NC} $(_motd_load)"
|
||||
echo -e "${DF_CYAN}Memory:${DF_NC} $(_motd_mem)"
|
||||
echo -e "${DF_CYAN}Disk:${DF_NC} $(_motd_disk)"
|
||||
|
||||
local kernel=$(_motd_kernel)
|
||||
echo -e "${DF_CYAN}Kernel:${DF_NC} ${kernel}"
|
||||
|
||||
local governor=$(_motd_governor)
|
||||
[[ -n "$governor" ]] && echo -e "${DF_CYAN}Governor:${DF_NC} ${governor}"
|
||||
|
||||
local scheduler=$(_motd_scheduler)
|
||||
[[ -n "$scheduler" ]] && echo -e "${DF_CYAN}Scheduler:${DF_NC} ${scheduler}"
|
||||
|
||||
local failed=$(_motd_failed_services)
|
||||
if (( failed > 0 )); then
|
||||
echo -e "${DF_RED}Failed:${DF_NC} ${failed} service(s)"
|
||||
fi
|
||||
_motd_auto() {
|
||||
case "${MOTD_STYLE:-compact}" in
|
||||
full) show_motd_full ;;
|
||||
mini) show_motd_mini ;;
|
||||
none|off|false) ;;
|
||||
*) show_motd ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run on source if ENABLE_MOTD is true
|
||||
[[ "${ENABLE_MOTD:-true}" == "true" ]] && _motd_auto
|
||||
|
||||
154
zsh/lib/config.zsh
Normal file
154
zsh/lib/config.zsh
Normal file
@@ -0,0 +1,154 @@
|
||||
# ============================================================================
|
||||
# Dotfiles Configuration Loader
|
||||
# ============================================================================
|
||||
# This file loads dotfiles.conf and sets up all configuration variables.
|
||||
# It serves as the bridge between dotfiles.conf and the rest of the system.
|
||||
#
|
||||
# Source this file to get access to all configuration:
|
||||
# source "${0:A:h}/config.zsh"
|
||||
#
|
||||
# This file:
|
||||
# 1. Finds and sources dotfiles.conf
|
||||
# 2. Sets sensible defaults for any missing values
|
||||
# 3. Exports variables for use in subshells/scripts
|
||||
# ============================================================================
|
||||
|
||||
# Prevent double-sourcing
|
||||
[[ -n "$_DF_CONFIG_LOADED" ]] && return 0
|
||||
|
||||
# ============================================================================
|
||||
# Find and Source dotfiles.conf
|
||||
# ============================================================================
|
||||
|
||||
_df_find_config() {
|
||||
local locations=(
|
||||
"${DOTFILES_DIR}/dotfiles.conf"
|
||||
"${DOTFILES_HOME}/dotfiles.conf"
|
||||
"$HOME/.dotfiles/dotfiles.conf"
|
||||
"${0:A:h}/../../dotfiles.conf"
|
||||
)
|
||||
|
||||
for loc in "${locations[@]}"; do
|
||||
[[ -f "$loc" ]] && { echo "$loc"; return 0; }
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
_DF_CONFIG_FILE=$(_df_find_config)
|
||||
|
||||
if [[ -n "$_DF_CONFIG_FILE" && -f "$_DF_CONFIG_FILE" ]]; then
|
||||
source "$_DF_CONFIG_FILE"
|
||||
typeset -g _DF_CONFIG_LOADED=1
|
||||
else
|
||||
# Config file not found - set critical defaults
|
||||
typeset -g _DF_CONFIG_LOADED=1
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Set Defaults for Any Missing Values
|
||||
# ============================================================================
|
||||
# These defaults ensure scripts work even if dotfiles.conf is incomplete
|
||||
|
||||
# Core Settings
|
||||
typeset -g DOTFILES_VERSION="${DOTFILES_VERSION:-1.0.0}"
|
||||
typeset -g DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
|
||||
typeset -g DOTFILES_HOME="${DOTFILES_HOME:-$DOTFILES_DIR}" # Alias for compatibility
|
||||
typeset -g DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
|
||||
typeset -g DOTFILES_BACKUP_PREFIX="${DOTFILES_BACKUP_PREFIX:-$HOME/.dotfiles_backup}"
|
||||
|
||||
# GitHub Settings
|
||||
typeset -g DOTFILES_GITHUB_USER="${DOTFILES_GITHUB_USER:-adlee-was-taken}"
|
||||
typeset -g DOTFILES_REPO_NAME="${DOTFILES_REPO_NAME:-dotfiles}"
|
||||
typeset -g DOTFILES_REPO_URL="${DOTFILES_REPO_URL:-https://github.com/${DOTFILES_GITHUB_USER}/${DOTFILES_REPO_NAME}.git}"
|
||||
typeset -g DOTFILES_RAW_URL="${DOTFILES_RAW_URL:-https://raw.githubusercontent.com/${DOTFILES_GITHUB_USER}/${DOTFILES_REPO_NAME}/${DOTFILES_BRANCH}}"
|
||||
|
||||
# Display Settings
|
||||
typeset -g DF_WIDTH="${DF_WIDTH:-66}"
|
||||
typeset -g ENABLE_MOTD="${ENABLE_MOTD:-true}"
|
||||
typeset -g MOTD_STYLE="${MOTD_STYLE:-compact}"
|
||||
typeset -g MOTD_SHOW_FAILED_SERVICES="${MOTD_SHOW_FAILED_SERVICES:-true}"
|
||||
typeset -g MOTD_SHOW_UPDATES="${MOTD_SHOW_UPDATES:-true}"
|
||||
|
||||
# Theme Settings
|
||||
typeset -g ZSH_THEME_NAME="${ZSH_THEME_NAME:-adlee}"
|
||||
typeset -g THEME_TIMER_THRESHOLD="${THEME_TIMER_THRESHOLD:-10}"
|
||||
typeset -g THEME_PATH_TRUNCATE_LENGTH="${THEME_PATH_TRUNCATE_LENGTH:-32}"
|
||||
|
||||
# Feature Toggles
|
||||
typeset -g ENABLE_SMART_SUGGESTIONS="${ENABLE_SMART_SUGGESTIONS:-true}"
|
||||
typeset -g ENABLE_COMMAND_PALETTE="${ENABLE_COMMAND_PALETTE:-true}"
|
||||
typeset -g ENABLE_SHELL_ANALYTICS="${ENABLE_SHELL_ANALYTICS:-false}"
|
||||
typeset -g ENABLE_VAULT="${ENABLE_VAULT:-true}"
|
||||
typeset -g DOTFILES_AUTO_SYNC_CHECK="${DOTFILES_AUTO_SYNC_CHECK:-true}"
|
||||
|
||||
# Btrfs Settings
|
||||
typeset -g BTRFS_DEFAULT_MOUNT="${BTRFS_DEFAULT_MOUNT:-/}"
|
||||
|
||||
# Snapper Settings
|
||||
typeset -g SNAPPER_CONFIG="${SNAPPER_CONFIG:-root}"
|
||||
typeset -g LIMINE_CONF="${LIMINE_CONF:-/boot/limine.conf}"
|
||||
|
||||
# Tmux Settings
|
||||
typeset -g TW_SESSION_PREFIX="${TW_SESSION_PREFIX:-work}"
|
||||
typeset -g TW_DEFAULT_TEMPLATE="${TW_DEFAULT_TEMPLATE:-dev}"
|
||||
|
||||
# Python Template Settings
|
||||
typeset -g PY_TEMPLATE_BASE_DIR="${PY_TEMPLATE_BASE_DIR:-$HOME/projects}"
|
||||
typeset -g PY_TEMPLATE_PYTHON="${PY_TEMPLATE_PYTHON:-python3}"
|
||||
typeset -g PY_TEMPLATE_VENV_NAME="${PY_TEMPLATE_VENV_NAME:-venv}"
|
||||
typeset -g PY_TEMPLATE_USE_POETRY="${PY_TEMPLATE_USE_POETRY:-false}"
|
||||
typeset -g PY_TEMPLATE_GIT_INIT="${PY_TEMPLATE_GIT_INIT:-true}"
|
||||
|
||||
# SSH Settings
|
||||
typeset -g SSH_AUTO_TMUX="${SSH_AUTO_TMUX:-true}"
|
||||
typeset -g SSH_TMUX_SESSION_PREFIX="${SSH_TMUX_SESSION_PREFIX:-ssh}"
|
||||
typeset -g SSH_SYNC_DOTFILES="${SSH_SYNC_DOTFILES:-ask}"
|
||||
|
||||
# Password Manager Settings
|
||||
typeset -g PW_CLIP_TIME="${PW_CLIP_TIME:-45}"
|
||||
|
||||
# Package Manager
|
||||
typeset -g AUR_HELPER="${AUR_HELPER:-auto}"
|
||||
|
||||
# Git Settings (with fallbacks to user identity)
|
||||
typeset -g GIT_USER_NAME="${GIT_USER_NAME:-$USER_FULLNAME}"
|
||||
typeset -g GIT_USER_EMAIL="${GIT_USER_EMAIL:-$USER_EMAIL}"
|
||||
typeset -g GIT_DEFAULT_BRANCH="${GIT_DEFAULT_BRANCH:-main}"
|
||||
|
||||
# ============================================================================
|
||||
# Export for Bash Scripts
|
||||
# ============================================================================
|
||||
# Bash scripts can't see typeset -g, so we export key variables
|
||||
|
||||
export DOTFILES_VERSION DOTFILES_DIR DOTFILES_HOME DOTFILES_BRANCH
|
||||
export DOTFILES_GITHUB_USER DOTFILES_REPO_NAME DOTFILES_REPO_URL DOTFILES_RAW_URL
|
||||
export DF_WIDTH MOTD_STYLE
|
||||
export ZSH_THEME_NAME
|
||||
|
||||
# ============================================================================
|
||||
# Helper Function: Get Config Value
|
||||
# ============================================================================
|
||||
# Usage: df_config "VARIABLE_NAME" "default_value"
|
||||
|
||||
df_config() {
|
||||
local var_name="$1"
|
||||
local default="$2"
|
||||
local value="${(P)var_name}"
|
||||
echo "${value:-$default}"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Helper Function: Show Config Summary
|
||||
# ============================================================================
|
||||
|
||||
df_show_config() {
|
||||
echo "Dotfiles Configuration"
|
||||
echo "======================"
|
||||
echo "Config File: ${_DF_CONFIG_FILE:-not found}"
|
||||
echo "Version: $DOTFILES_VERSION"
|
||||
echo "Directory: $DOTFILES_DIR"
|
||||
echo "Branch: $DOTFILES_BRANCH"
|
||||
echo "Display Width: $DF_WIDTH"
|
||||
echo "MOTD Style: $MOTD_STYLE"
|
||||
echo "Theme: $ZSH_THEME_NAME"
|
||||
}
|
||||
@@ -1,89 +1,86 @@
|
||||
# ============================================================================
|
||||
# Shared Utility Functions for Zsh Dotfiles
|
||||
# ============================================================================
|
||||
# Common helper functions used across multiple function files
|
||||
# Note: colors.zsh provides: DF_* color variables and df_print_func_name
|
||||
# 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.
|
||||
#
|
||||
# Source this file in function files:
|
||||
# source "${0:A:h}/../lib/utils.zsh"
|
||||
# ============================================================================
|
||||
|
||||
# Ensure colors are loaded first (provides DF_* vars and df_print_func_name)
|
||||
source "${0:A:h}/colors.zsh" 2>/dev/null || \
|
||||
source "$HOME/.dotfiles/zsh/lib/colors.zsh" 2>/dev/null
|
||||
# Prevent double-sourcing
|
||||
[[ -n "$_DF_UTILS_LOADED" ]] && return 0
|
||||
typeset -g _DF_UTILS_LOADED=1
|
||||
|
||||
# ============================================================================
|
||||
# Common Print Functions
|
||||
# Source Configuration and Colors
|
||||
# ============================================================================
|
||||
# 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 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'
|
||||
}
|
||||
|
||||
unset _df_lib_dir
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-Style Header Functions
|
||||
# ============================================================================
|
||||
|
||||
# Print a step/section header
|
||||
df_print_step() {
|
||||
echo -e "${DF_GREEN}==>${DF_NC} $1"
|
||||
# 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}"
|
||||
}
|
||||
|
||||
# Print success message
|
||||
df_print_success() {
|
||||
echo -e "${DF_GREEN}✓${DF_NC} $1"
|
||||
}
|
||||
|
||||
# Print error message (to stderr)
|
||||
df_print_error() {
|
||||
echo -e "${DF_RED}✗${DF_NC} $1" >&2
|
||||
}
|
||||
|
||||
# Print warning message
|
||||
df_print_warning() {
|
||||
echo -e "${DF_YELLOW}⚠${DF_NC} $1"
|
||||
}
|
||||
|
||||
# Print info message
|
||||
df_print_info() {
|
||||
echo -e "${DF_CYAN}ℹ${DF_NC} $1"
|
||||
}
|
||||
|
||||
# Print a section divider
|
||||
df_print_section() {
|
||||
echo ""
|
||||
echo -e "${DF_BLUE}▶${DF_NC} $1"
|
||||
echo -e "${DF_CYAN}─────────────────────────────────────────────────────────────${DF_NC}"
|
||||
}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-Style Header/Function Header
|
||||
# ============================================================================
|
||||
|
||||
# Prints a standardized header box for scripts
|
||||
# Usage: df_print_header "script-name"
|
||||
# Usage: df_print_func_name "func-name"
|
||||
|
||||
df_print_func_name() {
|
||||
local func_name="${1:-func}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local 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}"
|
||||
}
|
||||
|
||||
# Prints a standardized header box for scripts
|
||||
# Usage: df_print_header "script-name"
|
||||
df_print_header() {
|
||||
local script_name="${1:-script}"
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOST:-${HOSTNAME:-$(hostname -s 2>/dev/null)}}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local width=66
|
||||
local width="${DF_WIDTH:-66}"
|
||||
|
||||
# Build horizontal line
|
||||
local hline=""
|
||||
@@ -104,40 +101,25 @@ df_print_header() {
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Output Formatting Functions
|
||||
# ============================================================================
|
||||
|
||||
# Print a step/action indicator (blue arrow)
|
||||
df_print_step() { echo -e "${DF_BLUE}==>${DF_NC} $1"; }
|
||||
|
||||
# Print a success message (green checkmark)
|
||||
df_print_success() { echo -e "${DF_GREEN}✓${DF_NC} $1"; }
|
||||
|
||||
# Print an error message (red X)
|
||||
df_print_error() { echo -e "${DF_RED}✗${DF_NC} $1"; }
|
||||
|
||||
# Print a warning message (yellow warning sign)
|
||||
df_print_error() { echo -e "${DF_RED}✗${DF_NC} $1" >&2; }
|
||||
df_print_warning() { echo -e "${DF_YELLOW}⚠${DF_NC} $1"; }
|
||||
|
||||
# Print an info message (cyan info icon)
|
||||
df_print_info() { echo -e "${DF_CYAN}ℹ${DF_NC} $1"; }
|
||||
|
||||
# Print a section header (cyan label)
|
||||
df_print_section() { echo -e "${DF_CYAN}$1:${DF_NC}"; }
|
||||
|
||||
# Print indented content
|
||||
df_print_indent() { echo " $1"; }
|
||||
|
||||
# ============================================================================
|
||||
# Command Dependency Checking
|
||||
# ============================================================================
|
||||
|
||||
# Check if a command exists
|
||||
df_cmd_exists() { command -v "$1" &>/dev/null; }
|
||||
|
||||
# Require a command, show install hint if missing
|
||||
df_require_cmd() {
|
||||
local cmd="$1"
|
||||
local package="${2:-$1}"
|
||||
@@ -154,7 +136,6 @@ df_require_cmd() {
|
||||
# User Confirmation
|
||||
# ============================================================================
|
||||
|
||||
# Ask for yes/no confirmation (defaults to no)
|
||||
df_confirm() {
|
||||
local prompt="$1"
|
||||
read -q "REPLY?$prompt [y/N]: "
|
||||
@@ -162,7 +143,6 @@ df_confirm() {
|
||||
[[ "$REPLY" =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
# Confirm with warning prefix
|
||||
df_confirm_warning() {
|
||||
df_print_warning "$1"
|
||||
df_confirm "Continue?"
|
||||
@@ -172,16 +152,10 @@ df_confirm_warning() {
|
||||
# File/Directory Helpers
|
||||
# ============================================================================
|
||||
|
||||
# Check if in a git repo
|
||||
df_in_git_repo() { git rev-parse --git-dir &>/dev/null 2>&1; }
|
||||
|
||||
# Get git root directory
|
||||
df_git_root() { git rev-parse --show-toplevel 2>/dev/null; }
|
||||
|
||||
# Ensure directory exists
|
||||
df_ensure_dir() { [[ ! -d "$1" ]] && mkdir -p "$1"; }
|
||||
|
||||
# Ensure file exists with optional default content
|
||||
df_ensure_file() {
|
||||
local file="$1" content="${2:-}"
|
||||
if [[ ! -f "$file" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user