Dotfiles update 2025-12-22 12:00
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
|
||||
set -e
|
||||
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-.}"
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
readonly DOTFILES_VERSION="3.0.0"
|
||||
|
||||
# Color codes
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[1;33m'
|
||||
readonly BLUE='\033[0;34m'
|
||||
readonly CYAN='\033[0;36m'
|
||||
readonly NC='\033[0m'
|
||||
# Source shared colors
|
||||
source "$DOTFILES_HOME/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
# Fallback if colors.zsh not found
|
||||
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'
|
||||
}
|
||||
|
||||
# Track results
|
||||
TOTAL_CHECKS=0
|
||||
@@ -26,39 +27,22 @@ WARNING_CHECKS=0
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
_M_WIDTH=66
|
||||
|
||||
print_header() {
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local script_name="dotfiles-doctor"
|
||||
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 -e "${_M_GREY}╒${hline}╕${_M_RESET}"
|
||||
echo -e "${_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 -e "${_M_GREY}╘${hline}╛${_M_RESET}"
|
||||
echo ""
|
||||
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=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_DIM}dotfiles-doctor${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -66,25 +50,25 @@ print_header() {
|
||||
# ============================================================================
|
||||
|
||||
print_section() {
|
||||
echo -e "\n${BLUE}▶${NC} $1"
|
||||
echo -e "\n${DF_BLUE}▶${DF_NC} $1"
|
||||
}
|
||||
|
||||
check_pass() {
|
||||
((PASSED_CHECKS++))
|
||||
((TOTAL_CHECKS++))
|
||||
echo -e " ${GREEN}✓${NC} $1"
|
||||
echo -e " ${DF_GREEN}✓${DF_NC} $1"
|
||||
}
|
||||
|
||||
check_fail() {
|
||||
((FAILED_CHECKS++))
|
||||
((TOTAL_CHECKS++))
|
||||
echo -e " ${RED}✗${NC} $1"
|
||||
echo -e " ${DF_RED}✗${DF_NC} $1"
|
||||
}
|
||||
|
||||
check_warn() {
|
||||
((WARNING_CHECKS++))
|
||||
((TOTAL_CHECKS++))
|
||||
echo -e " ${YELLOW}⚠${NC} $1"
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} $1"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -314,23 +298,23 @@ check_dotfiles_dir() {
|
||||
|
||||
print_summary() {
|
||||
echo ""
|
||||
printf "${CYAN}─%.0s${NC}" {1..70}; echo ""
|
||||
printf "${DF_CYAN}─%.0s${DF_NC}" {1..70}; echo ""
|
||||
|
||||
if [[ $FAILED_CHECKS -eq 0 ]]; then
|
||||
echo -e "${GREEN}✓${NC} All checks passed ($PASSED_CHECKS/$TOTAL_CHECKS)"
|
||||
echo -e "${DF_GREEN}✓${DF_NC} All checks passed ($PASSED_CHECKS/$TOTAL_CHECKS)"
|
||||
else
|
||||
echo -e "${RED}✗${NC} Some checks failed"
|
||||
echo -e " ${GREEN}Passed:${NC} $PASSED_CHECKS"
|
||||
echo -e " ${RED}Failed:${NC} $FAILED_CHECKS"
|
||||
echo -e "${DF_RED}✗${DF_NC} Some checks failed"
|
||||
echo -e " ${DF_GREEN}Passed:${DF_NC} $PASSED_CHECKS"
|
||||
echo -e " ${DF_RED}Failed:${DF_NC} $FAILED_CHECKS"
|
||||
if [[ $WARNING_CHECKS -gt 0 ]]; then
|
||||
echo -e " ${YELLOW}Warnings:${NC} $WARNING_CHECKS"
|
||||
echo -e " ${DF_YELLOW}Warnings:${DF_NC} $WARNING_CHECKS"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
if [[ $FAILED_CHECKS -gt 0 ]]; then
|
||||
echo -e "${YELLOW}💡 Tip:${NC} Run 'dotfiles-doctor.sh --fix' to attempt automatic fixes"
|
||||
echo -e "${DF_YELLOW}💡 Tip:${DF_NC} Run 'dotfiles-doctor.sh --fix' to attempt automatic fixes"
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -5,52 +5,36 @@
|
||||
|
||||
set -e
|
||||
|
||||
# Color codes
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[1;33m'
|
||||
readonly BLUE='\033[0;34m'
|
||||
readonly CYAN='\033[0;36m'
|
||||
readonly MAGENTA='\033[0;35m'
|
||||
readonly NC='\033[0m'
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
|
||||
# Source shared colors
|
||||
source "$DOTFILES_HOME/zsh/lib/colors.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'
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
_M_WIDTH=66
|
||||
|
||||
print_header() {
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local script_name="dotfiles-stats"
|
||||
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 -e "${_M_GREY}╒${hline}╕${_M_RESET}"
|
||||
echo -e "${_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 -e "${_M_GREY}╘${hline}╛${_M_RESET}"
|
||||
echo ""
|
||||
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 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_DIM}dotfiles-stats${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -59,8 +43,8 @@ print_header() {
|
||||
|
||||
print_section() {
|
||||
echo ""
|
||||
echo -e "${BLUE}▶${NC} $1"
|
||||
echo -e "${CYAN}─────────────────────────────────────────────────────────────${NC}"
|
||||
echo -e "${DF_BLUE}▶${DF_NC} $1"
|
||||
echo -e "${DF_CYAN}─────────────────────────────────────────────────────────────${DF_NC}"
|
||||
}
|
||||
|
||||
# Get command history
|
||||
@@ -83,8 +67,8 @@ show_dashboard() {
|
||||
local unique=$(get_history | sort | uniq | wc -l)
|
||||
|
||||
echo ""
|
||||
echo -e " ${CYAN}Total Commands:${NC} $total"
|
||||
echo -e " ${CYAN}Unique Commands:${NC} $unique"
|
||||
echo -e " ${DF_CYAN}Total Commands:${DF_NC} $total"
|
||||
echo -e " ${DF_CYAN}Unique Commands:${DF_NC} $unique"
|
||||
echo ""
|
||||
|
||||
print_section "Top 15 Commands"
|
||||
@@ -93,7 +77,7 @@ show_dashboard() {
|
||||
local percent=$((count * 100 / total))
|
||||
local bar_length=$((percent / 5))
|
||||
local bar=$(printf '█%.0s' $(seq 1 $bar_length))
|
||||
printf " %-20s ${GREEN}%5d${NC} ${MAGENTA}%3d%%${NC} ${bar}\n" "$cmd" "$count" "$percent"
|
||||
printf " %-20s ${DF_GREEN}%5d${DF_NC} ${DF_MAGENTA}%3d%%${DF_NC} ${bar}\n" "$cmd" "$count" "$percent"
|
||||
done
|
||||
|
||||
echo ""
|
||||
@@ -109,7 +93,7 @@ show_top_n() {
|
||||
get_history | awk '{print $1}' | sort | uniq -c | sort -rn | head -"$n" | \
|
||||
while read count cmd; do
|
||||
local percent=$((count * 100 / total))
|
||||
printf " ${YELLOW}%4d${NC} %-30s ${CYAN}%3d%%${NC}\n" "$count" "$cmd" "$percent"
|
||||
printf " ${DF_YELLOW}%4d${DF_NC} %-30s ${DF_CYAN}%3d%%${DF_NC}\n" "$count" "$cmd" "$percent"
|
||||
done
|
||||
|
||||
echo ""
|
||||
@@ -124,7 +108,7 @@ show_suggestions() {
|
||||
get_history | awk '{print $1}' | sort | uniq -c | sort -rn | head -20 | \
|
||||
while read count cmd; do
|
||||
if [[ $count -gt 50 ]]; then
|
||||
printf " ${YELLOW}Suggestion:${NC} ${GREEN}alias ${cmd:0:2}='$cmd'${NC} (used $count times)\n"
|
||||
printf " ${DF_YELLOW}Suggestion:${DF_NC} ${DF_GREEN}alias ${cmd:0:2}='$cmd'${DF_NC} (used $count times)\n"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -135,22 +119,22 @@ show_breakdown() {
|
||||
print_section "Command Breakdown"
|
||||
|
||||
echo ""
|
||||
echo -e " ${CYAN}Git Commands:${NC}"
|
||||
echo -e " ${DF_CYAN}Git Commands:${DF_NC}"
|
||||
get_history | grep "^git" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${CYAN}Navigation (cd):${NC}"
|
||||
echo -e " ${DF_CYAN}Navigation (cd):${DF_NC}"
|
||||
get_history | grep "^cd" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${CYAN}File Operations (ls):${NC}"
|
||||
echo -e " ${DF_CYAN}File Operations (ls):${DF_NC}"
|
||||
get_history | grep "^ls" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${CYAN}Package Management (pacman/paru/yay):${NC}"
|
||||
echo -e " ${DF_CYAN}Package Management (pacman/paru/yay):${DF_NC}"
|
||||
get_history | grep -E "^(pacman|paru|yay)" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${CYAN}Editing (vim/nvim):${NC}"
|
||||
echo -e " ${DF_CYAN}Editing (vim/nvim):${DF_NC}"
|
||||
get_history | grep -E "^(vim|nvim)" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${CYAN}Dotfiles Commands (dotfiles-):${NC}"
|
||||
echo -e " ${DF_CYAN}Dotfiles Commands (dotfiles-):${DF_NC}"
|
||||
get_history | grep "^dotfiles-" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo ""
|
||||
@@ -161,15 +145,14 @@ show_heatmap() {
|
||||
|
||||
echo ""
|
||||
if [[ -f "$HOME/.zsh_history" ]]; then
|
||||
# Extract hour from zsh history timestamp
|
||||
grep "^:" "$HOME/.zsh_history" | awk -F'[: ]' '{print $2}' | \
|
||||
date -f - "+%H" 2>/dev/null | sort | uniq -c | sort -k2n | while read count hour; do
|
||||
local bar_length=$((count / 5))
|
||||
local bar=$(printf '█%.0s' $(seq 1 $bar_length))
|
||||
printf " ${CYAN}%02d:00${NC} ${MAGENTA}%5d${NC} ${GREEN}${bar}${NC}\n" "$hour" "$count"
|
||||
printf " ${DF_CYAN}%02d:00${DF_NC} ${DF_MAGENTA}%5d${DF_NC} ${DF_GREEN}${bar}${DF_NC}\n" "$hour" "$count"
|
||||
done
|
||||
else
|
||||
echo " ${YELLOW}⚠${NC} Zsh history file required for hourly breakdown"
|
||||
echo " ${DF_YELLOW}⚠${DF_NC} Zsh history file required for hourly breakdown"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -182,10 +165,10 @@ show_dirs() {
|
||||
if [[ -f "$HOME/.zsh_history" ]]; then
|
||||
grep "cd " "$HOME/.zsh_history" | awk '{print $NF}' | sort | uniq -c | \
|
||||
sort -rn | head -15 | while read count dir; do
|
||||
printf " ${CYAN}%4d${NC} ${YELLOW}%s${NC}\n" "$count" "$dir"
|
||||
printf " ${DF_CYAN}%4d${DF_NC} ${DF_YELLOW}%s${DF_NC}\n" "$count" "$dir"
|
||||
done
|
||||
else
|
||||
echo " ${YELLOW}⚠${NC} Zsh history file required"
|
||||
echo " ${DF_YELLOW}⚠${DF_NC} Zsh history file required"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
@@ -198,14 +181,14 @@ show_git_breakdown() {
|
||||
local total=$(get_history | grep "^git" | wc -l)
|
||||
|
||||
if [[ $total -eq 0 ]]; then
|
||||
echo " ${YELLOW}No git commands found${NC}"
|
||||
echo " ${DF_YELLOW}No git commands found${DF_NC}"
|
||||
return
|
||||
fi
|
||||
|
||||
get_history | grep "^git " | awk '{print $2}' | sort | uniq -c | sort -rn | \
|
||||
head -10 | while read count subcmd; do
|
||||
local percent=$((count * 100 / total))
|
||||
printf " ${YELLOW}git %-15s${NC} ${CYAN}%4d${NC} (${MAGENTA}%3d%%${NC})\n" \
|
||||
printf " ${DF_YELLOW}git %-15s${DF_NC} ${DF_CYAN}%4d${DF_NC} (${DF_MAGENTA}%3d%%${DF_NC})\n" \
|
||||
"$subcmd" "$count" "$percent"
|
||||
done
|
||||
|
||||
@@ -242,7 +225,6 @@ main() {
|
||||
show_git_breakdown
|
||||
;;
|
||||
export)
|
||||
# Export as JSON
|
||||
echo "{"
|
||||
echo " \"total_commands\": $(get_history | wc -l),"
|
||||
echo " \"unique_commands\": $(get_history | sort | uniq | wc -l),"
|
||||
|
||||
@@ -2,57 +2,31 @@
|
||||
# ============================================================================
|
||||
# Update Dotfiles Script
|
||||
# ============================================================================
|
||||
# Updates dotfiles from the git repository and relinks files
|
||||
#
|
||||
# Usage:
|
||||
# dotfiles-update.sh # Pull and re-run install
|
||||
# dotfiles-update.sh --skip-deps # Pull and re-run install without deps
|
||||
# dotfiles-update.sh --pull-only # Only git pull, don't re-run install
|
||||
#
|
||||
# Aliases: dfu, dfupdate
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# ============================================================================
|
||||
# Options
|
||||
# ============================================================================
|
||||
|
||||
SKIP_DEPS=true # Default to skipping deps on updates
|
||||
SKIP_DEPS=true
|
||||
PULL_ONLY=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--skip-deps)
|
||||
SKIP_DEPS=true
|
||||
;;
|
||||
--with-deps)
|
||||
SKIP_DEPS=false
|
||||
;;
|
||||
--pull-only)
|
||||
PULL_ONLY=true
|
||||
;;
|
||||
--skip-deps) SKIP_DEPS=true ;;
|
||||
--with-deps) SKIP_DEPS=false ;;
|
||||
--pull-only) PULL_ONLY=true ;;
|
||||
--help|-h)
|
||||
echo "Usage: dotfiles-update.sh [OPTIONS]"
|
||||
echo
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --skip-deps Skip dependency check (default for updates)"
|
||||
echo " --with-deps Run full dependency check"
|
||||
echo " --pull-only Only git pull, don't re-run install script"
|
||||
echo " --help Show this help message"
|
||||
echo
|
||||
echo "Aliases:"
|
||||
echo " dfu, dfupdate Update dotfiles"
|
||||
echo
|
||||
exit 0
|
||||
;;
|
||||
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"
|
||||
@@ -60,78 +34,55 @@ DOTFILES_CONF="${SCRIPT_DIR}/../dotfiles.conf"
|
||||
if [[ -f "$DOTFILES_CONF" ]]; then
|
||||
source "$DOTFILES_CONF"
|
||||
else
|
||||
# Fallback defaults
|
||||
DOTFILES_DIR="$HOME/.dotfiles"
|
||||
DOTFILES_BRANCH="main"
|
||||
DOTFILES_GITHUB_USER="adlee-was-taken"
|
||||
DOTFILES_REPO_NAME="dotfiles"
|
||||
DOTFILES_RAW_URL="https://raw.githubusercontent.com/${DOTFILES_GITHUB_USER}/${DOTFILES_REPO_NAME}/${DOTFILES_BRANCH}"
|
||||
DOTFILES_RAW_URL="https://raw.githubusercontent.com/adlee-was-taken/dotfiles/main"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Colors
|
||||
# ============================================================================
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
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_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'
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
_M_WIDTH=66
|
||||
|
||||
print_header() {
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local script_name="dotfiles-update"
|
||||
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 -e "${_M_GREY}╒${hline}╕${_M_RESET}"
|
||||
echo -e "${_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 -e "${_M_GREY}╘${hline}╛${_M_RESET}"
|
||||
echo ""
|
||||
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 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_DIM}dotfiles-update${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✓${NC} $1"
|
||||
echo -e "${DF_GREEN}✓${DF_NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠${NC} $1"
|
||||
echo -e "${DF_YELLOW}⚠${DF_NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}✗${NC} $1"
|
||||
echo -e "${DF_RED}✗${DF_NC} $1"
|
||||
}
|
||||
|
||||
print_step() {
|
||||
echo -e "${GREEN}==>${NC} $1"
|
||||
echo -e "${DF_GREEN}==>${DF_NC} $1"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -178,7 +129,7 @@ if [ $? -eq 0 ]; then
|
||||
|
||||
echo
|
||||
print_success "Update complete!"
|
||||
echo -e "Reload your shell: ${CYAN}reload${NC} or ${CYAN}source ~/.zshrc${NC}"
|
||||
echo -e "Reload your shell: ${DF_CYAN}reload${DF_NC} or ${DF_CYAN}source ~/.zshrc${DF_NC}"
|
||||
else
|
||||
print_error "Failed to update dotfiles"
|
||||
exit 1
|
||||
|
||||
@@ -5,54 +5,38 @@
|
||||
|
||||
set -e
|
||||
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
readonly VAULT_DIR="${HOME}/.dotfiles/vault"
|
||||
readonly VAULT_FILE="${VAULT_DIR}/secrets.enc"
|
||||
|
||||
# Color codes
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[1;33m'
|
||||
readonly BLUE='\033[0;34m'
|
||||
readonly CYAN='\033[0;36m'
|
||||
readonly NC='\033[0m'
|
||||
# Source shared colors
|
||||
source "$DOTFILES_HOME/zsh/lib/colors.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'
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
_M_WIDTH=66
|
||||
|
||||
print_header() {
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local script_name="dotfiles-vault"
|
||||
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 -e "${_M_GREY}╒${hline}╕${_M_RESET}"
|
||||
echo -e "${_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 -e "${_M_GREY}╘${hline}╛${_M_RESET}"
|
||||
echo ""
|
||||
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 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_DIM}dotfiles-vault${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -60,16 +44,16 @@ print_header() {
|
||||
# ============================================================================
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✓${NC} $1"
|
||||
echo -e "${DF_GREEN}✓${DF_NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}✗${NC} $1" >&2
|
||||
echo -e "${DF_RED}✗${DF_NC} $1" >&2
|
||||
}
|
||||
|
||||
print_section() {
|
||||
echo ""
|
||||
echo -e "${BLUE}▶${NC} $1"
|
||||
echo -e "${DF_BLUE}▶${DF_NC} $1"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -94,7 +78,6 @@ init_vault() {
|
||||
chmod 700 "$VAULT_DIR"
|
||||
|
||||
if [[ ! -f "$VAULT_FILE" ]]; then
|
||||
# Create empty encrypted file
|
||||
echo "{}" | $(get_cipher) > "$VAULT_FILE"
|
||||
print_success "Vault initialized"
|
||||
else
|
||||
@@ -147,24 +130,19 @@ vault_set() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get value from stdin if not provided
|
||||
if [[ -z "$value" ]]; then
|
||||
read -s -p "Enter value for $key: " value
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Decrypt current vault
|
||||
local current=$(decrypt_vault)
|
||||
|
||||
# Add new key-value pair (using jq if available, otherwise simple replacement)
|
||||
if command -v jq &> /dev/null; then
|
||||
local updated=$(echo "$current" | jq --arg k "$key" --arg v "$value" '.[$k] = $v')
|
||||
else
|
||||
# Simple fallback without jq
|
||||
local updated="{\"$key\": \"$value\"}"
|
||||
fi
|
||||
|
||||
# Encrypt and save
|
||||
encrypt_vault "$updated"
|
||||
print_success "Secret stored: $key"
|
||||
}
|
||||
@@ -182,7 +160,6 @@ vault_get() {
|
||||
if command -v jq &> /dev/null; then
|
||||
echo "$vault" | jq -r ".\"$key\" // \"\"" | grep -v "^$"
|
||||
else
|
||||
# Simple grep fallback
|
||||
echo "$vault" | grep "\"$key\"" | cut -d'"' -f4
|
||||
fi
|
||||
}
|
||||
@@ -194,12 +171,11 @@ vault_list() {
|
||||
|
||||
if command -v jq &> /dev/null; then
|
||||
echo "$vault" | jq -r 'keys[]' | while read key; do
|
||||
echo -e " ${CYAN}•${NC} $key"
|
||||
echo -e " ${DF_CYAN}•${DF_NC} $key"
|
||||
done
|
||||
else
|
||||
# Simple fallback
|
||||
echo "$vault" | grep -o '"[^"]*":' | sed 's/"//g' | sed 's/:$//' | while read key; do
|
||||
echo -e " ${CYAN}•${NC} $key"
|
||||
echo -e " ${DF_CYAN}•${DF_NC} $key"
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -280,23 +256,23 @@ vault_status() {
|
||||
print_section "Vault Status"
|
||||
|
||||
if [[ ! -d "$VAULT_DIR" ]]; then
|
||||
echo -e " ${YELLOW}⚠${NC} Vault not initialized"
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Vault not initialized"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ ! -f "$VAULT_FILE" ]]; then
|
||||
echo -e " ${YELLOW}⚠${NC} Vault file not found"
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Vault file not found"
|
||||
return
|
||||
fi
|
||||
|
||||
local size=$(du -h "$VAULT_FILE" | cut -f1)
|
||||
local modified=$(stat -c %y "$VAULT_FILE" 2>/dev/null | cut -d' ' -f1 || stat -f '%Sm' "$VAULT_FILE" 2>/dev/null)
|
||||
|
||||
echo -e " ${CYAN}Location:${NC} $VAULT_FILE"
|
||||
echo -e " ${CYAN}Size:${NC} $size"
|
||||
echo -e " ${CYAN}Modified:${NC} $modified"
|
||||
echo -e " ${CYAN}Encryption:${NC} $(get_cipher)"
|
||||
echo -e " ${CYAN}Permissions:${NC} $(stat -c '%a' $VAULT_FILE 2>/dev/null || stat -f '%a' "$VAULT_FILE")"
|
||||
echo -e " ${DF_CYAN}Location:${DF_NC} $VAULT_FILE"
|
||||
echo -e " ${DF_CYAN}Size:${DF_NC} $size"
|
||||
echo -e " ${DF_CYAN}Modified:${DF_NC} $modified"
|
||||
echo -e " ${DF_CYAN}Encryption:${DF_NC} $(get_cipher)"
|
||||
echo -e " ${DF_CYAN}Permissions:${DF_NC} $(stat -c '%a' $VAULT_FILE 2>/dev/null || stat -f '%a' "$VAULT_FILE")"
|
||||
|
||||
echo ""
|
||||
}
|
||||
@@ -308,7 +284,6 @@ vault_status() {
|
||||
main() {
|
||||
print_header
|
||||
|
||||
# Initialize vault if not exists
|
||||
if [[ ! -d "$VAULT_DIR" ]]; then
|
||||
init_vault
|
||||
fi
|
||||
|
||||
@@ -2,17 +2,8 @@
|
||||
# ============================================================================
|
||||
# Dotfiles Version Checker
|
||||
# ============================================================================
|
||||
# Shows current and remote version info
|
||||
#
|
||||
# Usage:
|
||||
# dotfiles-version.sh # Show version info
|
||||
# dotfiles-version.sh --check # Check for updates (exit 1 if behind)
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# Load Configuration
|
||||
# ============================================================================
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DOTFILES_CONF="${SCRIPT_DIR}/../dotfiles.conf"
|
||||
[[ -f "$DOTFILES_CONF" ]] || DOTFILES_CONF="${SCRIPT_DIR}/dotfiles.conf"
|
||||
@@ -27,82 +18,51 @@ else
|
||||
DOTFILES_RAW_URL="https://raw.githubusercontent.com/adlee-was-taken/dotfiles/main"
|
||||
fi
|
||||
|
||||
# ============================================================================
|
||||
# Colors
|
||||
# ============================================================================
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
_M_WIDTH=66
|
||||
|
||||
print_header() {
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local script_name="dotfiles-version"
|
||||
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 -e "${_M_GREY}╒${hline}╕${_M_RESET}"
|
||||
echo -e "${_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 -e "${_M_GREY}╘${hline}╛${_M_RESET}"
|
||||
echo ""
|
||||
# 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'
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Options
|
||||
# ============================================================================
|
||||
|
||||
CHECK_ONLY=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--check|-c)
|
||||
CHECK_ONLY=true
|
||||
;;
|
||||
--check|-c) CHECK_ONLY=true ;;
|
||||
--help|-h)
|
||||
echo "Usage: dotfiles-version.sh [OPTIONS]"
|
||||
echo
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --check Only check for updates (exit 1 if behind)"
|
||||
echo " --help Show this help message"
|
||||
echo
|
||||
echo "Aliases:"
|
||||
echo " dfv, dfversion Show version info"
|
||||
echo
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
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=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_DIM}dotfiles-version${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Functions
|
||||
# ============================================================================
|
||||
@@ -132,7 +92,6 @@ get_local_date() {
|
||||
}
|
||||
|
||||
get_remote_version() {
|
||||
# Try to get version from remote dotfiles.conf
|
||||
local remote_conf=$(curl -fsSL "${DOTFILES_RAW_URL}/dotfiles.conf" 2>/dev/null)
|
||||
if [[ -n "$remote_conf" ]]; then
|
||||
echo "$remote_conf" | grep -oP 'DOTFILES_VERSION="\K[^"]+' || echo "unknown"
|
||||
@@ -176,7 +135,6 @@ compare_versions() {
|
||||
if [[ "$local_v" == "$remote_v" ]]; then
|
||||
echo "current"
|
||||
else
|
||||
# Simple semver comparison
|
||||
local local_parts=(${local_v//./ })
|
||||
local remote_parts=(${remote_v//./ })
|
||||
|
||||
@@ -220,44 +178,44 @@ main() {
|
||||
|
||||
print_header
|
||||
|
||||
echo -e "${CYAN}Local:${NC}"
|
||||
echo -e " Version: ${GREEN}${local_version}${NC}"
|
||||
echo -e "${DF_CYAN}Local:${DF_NC}"
|
||||
echo -e " Version: ${DF_GREEN}${local_version}${DF_NC}"
|
||||
echo -e " Commit: ${local_commit}"
|
||||
echo -e " Date: ${local_date}"
|
||||
echo -e " Path: ${DOTFILES_DIR}"
|
||||
echo
|
||||
|
||||
echo -e "${CYAN}Remote:${NC}"
|
||||
echo -e "${DF_CYAN}Remote:${DF_NC}"
|
||||
echo -e " Version: ${remote_version}"
|
||||
echo -e " Commit: ${remote_commit}"
|
||||
echo -e " Branch: ${DOTFILES_BRANCH}"
|
||||
echo
|
||||
|
||||
echo -e "${CYAN}Status:${NC}"
|
||||
echo -e "${DF_CYAN}Status:${DF_NC}"
|
||||
|
||||
case "$version_status" in
|
||||
current)
|
||||
echo -e " Version: ${GREEN}✓ Up to date${NC}"
|
||||
echo -e " Version: ${DF_GREEN}✓ Up to date${DF_NC}"
|
||||
;;
|
||||
behind)
|
||||
echo -e " Version: ${YELLOW}⚠ New version available: ${remote_version}${NC}"
|
||||
echo -e " Version: ${DF_YELLOW}⚠ New version available: ${remote_version}${DF_NC}"
|
||||
;;
|
||||
ahead)
|
||||
echo -e " Version: ${CYAN}ℹ Local is ahead of remote${NC}"
|
||||
echo -e " Version: ${DF_CYAN}ℹ Local is ahead of remote${DF_NC}"
|
||||
;;
|
||||
*)
|
||||
echo -e " Version: ${YELLOW}? Cannot determine${NC}"
|
||||
echo -e " Version: ${DF_YELLOW}? Cannot determine${DF_NC}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$commits_behind" -gt 0 ]]; then
|
||||
echo -e " Commits: ${YELLOW}⚠ ${commits_behind} commit(s) behind${NC}"
|
||||
echo -e " Commits: ${DF_YELLOW}⚠ ${commits_behind} commit(s) behind${DF_NC}"
|
||||
echo
|
||||
echo -e "${YELLOW}To update:${NC}"
|
||||
echo -e "${DF_YELLOW}To update:${DF_NC}"
|
||||
echo " dfu # Alias"
|
||||
echo " dotfiles-update.sh # Full command"
|
||||
elif [[ "$commits_behind" == "0" ]]; then
|
||||
echo -e " Commits: ${GREEN}✓ Up to date${NC}"
|
||||
echo -e " Commits: ${DF_GREEN}✓ Up to date${DF_NC}"
|
||||
fi
|
||||
|
||||
echo
|
||||
|
||||
Reference in New Issue
Block a user