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,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
}