Dotfiles update 2025-12-25 11:21
This commit is contained in:
@@ -7,15 +7,16 @@ set -e
|
||||
|
||||
DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
|
||||
|
||||
# Source shared colors
|
||||
# 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 || {
|
||||
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'
|
||||
}
|
||||
|
||||
# Source utils (fixed: was DOTFILES_HOME, should be DOTFILES_DIR)
|
||||
source "$DOTFILES_DIR/zsh/lib/utils.zsh" 2>/dev/null
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
typeset -g WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
@@ -23,14 +24,13 @@ source "$DOTFILES_DIR/zsh/lib/utils.zsh" 2>/dev/null
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-compile "
|
||||
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
|
||||
for ((i=0; i<WIDTH; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
|
||||
@@ -2,20 +2,43 @@
|
||||
# ============================================================================
|
||||
# Dotfiles Health Check (Arch/CachyOS)
|
||||
# ============================================================================
|
||||
# Comprehensive health check with Arch-specific diagnostics
|
||||
#
|
||||
# Usage:
|
||||
# dotfiles-doctor.sh # Run all checks
|
||||
# dotfiles-doctor.sh --fix # Attempt automatic fixes
|
||||
# dotfiles-doctor.sh --quick # Quick essential checks only
|
||||
# ============================================================================
|
||||
|
||||
# Note: Not using set -e because arithmetic operations can return non-zero
|
||||
# ============================================================================
|
||||
# Source Configuration
|
||||
# ============================================================================
|
||||
# utils.zsh sources config.zsh which sources dotfiles.conf
|
||||
# This gives us access to all settings including DF_WIDTH, DOTFILES_VERSION, etc.
|
||||
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
readonly DOTFILES_VERSION="3.1.0"
|
||||
_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
|
||||
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_source_config
|
||||
|
||||
# ============================================================================
|
||||
# Parse Arguments
|
||||
# ============================================================================
|
||||
|
||||
# Parse arguments
|
||||
DO_FIX=false
|
||||
QUICK_MODE=false
|
||||
for arg in "$@"; do
|
||||
@@ -34,17 +57,6 @@ for arg in "$@"; do
|
||||
esac
|
||||
done
|
||||
|
||||
# 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'
|
||||
}
|
||||
|
||||
# Source utils.zsh
|
||||
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
|
||||
# Track results
|
||||
TOTAL_CHECKS=0
|
||||
PASSED_CHECKS=0
|
||||
@@ -53,65 +65,42 @@ WARNING_CHECKS=0
|
||||
FIXED_CHECKS=0
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# Header (uses DF_WIDTH from config)
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
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
|
||||
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
|
||||
|
||||
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 ""
|
||||
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
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Health check functions
|
||||
# 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"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Core Health Checks
|
||||
# ============================================================================
|
||||
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
|
||||
local version=$(grep "VERSION_ID" /etc/os-release 2>/dev/null | cut -d= -f2 | tr -d '"')
|
||||
check_pass "Running CachyOS ${version}"
|
||||
check_pass "Running CachyOS"
|
||||
elif grep -qi "arch" /etc/os-release 2>/dev/null; then
|
||||
check_pass "Running Arch Linux"
|
||||
else
|
||||
@@ -120,407 +109,61 @@ check_os() {
|
||||
else
|
||||
check_fail "Not running on Linux"
|
||||
fi
|
||||
|
||||
# Kernel check
|
||||
local kernel=$(uname -r)
|
||||
if [[ "$kernel" == *"cachyos"* ]]; then
|
||||
check_pass "CachyOS kernel: $kernel"
|
||||
elif [[ "$kernel" == *"zen"* ]]; then
|
||||
check_pass "Zen kernel: $kernel"
|
||||
elif [[ "$kernel" == *"lts"* ]]; then
|
||||
check_pass "LTS kernel: $kernel"
|
||||
else
|
||||
check_pass "Kernel: $kernel"
|
||||
fi
|
||||
check_pass "Kernel: $(uname -r)"
|
||||
}
|
||||
|
||||
check_shell() {
|
||||
print_section "Shell Configuration"
|
||||
|
||||
if [[ -f "$HOME/.zshrc" ]]; then
|
||||
check_pass "Zsh configuration exists"
|
||||
else
|
||||
check_fail "Zsh configuration missing"
|
||||
if [[ "$DO_FIX" == true ]]; then
|
||||
ln -sf "$DOTFILES_HOME/zsh/.zshrc" "$HOME/.zshrc" 2>/dev/null && check_fixed ".zshrc symlink created"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$SHELL" == *"zsh"* ]]; then
|
||||
check_pass "Zsh is default shell"
|
||||
else
|
||||
check_warn "Zsh is not default shell (current: $SHELL)"
|
||||
if [[ "$DO_FIX" == true ]]; then
|
||||
echo " Run: chsh -s \$(which zsh)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if zsh is recent version
|
||||
if command -v zsh &>/dev/null; then
|
||||
local zsh_version=$(zsh --version | awk '{print $2}')
|
||||
check_pass "Zsh version: $zsh_version"
|
||||
fi
|
||||
[[ -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}')"
|
||||
}
|
||||
|
||||
check_symlinks() {
|
||||
print_section "Symlinks"
|
||||
|
||||
local symlink_count=0
|
||||
local broken_count=0
|
||||
|
||||
for symlink in ~/.zshrc ~/.gitconfig ~/.vimrc ~/.tmux.conf; do
|
||||
if [[ -L "$symlink" ]]; then
|
||||
symlink_count=$((symlink_count + 1))
|
||||
if [[ -e "$symlink" ]]; then
|
||||
check_pass "$(basename $symlink) → $(readlink $symlink)"
|
||||
else
|
||||
broken_count=$((broken_count + 1))
|
||||
check_fail "$(basename $symlink) is broken"
|
||||
fi
|
||||
[[ -e "$symlink" ]] && check_pass "$(basename $symlink) → $(readlink $symlink)" || check_fail "$(basename $symlink) is broken"
|
||||
elif [[ -f "$symlink" ]]; then
|
||||
check_warn "$(basename $symlink) is regular file (not symlink)"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $symlink_count -eq 0 ]]; then
|
||||
check_warn "No symlinks found (may not be installed yet)"
|
||||
fi
|
||||
}
|
||||
|
||||
check_vim() {
|
||||
print_section "Editor Configuration"
|
||||
|
||||
if command -v vim &>/dev/null; then
|
||||
local vim_version=$(vim --version | head -1 | awk '{print $5}')
|
||||
check_pass "Vim installed: $vim_version"
|
||||
else
|
||||
check_fail "Vim not installed"
|
||||
fi
|
||||
|
||||
if command -v nvim &>/dev/null; then
|
||||
local nvim_version=$(nvim --version | head -1 | awk '{print $2}')
|
||||
check_pass "Neovim installed: $nvim_version"
|
||||
else
|
||||
check_warn "Neovim not installed (optional)"
|
||||
fi
|
||||
}
|
||||
|
||||
check_git() {
|
||||
print_section "Git Configuration"
|
||||
|
||||
if command -v git &>/dev/null; then
|
||||
check_pass "Git installed"
|
||||
|
||||
if git config --global user.name &>/dev/null; then
|
||||
local git_user=$(git config --global user.name)
|
||||
check_pass "Git user: $git_user"
|
||||
else
|
||||
check_fail "Git user not configured"
|
||||
fi
|
||||
|
||||
if git config --global user.email &>/dev/null; then
|
||||
check_pass "Git email configured"
|
||||
else
|
||||
check_fail "Git email not configured"
|
||||
fi
|
||||
else
|
||||
check_fail "Git not installed"
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Arch-Specific Checks
|
||||
# ============================================================================
|
||||
|
||||
check_pacman() {
|
||||
print_section "Package Manager"
|
||||
|
||||
if command -v pacman &>/dev/null; then
|
||||
check_pass "Pacman available"
|
||||
else
|
||||
check_fail "Pacman not found"
|
||||
return
|
||||
fi
|
||||
|
||||
# Check for AUR helper
|
||||
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 (recommend: paru)"
|
||||
fi
|
||||
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"
|
||||
}
|
||||
|
||||
check_pacman_health() {
|
||||
[[ "$QUICK_MODE" == true ]] && return
|
||||
|
||||
print_section "Pacman Health"
|
||||
|
||||
# Check for orphaned packages
|
||||
local orphans=$(pacman -Qtdq 2>/dev/null | wc -l)
|
||||
if [[ $orphans -eq 0 ]]; then
|
||||
check_pass "No orphaned packages"
|
||||
else
|
||||
check_warn "$orphans orphaned package(s)"
|
||||
if [[ "$DO_FIX" == true ]]; then
|
||||
echo " Clean: pacman -Qtdq | sudo pacman -Rns -"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check package cache size
|
||||
if [[ -d /var/cache/pacman/pkg ]]; then
|
||||
local cache_size=$(du -sh /var/cache/pacman/pkg 2>/dev/null | cut -f1)
|
||||
local pkg_count=$(ls /var/cache/pacman/pkg 2>/dev/null | wc -l)
|
||||
|
||||
if [[ $pkg_count -gt 500 ]]; then
|
||||
check_warn "Package cache: $cache_size ($pkg_count files)"
|
||||
if [[ "$DO_FIX" == true ]]; then
|
||||
echo " Clean: sudo paccache -rk2"
|
||||
fi
|
||||
else
|
||||
check_pass "Package cache: $cache_size"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for available updates
|
||||
if command -v checkupdates &>/dev/null; then
|
||||
local updates=$(checkupdates 2>/dev/null | wc -l)
|
||||
if [[ $updates -eq 0 ]]; then
|
||||
check_pass "System up to date"
|
||||
else
|
||||
check_warn "$updates update(s) available"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_systemd() {
|
||||
[[ "$QUICK_MODE" == true ]] && return
|
||||
|
||||
print_section "Systemd Services"
|
||||
|
||||
# Check for failed services
|
||||
local failed_count=$(systemctl --failed --no-pager --no-legend 2>/dev/null | wc -l)
|
||||
|
||||
if [[ $failed_count -eq 0 ]]; then
|
||||
check_pass "No failed system services"
|
||||
else
|
||||
check_fail "$failed_count failed service(s)"
|
||||
systemctl --failed --no-pager --no-legend 2>/dev/null | head -3 | while read -r line; do
|
||||
local svc=$(echo "$line" | awk '{print $1}')
|
||||
echo -e " ${DF_DIM}• $svc${DF_NC}"
|
||||
done
|
||||
fi
|
||||
|
||||
# Check user services
|
||||
local user_failed=$(systemctl --user --failed --no-pager --no-legend 2>/dev/null | wc -l)
|
||||
if [[ $user_failed -eq 0 ]]; then
|
||||
check_pass "No failed user services"
|
||||
else
|
||||
check_warn "$user_failed failed user service(s)"
|
||||
fi
|
||||
}
|
||||
|
||||
check_btrfs() {
|
||||
[[ "$QUICK_MODE" == true ]] && return
|
||||
|
||||
# Only check if root is btrfs
|
||||
local fstype=$(df -T / 2>/dev/null | awk 'NR==2 {print $2}')
|
||||
[[ "$fstype" != "btrfs" ]] && return
|
||||
|
||||
print_section "Btrfs Filesystem"
|
||||
|
||||
check_pass "Root filesystem: btrfs"
|
||||
|
||||
# Check for device errors
|
||||
local stats=$(sudo btrfs device stats / 2>/dev/null)
|
||||
local errors=$(echo "$stats" | grep -v " 0$" | grep -v "^$")
|
||||
|
||||
if [[ -z "$errors" ]]; then
|
||||
check_pass "No btrfs device errors"
|
||||
else
|
||||
check_fail "Btrfs errors detected!"
|
||||
echo "$errors" | head -3 | while read -r line; do
|
||||
echo -e " ${DF_DIM}$line${DF_NC}"
|
||||
done
|
||||
fi
|
||||
|
||||
# Check last scrub
|
||||
local scrub_info=$(sudo btrfs scrub status / 2>/dev/null)
|
||||
if echo "$scrub_info" | grep -q "running"; then
|
||||
check_pass "Scrub currently running"
|
||||
elif echo "$scrub_info" | grep -q "finished"; then
|
||||
local scrub_date=$(echo "$scrub_info" | grep "Scrub started" | awk '{print $3, $4}')
|
||||
check_pass "Last scrub: $scrub_date"
|
||||
else
|
||||
check_warn "No scrub history (recommend monthly)"
|
||||
fi
|
||||
|
||||
# Check snapper
|
||||
if command -v snapper &>/dev/null && [[ -d "/.snapshots" ]]; then
|
||||
local snap_count=$(sudo snapper -c root list 2>/dev/null | tail -n +3 | wc -l)
|
||||
check_pass "Snapper: $snap_count snapshot(s)"
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Standard Checks
|
||||
# ============================================================================
|
||||
|
||||
check_optional_tools() {
|
||||
print_section "Optional Tools"
|
||||
|
||||
if command -v fzf &>/dev/null; then
|
||||
check_pass "fzf (fuzzy finder)"
|
||||
else
|
||||
check_warn "fzf not installed (command palette needs this)"
|
||||
fi
|
||||
|
||||
if command -v bat &>/dev/null; then
|
||||
check_pass "bat (syntax highlighting)"
|
||||
else
|
||||
check_warn "bat not installed"
|
||||
fi
|
||||
|
||||
if command -v eza &>/dev/null; then
|
||||
check_pass "eza (modern ls)"
|
||||
else
|
||||
check_warn "eza not installed"
|
||||
fi
|
||||
|
||||
if command -v tmux &>/dev/null; then
|
||||
check_pass "tmux (terminal multiplexer)"
|
||||
else
|
||||
check_warn "tmux not installed"
|
||||
fi
|
||||
|
||||
if command -v age &>/dev/null || command -v gpg &>/dev/null; then
|
||||
check_pass "Encryption available (age/gpg)"
|
||||
else
|
||||
check_warn "No encryption tool (vault needs age/gpg)"
|
||||
fi
|
||||
}
|
||||
|
||||
check_permissions() {
|
||||
print_section "File Permissions"
|
||||
|
||||
if [[ -f "$DOTFILES_HOME/install.sh" ]]; then
|
||||
if [[ -x "$DOTFILES_HOME/install.sh" ]]; then
|
||||
check_pass "install.sh is executable"
|
||||
else
|
||||
check_fail "install.sh is not executable"
|
||||
if [[ "$DO_FIX" == true ]]; then
|
||||
chmod +x "$DOTFILES_HOME/install.sh"
|
||||
check_fixed "install.sh permissions"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -d "$DOTFILES_HOME/bin" ]]; then
|
||||
local non_exec=$(find "$DOTFILES_HOME/bin" -type f ! -perm /u+x 2>/dev/null | wc -l)
|
||||
if [[ $non_exec -eq 0 ]]; then
|
||||
check_pass "All bin/ scripts executable"
|
||||
else
|
||||
check_fail "$non_exec bin/ scripts not executable"
|
||||
if [[ "$DO_FIX" == true ]]; then
|
||||
find "$DOTFILES_HOME/bin" -type f ! -perm /u+x -exec chmod +x {} \;
|
||||
check_fixed "bin/ permissions"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_zsh_plugins() {
|
||||
print_section "Zsh Plugins"
|
||||
|
||||
if [[ -d "$HOME/.oh-my-zsh" ]]; then
|
||||
check_pass "Oh My Zsh installed"
|
||||
|
||||
if [[ -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]]; then
|
||||
check_pass "zsh-autosuggestions"
|
||||
else
|
||||
check_warn "zsh-autosuggestions not installed"
|
||||
fi
|
||||
|
||||
if [[ -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]]; then
|
||||
check_pass "zsh-syntax-highlighting"
|
||||
else
|
||||
check_warn "zsh-syntax-highlighting not installed"
|
||||
fi
|
||||
|
||||
if [[ -f "$HOME/.oh-my-zsh/themes/adlee.zsh-theme" ]]; then
|
||||
check_pass "adlee theme"
|
||||
else
|
||||
check_warn "adlee theme not installed"
|
||||
fi
|
||||
else
|
||||
check_warn "Oh My Zsh not installed"
|
||||
fi
|
||||
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"
|
||||
}
|
||||
|
||||
check_dotfiles_dir() {
|
||||
print_section "Dotfiles Directory"
|
||||
|
||||
if [[ -d "$DOTFILES_HOME" ]]; then
|
||||
check_pass "Dotfiles: $DOTFILES_HOME"
|
||||
else
|
||||
check_fail "Dotfiles not found: $DOTFILES_HOME"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -f "$DOTFILES_HOME/dotfiles.conf" ]]; then
|
||||
check_pass "Config file exists"
|
||||
else
|
||||
check_warn "Config file missing"
|
||||
fi
|
||||
|
||||
if [[ -d "$DOTFILES_HOME/.git" ]]; then
|
||||
check_pass "Git repo initialized"
|
||||
|
||||
# Check for uncommitted changes
|
||||
local changes=$(cd "$DOTFILES_HOME" && git status --porcelain 2>/dev/null | wc -l)
|
||||
if [[ $changes -gt 0 ]]; then
|
||||
check_warn "$changes uncommitted change(s)"
|
||||
fi
|
||||
else
|
||||
check_warn "Not a git repository"
|
||||
fi
|
||||
[[ -d "$DOTFILES_HOME" ]] && check_pass "Dotfiles: $DOTFILES_HOME" || { check_fail "Dotfiles not found"; return; }
|
||||
[[ -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"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Print Summary
|
||||
# ============================================================================
|
||||
|
||||
print_summary() {
|
||||
local width="${DF_WIDTH:-66}"
|
||||
echo ""
|
||||
printf "${DF_CYAN}─%.0s${DF_NC}" {1..70}; 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"
|
||||
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 " ${DF_YELLOW}Warnings:${DF_NC} $WARNING_CHECKS"
|
||||
fi
|
||||
if [[ $FIXED_CHECKS -gt 0 ]]; then
|
||||
echo -e " ${DF_CYAN}Fixed:${DF_NC} $FIXED_CHECKS"
|
||||
fi
|
||||
echo -e "${DF_RED}✗${DF_NC} Issues found: $FAILED_CHECKS failed, $WARNING_CHECKS warnings"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
if [[ $FAILED_CHECKS -gt 0 && "$DO_FIX" != true ]]; then
|
||||
echo -e "${DF_YELLOW}💡${DF_NC} Run with --fix to attempt automatic fixes"
|
||||
echo ""
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $FIXED_CHECKS -gt 0 ]]; then
|
||||
echo -e "${DF_CYAN}ℹ${DF_NC} Fixed $FIXED_CHECKS issue(s). Run again to verify."
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -529,26 +172,12 @@ print_summary() {
|
||||
|
||||
main() {
|
||||
print_header
|
||||
|
||||
# Essential checks (always run)
|
||||
check_os
|
||||
check_pacman
|
||||
check_shell
|
||||
check_dotfiles_dir
|
||||
check_symlinks
|
||||
|
||||
# Additional checks (skip in quick mode)
|
||||
if [[ "$QUICK_MODE" != true ]]; then
|
||||
check_vim
|
||||
check_git
|
||||
check_zsh_plugins
|
||||
check_optional_tools
|
||||
check_permissions
|
||||
check_pacman_health
|
||||
check_systemd
|
||||
check_btrfs
|
||||
fi
|
||||
|
||||
[[ "$QUICK_MODE" != true ]] && check_optional_tools
|
||||
print_summary
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,17 @@ set -e
|
||||
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
|
||||
# Source shared colors
|
||||
# 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 || {
|
||||
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_BOLD=$'\033[1m' DF_DIM=$'\033[2m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
}
|
||||
|
||||
# Source utils.zsh
|
||||
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
readonly WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
@@ -24,230 +25,55 @@ source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-stats "
|
||||
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
|
||||
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}│${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
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Helper functions
|
||||
# ============================================================================
|
||||
|
||||
print_section() {
|
||||
echo ""
|
||||
echo -e "${DF_BLUE}▶${DF_NC} $1"
|
||||
echo -e "${DF_CYAN}─────────────────────────────────────────────────────────────${DF_NC}"
|
||||
}
|
||||
|
||||
# Get command history
|
||||
get_history() {
|
||||
if [[ -f "$HOME/.bash_history" ]]; then
|
||||
cat "$HOME/.bash_history"
|
||||
elif [[ -f "$HOME/.zsh_history" ]]; then
|
||||
if [[ -f "$HOME/.zsh_history" ]]; then
|
||||
grep -I "^:" "$HOME/.zsh_history" | cut -d';' -f2 || cat "$HOME/.zsh_history"
|
||||
elif [[ -f "$HOME/.bash_history" ]]; then
|
||||
cat "$HOME/.bash_history"
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Statistics functions
|
||||
# ============================================================================
|
||||
|
||||
show_dashboard() {
|
||||
print_section "Command History Dashboard"
|
||||
|
||||
local total=$(get_history | wc -l)
|
||||
local unique=$(get_history | sort | uniq | wc -l)
|
||||
|
||||
echo ""
|
||||
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
|
||||
local percent=$((count * 100 / total))
|
||||
local bar_length=$((percent / 5))
|
||||
local bar=$(printf '█%.0s' $(seq 1 $bar_length))
|
||||
printf " %-20s ${DF_GREEN}%5d${DF_NC} ${DF_MAGENTA}%3d%%${DF_NC} ${bar}\n" "$cmd" "$count" "$percent"
|
||||
printf " %-20s ${DF_GREEN}%5d${DF_NC}\n" "$cmd" "$count"
|
||||
done
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
show_top_n() {
|
||||
local n="${1:-20}"
|
||||
|
||||
print_section "Top $n Commands"
|
||||
|
||||
local total=$(get_history | wc -l)
|
||||
|
||||
get_history | awk '{print $1}' | sort | uniq -c | sort -rn | head -"$n" | \
|
||||
while read count cmd; do
|
||||
local percent=$((count * 100 / total))
|
||||
printf " ${DF_YELLOW}%4d${DF_NC} %-30s ${DF_CYAN}%3d%%${DF_NC}\n" "$count" "$cmd" "$percent"
|
||||
done
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
show_suggestions() {
|
||||
print_section "Suggested Aliases"
|
||||
|
||||
local total=$(get_history | wc -l)
|
||||
|
||||
echo ""
|
||||
get_history | awk '{print $1}' | sort | uniq -c | sort -rn | head -20 | \
|
||||
while read count cmd; do
|
||||
if [[ $count -gt 50 ]]; then
|
||||
printf " ${DF_YELLOW}Suggestion:${DF_NC} ${DF_GREEN}alias ${cmd:0:2}='$cmd'${DF_NC} (used $count times)\n"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
show_breakdown() {
|
||||
print_section "Command Breakdown"
|
||||
|
||||
echo ""
|
||||
echo -e " ${DF_CYAN}Git Commands:${DF_NC}"
|
||||
get_history | grep -I "^git" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${DF_CYAN}Navigation (cd):${DF_NC}"
|
||||
get_history | grep -I "^cd" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${DF_CYAN}File Operations (ls):${DF_NC}"
|
||||
get_history | grep -I "^ls" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${DF_CYAN}Package Management (pacman/paru/yay):${DF_NC}"
|
||||
get_history | grep -I -E "^(pacman|paru|yay)" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${DF_CYAN}Editing (vim/nvim):${DF_NC}"
|
||||
get_history | grep -I -E "^(vim|nvim)" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo -e " ${DF_CYAN}Dotfiles Commands (dotfiles-):${DF_NC}"
|
||||
get_history | grep -I "^dotfiles-" | wc -l | xargs printf " %d\n"
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
show_heatmap() {
|
||||
print_section "Activity by Hour"
|
||||
|
||||
echo ""
|
||||
if [[ -f "$HOME/.zsh_history" ]]; then
|
||||
grep -I "^:" "$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 " ${DF_CYAN}%02d:00${DF_NC} ${DF_MAGENTA}%5d${DF_NC} ${DF_GREEN}${bar}${DF_NC}\n" "$hour" "$count"
|
||||
done
|
||||
else
|
||||
echo " ${DF_YELLOW}⚠${DF_NC} Zsh history file required for hourly breakdown"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
show_dirs() {
|
||||
print_section "Most Visited Directories"
|
||||
|
||||
echo ""
|
||||
if [[ -f "$HOME/.zsh_history" ]]; then
|
||||
grep -I "cd " "$HOME/.zsh_history" | awk '{print $NF}' | sort | uniq -c | \
|
||||
sort -rn | head -15 | while read count dir; do
|
||||
printf " ${DF_CYAN}%4d${DF_NC} ${DF_YELLOW}%s${DF_NC}\n" "$count" "$dir"
|
||||
done
|
||||
else
|
||||
echo " ${DF_YELLOW}⚠${DF_NC} Zsh history file required"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
show_git_breakdown() {
|
||||
print_section "Git Command Breakdown"
|
||||
|
||||
echo ""
|
||||
local total=$(get_history | grep -I "^git" | wc -l)
|
||||
|
||||
if [[ $total -eq 0 ]]; then
|
||||
echo " ${DF_YELLOW}No git commands found${DF_NC}"
|
||||
return
|
||||
fi
|
||||
|
||||
get_history | grep -I "^git " | awk '{print $2}' | sort | uniq -c | sort -rn | \
|
||||
head -10 | while read count subcmd; do
|
||||
local percent=$((count * 100 / total))
|
||||
printf " ${DF_YELLOW}git %-15s${DF_NC} ${DF_CYAN}%4d${DF_NC} (${DF_MAGENTA}%3d%%${DF_NC})\n" \
|
||||
"$subcmd" "$count" "$percent"
|
||||
done
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
print_header
|
||||
|
||||
case "${1:-dashboard}" in
|
||||
dashboard)
|
||||
show_dashboard
|
||||
;;
|
||||
top)
|
||||
show_top_n "${2:-20}"
|
||||
;;
|
||||
suggest)
|
||||
show_suggestions
|
||||
;;
|
||||
breakdown)
|
||||
show_breakdown
|
||||
;;
|
||||
heatmap)
|
||||
show_heatmap
|
||||
;;
|
||||
dirs)
|
||||
show_dirs
|
||||
;;
|
||||
git)
|
||||
show_git_breakdown
|
||||
;;
|
||||
export)
|
||||
echo "{"
|
||||
echo " \"total_commands\": $(get_history | wc -l),"
|
||||
echo " \"unique_commands\": $(get_history | sort | uniq | wc -l),"
|
||||
echo " \"timestamp\": \"$(date -Iseconds)\""
|
||||
echo "}"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {dashboard|top [n]|suggest|breakdown|heatmap|dirs|git|export}"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " dashboard Show full dashboard (default)"
|
||||
echo " top [n] Show top N commands (default: 20)"
|
||||
echo " suggest Suggest aliases"
|
||||
echo " breakdown Command category breakdown"
|
||||
echo " heatmap Activity by hour"
|
||||
echo " dirs Most visited directories"
|
||||
echo " git Git command breakdown"
|
||||
echo " export Export as JSON"
|
||||
exit 1
|
||||
;;
|
||||
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 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
@@ -5,345 +5,162 @@
|
||||
|
||||
set -e
|
||||
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
# ============================================================================
|
||||
# Source Configuration
|
||||
# ============================================================================
|
||||
|
||||
# Source shared colors
|
||||
source "$DOTFILES_HOME/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
_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_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_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}"
|
||||
}
|
||||
|
||||
# Source utils.zsh
|
||||
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
|
||||
# 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'
|
||||
|
||||
# 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'
|
||||
}
|
||||
|
||||
|
||||
_df_source_config
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# Header
|
||||
# ============================================================================
|
||||
|
||||
DF_WIDTH=66
|
||||
|
||||
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 script_name="dotfiles-sync"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
|
||||
|
||||
# Build horizontal line
|
||||
local hline=""
|
||||
for ((i=0; i<DF_WIDTH; i++)); do hline+="═"; done
|
||||
local inner=$((DF_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
|
||||
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}${h_left}${DF_NC}${h_spaces}${DF_LIGHT_GREEN}${h_center}${h_spaces}${DF_NC}${DF_BOLD}${h_right}${DF_NC} ${DF_GREY}│${DF_NC}"
|
||||
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
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Helper functions
|
||||
# Helper Functions
|
||||
# ============================================================================
|
||||
|
||||
print_status() {
|
||||
echo -e "${CYAN}⎯${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}✓${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}✗${NC} $1" >&2
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠${NC} $1"
|
||||
}
|
||||
|
||||
print_section() {
|
||||
echo ""
|
||||
echo -e "${BLUE}▶${NC} $1"
|
||||
echo -e "${CYAN}─────────────────────────────────────────────────────────────${NC}"
|
||||
}
|
||||
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"; }
|
||||
|
||||
# ============================================================================
|
||||
# Sync functions
|
||||
# Sync Functions
|
||||
# ============================================================================
|
||||
|
||||
check_git_repo() {
|
||||
if ! git -C "$DOTFILES_HOME" rev-parse --git-dir > /dev/null 2>&1; then
|
||||
print_error "Not a git repository: $DOTFILES_HOME"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_git_config() {
|
||||
if ! git config --global user.name > /dev/null 2>&1; then
|
||||
print_error "Git user.name not configured"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! git config --global user.email > /dev/null 2>&1; then
|
||||
print_error "Git user.email not configured"
|
||||
exit 1
|
||||
fi
|
||||
git -C "$DOTFILES_HOME" rev-parse --git-dir > /dev/null 2>&1 || { print_error "Not a git repository: $DOTFILES_HOME"; exit 1; }
|
||||
}
|
||||
|
||||
get_sync_status() {
|
||||
cd "$DOTFILES_HOME"
|
||||
|
||||
local local_commits=$(git rev-list --count @{u}..HEAD 2>/dev/null || echo 0)
|
||||
local remote_commits=$(git rev-list --count HEAD..@{u} 2>/dev/null || echo 0)
|
||||
|
||||
echo "$local_commits:$remote_commits"
|
||||
}
|
||||
|
||||
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')"
|
||||
print_status "Last update: $(git log -1 --pretty=format:'%ar' 2>/dev/null || echo 'N/A')"
|
||||
|
||||
|
||||
local status=$(get_sync_status)
|
||||
local local_commits="${status%:*}"
|
||||
local remote_commits="${status#*:}"
|
||||
|
||||
|
||||
echo ""
|
||||
if [[ $local_commits -gt 0 ]]; then
|
||||
print_warning "$local_commits commit(s) ahead of remote"
|
||||
fi
|
||||
|
||||
if [[ $remote_commits -gt 0 ]]; then
|
||||
print_warning "$remote_commits commit(s) behind remote"
|
||||
fi
|
||||
|
||||
if [[ $local_commits -eq 0 ]] && [[ $remote_commits -eq 0 ]]; then
|
||||
print_success "In sync with remote"
|
||||
fi
|
||||
[[ $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"
|
||||
}
|
||||
|
||||
show_status_short() {
|
||||
cd "$DOTFILES_HOME"
|
||||
|
||||
# Count local changes
|
||||
local changes=$(git status --porcelain | wc -l)
|
||||
|
||||
# Check commits ahead/behind
|
||||
local status=$(get_sync_status)
|
||||
local local_commits="${status%:*}"
|
||||
local remote_commits="${status#*:}"
|
||||
|
||||
if [[ $changes -gt 0 ]]; then
|
||||
echo -e " ${YELLOW}⚠${NC} Dotfiles: ${changes} local change(s) not pushed"
|
||||
echo -e " Run: ${CYAN}dfpush${NC} or ${CYAN}dotfiles-sync.sh push${NC}"
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Dotfiles: ${changes} local change(s) not pushed"
|
||||
elif [[ $local_commits -gt 0 ]]; then
|
||||
echo -e " ${YELLOW}⚠${NC} Dotfiles: ${local_commits} commit(s) not pushed"
|
||||
echo -e " Run: ${CYAN}git push${NC} in ~/.dotfiles"
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Dotfiles: ${local_commits} commit(s) not pushed"
|
||||
elif [[ $remote_commits -gt 0 ]]; then
|
||||
echo -e " ${YELLOW}⚠${NC} Dotfiles: ${remote_commits} commit(s) behind remote"
|
||||
echo -e " Run: ${CYAN}dfpull${NC} or ${CYAN}dotfiles-sync.sh pull${NC}"
|
||||
#else
|
||||
# echo -e " ${GREEN}✓${NC} Dotfiles: in sync"
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
show_diff() {
|
||||
print_section "Local Changes"
|
||||
|
||||
cd "$DOTFILES_HOME"
|
||||
|
||||
if git status --porcelain | grep -I -q .; then
|
||||
print_status "Modified files:"
|
||||
git status --porcelain | sed 's/^/ /'
|
||||
else
|
||||
print_success "No local changes"
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Dotfiles: ${remote_commits} commit(s) behind remote"
|
||||
fi
|
||||
}
|
||||
|
||||
pull_changes() {
|
||||
print_section "Pulling Changes"
|
||||
|
||||
cd "$DOTFILES_HOME"
|
||||
|
||||
print_status "Fetching from remote..."
|
||||
git fetch origin
|
||||
|
||||
local status=$(get_sync_status)
|
||||
local remote_commits="${status#*:}"
|
||||
|
||||
if [[ $remote_commits -gt 0 ]]; then
|
||||
print_status "Pulling $remote_commits remote commit(s)..."
|
||||
git pull origin
|
||||
print_success "Changes pulled"
|
||||
else
|
||||
print_success "Already up to date"
|
||||
fi
|
||||
git pull origin && print_success "Changes pulled" || print_success "Already up to date"
|
||||
}
|
||||
|
||||
push_changes() {
|
||||
local commit_msg="$1"
|
||||
|
||||
print_section "Pushing Changes"
|
||||
|
||||
cd "$DOTFILES_HOME"
|
||||
|
||||
if ! git status --porcelain | grep -I -q .; then
|
||||
|
||||
if ! git status --porcelain | grep -q .; then
|
||||
print_warning "No local changes to push"
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
print_status "Staging changes..."
|
||||
git add -A
|
||||
|
||||
# If no commit message provided, prompt for one
|
||||
|
||||
if [[ -z "$commit_msg" ]]; then
|
||||
print_status "Enter commit message (or press Ctrl+C to cancel):"
|
||||
read -p " > " commit_msg
|
||||
|
||||
if [[ -z "$commit_msg" ]]; then
|
||||
print_error "Commit cancelled"
|
||||
return 1
|
||||
fi
|
||||
read -p "Commit message: " commit_msg
|
||||
[[ -z "$commit_msg" ]] && { print_error "Commit cancelled"; return 1; }
|
||||
fi
|
||||
|
||||
print_status "Committing: $commit_msg"
|
||||
|
||||
git commit -m "$commit_msg"
|
||||
|
||||
print_status "Pushing to remote..."
|
||||
git push origin
|
||||
|
||||
print_success "Changes pushed"
|
||||
}
|
||||
|
||||
auto_sync() {
|
||||
print_section "Auto-Sync"
|
||||
|
||||
cd "$DOTFILES_HOME"
|
||||
|
||||
# Pull remote changes
|
||||
print_status "Pulling from remote..."
|
||||
git fetch origin
|
||||
|
||||
if git status --porcelain | grep -I -q .; then
|
||||
print_status "Resolving conflicts automatically..."
|
||||
git pull --strategy=ours
|
||||
else
|
||||
git pull origin
|
||||
fi
|
||||
|
||||
print_success "Auto-sync complete"
|
||||
}
|
||||
|
||||
watch_sync() {
|
||||
local interval="${1:-300}"
|
||||
|
||||
print_section "Watch Mode"
|
||||
print_status "Auto-syncing every $interval seconds"
|
||||
print_status "Press Ctrl+C to stop"
|
||||
|
||||
while true; do
|
||||
auto_sync
|
||||
sleep "$interval"
|
||||
done
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
check_git_repo
|
||||
check_git_config
|
||||
|
||||
|
||||
case "${1:-status}" in
|
||||
status)
|
||||
if [[ "$2" == "-s" || "$2" == "--short" ]]; then
|
||||
show_status_short
|
||||
else
|
||||
print_header
|
||||
show_status
|
||||
show_diff
|
||||
fi
|
||||
[[ "$2" == "-s" || "$2" == "--short" ]] && show_status_short || { print_header; show_status; }
|
||||
;;
|
||||
push)
|
||||
print_header
|
||||
shift
|
||||
push_changes "$*"
|
||||
print_header; shift; push_changes "$*"
|
||||
;;
|
||||
pull)
|
||||
print_header
|
||||
pull_changes
|
||||
;;
|
||||
diff)
|
||||
print_header
|
||||
show_diff
|
||||
;;
|
||||
auto)
|
||||
auto_sync
|
||||
;;
|
||||
watch)
|
||||
print_header
|
||||
watch_sync "${2:-300}"
|
||||
print_header; pull_changes
|
||||
;;
|
||||
-s|--short)
|
||||
show_status_short
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {status [-s]|push [message]|pull|diff|auto|watch [interval]}"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " status Show sync status (default)"
|
||||
echo " status -s Show abbreviated one-line status"
|
||||
echo " push [message] Push local changes (prompts if no message)"
|
||||
echo " pull Pull remote changes"
|
||||
echo " diff Show local changes"
|
||||
echo " auto Automatically sync (pull remote)"
|
||||
echo " watch [sec] Auto-sync every N seconds (default: 300)"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -s, --short Abbreviated output (one line)"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 push \"Updated aliases\""
|
||||
echo " $0 push # Will prompt for message"
|
||||
echo " $0 status -s # Quick status check"
|
||||
echo "Usage: $0 {status [-s]|push [message]|pull}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -39,7 +39,8 @@ else
|
||||
DOTFILES_RAW_URL="https://raw.githubusercontent.com/adlee-was-taken/dotfiles/main"
|
||||
fi
|
||||
|
||||
# Source shared colors
|
||||
# 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 || {
|
||||
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'
|
||||
@@ -47,8 +48,8 @@ source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
}
|
||||
|
||||
# Source utils.zsh
|
||||
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
readonly WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
@@ -61,8 +62,7 @@ print_header() {
|
||||
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
|
||||
local hline="" && for ((i=0; i<WIDTH; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo -e "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
@@ -72,21 +72,10 @@ print_header() {
|
||||
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"
|
||||
}
|
||||
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
|
||||
@@ -96,8 +85,6 @@ print_header
|
||||
|
||||
if [ ! -d "$DOTFILES_DIR" ]; then
|
||||
print_error "Dotfiles directory not found: $DOTFILES_DIR"
|
||||
echo "Run the installation script first:"
|
||||
echo " curl -fsSL ${DOTFILES_RAW_URL}/install.sh | bash"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -112,24 +99,9 @@ if [ $? -eq 0 ]; then
|
||||
if [[ "$PULL_ONLY" == true ]]; then
|
||||
echo
|
||||
print_success "Pull complete (--pull-only mode)"
|
||||
echo "Run ./install.sh manually to re-link files"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -f "$DOTFILES_DIR/install.sh" ]; then
|
||||
echo
|
||||
read -p "Run install script to update links? [Y/n]: " response
|
||||
response=${response:-y}
|
||||
|
||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
||||
if [[ "$SKIP_DEPS" == true ]]; then
|
||||
"$DOTFILES_DIR/install.sh" --skip-deps
|
||||
else
|
||||
"$DOTFILES_DIR/install.sh"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
print_success "Update complete!"
|
||||
echo -e "Reload your shell: ${DF_CYAN}reload${DF_NC} or ${DF_CYAN}source ~/.zshrc${DF_NC}"
|
||||
|
||||
@@ -9,16 +9,17 @@ readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
readonly VAULT_DIR="${HOME}/.dotfiles/vault"
|
||||
readonly VAULT_FILE="${VAULT_DIR}/secrets.enc"
|
||||
|
||||
# Source shared colors
|
||||
# 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 || {
|
||||
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_BOLD=$'\033[1m' DF_DIM=$'\033[2m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
}
|
||||
|
||||
# Source utils.zsh
|
||||
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
readonly WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
@@ -26,314 +27,63 @@ source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-vault "
|
||||
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
|
||||
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}│${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"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Encryption/Decryption
|
||||
# ============================================================================
|
||||
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() {
|
||||
if command -v age &> /dev/null; then
|
||||
echo "age"
|
||||
elif command -v gpg &> /dev/null; then
|
||||
echo "gpg"
|
||||
else
|
||||
print_error "No encryption tool available (install age or gpg)"
|
||||
exit 1
|
||||
fi
|
||||
command -v age &> /dev/null && echo "age" || \
|
||||
command -v gpg &> /dev/null && echo "gpg" || \
|
||||
{ print_error "No encryption tool available"; exit 1; }
|
||||
}
|
||||
|
||||
init_vault() {
|
||||
print_section "Initializing Vault"
|
||||
|
||||
mkdir -p "$VAULT_DIR"
|
||||
chmod 700 "$VAULT_DIR"
|
||||
|
||||
if [[ ! -f "$VAULT_FILE" ]]; then
|
||||
echo "{}" | $(get_cipher) > "$VAULT_FILE"
|
||||
print_success "Vault initialized"
|
||||
else
|
||||
print_success "Vault already exists"
|
||||
fi
|
||||
}
|
||||
|
||||
decrypt_vault() {
|
||||
if [[ ! -f "$VAULT_FILE" ]]; then
|
||||
echo "{}"
|
||||
return
|
||||
fi
|
||||
|
||||
local cipher=$(get_cipher)
|
||||
|
||||
case "$cipher" in
|
||||
age)
|
||||
age -d -i "$HOME/.age/keys.txt" "$VAULT_FILE" 2>/dev/null || echo "{}"
|
||||
;;
|
||||
gpg)
|
||||
gpg --decrypt "$VAULT_FILE" 2>/dev/null || echo "{}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
encrypt_vault() {
|
||||
local data="$1"
|
||||
local cipher=$(get_cipher)
|
||||
|
||||
case "$cipher" in
|
||||
age)
|
||||
echo "$data" | age -R "$HOME/.age/keys.txt" > "$VAULT_FILE"
|
||||
;;
|
||||
gpg)
|
||||
echo "$data" | gpg --encrypt --armor > "$VAULT_FILE"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Vault operations
|
||||
# ============================================================================
|
||||
|
||||
vault_set() {
|
||||
local key="$1"
|
||||
local value="${2:-}"
|
||||
|
||||
if [[ -z "$key" ]]; then
|
||||
print_error "Usage: vault set <key> [value]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$value" ]]; then
|
||||
read -s -p "Enter value for $key: " value
|
||||
echo ""
|
||||
fi
|
||||
|
||||
local current=$(decrypt_vault)
|
||||
|
||||
if command -v jq &> /dev/null; then
|
||||
local updated=$(echo "$current" | jq --arg k "$key" --arg v "$value" '.[$k] = $v')
|
||||
else
|
||||
local updated="{\"$key\": \"$value\"}"
|
||||
fi
|
||||
|
||||
encrypt_vault "$updated"
|
||||
print_success "Secret stored: $key"
|
||||
}
|
||||
|
||||
vault_get() {
|
||||
local key="$1"
|
||||
|
||||
if [[ -z "$key" ]]; then
|
||||
print_error "Usage: vault get <key>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local vault=$(decrypt_vault)
|
||||
|
||||
if command -v jq &> /dev/null; then
|
||||
echo "$vault" | jq -r ".\"$key\" // \"\"" | grep -v "^$"
|
||||
else
|
||||
echo "$vault" | grep "\"$key\"" | cut -d'"' -f4
|
||||
fi
|
||||
[[ ! -f "$VAULT_FILE" ]] && { echo "{}" > "$VAULT_FILE"; print_success "Vault initialized"; } || print_success "Vault exists"
|
||||
}
|
||||
|
||||
vault_list() {
|
||||
print_section "Secrets"
|
||||
|
||||
local vault=$(decrypt_vault)
|
||||
|
||||
if command -v jq &> /dev/null; then
|
||||
echo "$vault" | jq -r 'keys[]' | while read key; do
|
||||
echo -e " ${DF_CYAN}•${DF_NC} $key"
|
||||
done
|
||||
else
|
||||
echo "$vault" | grep -o '"[^"]*":' | sed 's/"//g' | sed 's/:$//' | while read key; do
|
||||
echo -e " ${DF_CYAN}•${DF_NC} $key"
|
||||
done
|
||||
fi
|
||||
|
||||
[[ -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"
|
||||
echo ""
|
||||
}
|
||||
|
||||
vault_delete() {
|
||||
local key="$1"
|
||||
|
||||
if [[ -z "$key" ]]; then
|
||||
print_error "Usage: vault delete <key>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local vault=$(decrypt_vault)
|
||||
|
||||
if command -v jq &> /dev/null; then
|
||||
local updated=$(echo "$vault" | jq "del(.\"$key\")")
|
||||
else
|
||||
print_error "jq required for delete operation"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
encrypt_vault "$updated"
|
||||
print_success "Secret deleted: $key"
|
||||
}
|
||||
|
||||
vault_shell() {
|
||||
print_section "Loading secrets into environment"
|
||||
|
||||
local vault=$(decrypt_vault)
|
||||
|
||||
if command -v jq &> /dev/null; then
|
||||
echo "$vault" | jq -r 'to_entries[] | "export \(.key)=\"\(.value)\""'
|
||||
else
|
||||
print_error "jq required for shell export"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
vault_export() {
|
||||
local dest="${1:-.}"
|
||||
|
||||
if [[ -z "$dest" ]]; then
|
||||
print_error "Usage: vault export <filename>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -f "$dest" ]]; then
|
||||
print_error "File already exists: $dest"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "$VAULT_FILE" "$dest"
|
||||
chmod 600 "$dest"
|
||||
print_success "Vault exported to: $dest"
|
||||
}
|
||||
|
||||
vault_import() {
|
||||
local src="${1:-}"
|
||||
|
||||
if [[ -z "$src" ]]; then
|
||||
print_error "Usage: vault import <filename>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$src" ]]; then
|
||||
print_error "File not found: $src"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "$src" "$VAULT_FILE"
|
||||
chmod 600 "$VAULT_FILE"
|
||||
print_success "Vault imported from: $src"
|
||||
}
|
||||
|
||||
vault_status() {
|
||||
print_section "Vault Status"
|
||||
|
||||
if [[ ! -d "$VAULT_DIR" ]]; then
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Vault not initialized"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ ! -f "$VAULT_FILE" ]]; then
|
||||
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 " ${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")"
|
||||
|
||||
[[ -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; }
|
||||
echo -e " ${DF_CYAN}Location:${DF_NC} $VAULT_FILE"
|
||||
echo -e " ${DF_CYAN}Encryption:${DF_NC} $(get_cipher)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
print_header
|
||||
|
||||
if [[ ! -d "$VAULT_DIR" ]]; then
|
||||
init_vault
|
||||
fi
|
||||
|
||||
[[ ! -d "$VAULT_DIR" ]] && init_vault
|
||||
case "${1:-list}" in
|
||||
init)
|
||||
init_vault
|
||||
;;
|
||||
set)
|
||||
vault_set "$2" "${3:-}"
|
||||
;;
|
||||
get)
|
||||
vault_get "$2"
|
||||
;;
|
||||
list|ls)
|
||||
vault_list
|
||||
;;
|
||||
delete|rm)
|
||||
vault_delete "$2"
|
||||
;;
|
||||
shell)
|
||||
vault_shell
|
||||
;;
|
||||
export)
|
||||
vault_export "$2"
|
||||
;;
|
||||
import)
|
||||
vault_import "$2"
|
||||
;;
|
||||
status)
|
||||
vault_status
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {init|set|get|list|delete|shell|export|import|status}"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " init Initialize vault"
|
||||
echo " set <key> [value] Store secret (prompts if value omitted)"
|
||||
echo " get <key> Retrieve secret"
|
||||
echo " list List all keys"
|
||||
echo " delete <key> Delete secret"
|
||||
echo " shell Print secrets as export statements"
|
||||
echo " export <file> Backup vault (encrypted)"
|
||||
echo " import <file> Restore vault from backup"
|
||||
echo " status Show vault information"
|
||||
exit 1
|
||||
;;
|
||||
init) init_vault ;;
|
||||
list|ls) vault_list ;;
|
||||
status) vault_status ;;
|
||||
*) echo "Usage: $0 {init|list|status}"; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
@@ -3,157 +3,75 @@
|
||||
# Dotfiles Version Checker
|
||||
# ============================================================================
|
||||
|
||||
# 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"
|
||||
[[ -f "$DOTFILES_CONF" ]] || DOTFILES_CONF="$HOME/.dotfiles/dotfiles.conf"
|
||||
# ============================================================================
|
||||
# Source Configuration
|
||||
# ============================================================================
|
||||
|
||||
if [[ -f "$DOTFILES_CONF" ]]; then
|
||||
source "$DOTFILES_CONF"
|
||||
else
|
||||
DOTFILES_DIR="$HOME/.dotfiles"
|
||||
DOTFILES_VERSION="unknown"
|
||||
DOTFILES_BRANCH="main"
|
||||
DOTFILES_RAW_URL="https://raw.githubusercontent.com/adlee-was-taken/dotfiles/main"
|
||||
fi
|
||||
|
||||
# Source shared colors
|
||||
source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
_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_DIM=$'\033[2m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
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}"
|
||||
}
|
||||
|
||||
# Source utils.zsh
|
||||
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null
|
||||
_df_source_config
|
||||
|
||||
# ============================================================================
|
||||
# Parse Arguments
|
||||
# ============================================================================
|
||||
|
||||
CHECK_ONLY=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--check|-c) CHECK_ONLY=true ;;
|
||||
--help|-h)
|
||||
echo "Usage: dotfiles-version.sh [OPTIONS]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --check Only check for updates (exit 1 if behind)"
|
||||
echo " --help Show this help message"
|
||||
exit 0
|
||||
;;
|
||||
--help|-h) echo "Usage: dotfiles-version.sh [--check]"; exit 0 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# Header
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-version "
|
||||
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 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_LIGHT_GREEN}dotfiles-version${DF_NC} ${datetime} ${DF_GREY}│${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
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Functions
|
||||
# Version Info
|
||||
# ============================================================================
|
||||
|
||||
get_local_version() {
|
||||
echo "${DOTFILES_VERSION:-unknown}"
|
||||
}
|
||||
|
||||
get_local_commit() {
|
||||
if [[ -d "$DOTFILES_DIR/.git" ]]; then
|
||||
cd "$DOTFILES_DIR"
|
||||
git rev-parse --short HEAD 2>/dev/null || echo "unknown"
|
||||
cd - > /dev/null
|
||||
else
|
||||
echo "not a git repo"
|
||||
fi
|
||||
[[ -d "${DOTFILES_DIR}/.git" ]] && { cd "$DOTFILES_DIR"; git rev-parse --short HEAD 2>/dev/null || echo "unknown"; } || echo "not a git repo"
|
||||
}
|
||||
|
||||
get_local_date() {
|
||||
if [[ -d "$DOTFILES_DIR/.git" ]]; then
|
||||
cd "$DOTFILES_DIR"
|
||||
git log -1 --format="%ci" 2>/dev/null | cut -d' ' -f1 || echo "unknown"
|
||||
cd - > /dev/null
|
||||
else
|
||||
echo "unknown"
|
||||
fi
|
||||
}
|
||||
|
||||
get_remote_version() {
|
||||
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"
|
||||
else
|
||||
echo "unavailable"
|
||||
fi
|
||||
}
|
||||
|
||||
get_remote_commit() {
|
||||
if [[ -d "$DOTFILES_DIR/.git" ]]; then
|
||||
cd "$DOTFILES_DIR"
|
||||
git fetch origin --quiet 2>/dev/null || true
|
||||
git rev-parse --short "origin/${DOTFILES_BRANCH}" 2>/dev/null || echo "unavailable"
|
||||
cd - > /dev/null
|
||||
else
|
||||
echo "not a git repo"
|
||||
fi
|
||||
}
|
||||
|
||||
get_commits_behind() {
|
||||
if [[ -d "$DOTFILES_DIR/.git" ]]; then
|
||||
cd "$DOTFILES_DIR"
|
||||
git fetch origin --quiet 2>/dev/null || true
|
||||
local behind=$(git rev-list HEAD.."origin/${DOTFILES_BRANCH}" --count 2>/dev/null)
|
||||
echo "${behind:-0}"
|
||||
cd - > /dev/null
|
||||
else
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
compare_versions() {
|
||||
local local_v="$1"
|
||||
local remote_v="$2"
|
||||
|
||||
if [[ "$local_v" == "unknown" || "$remote_v" == "unknown" || "$remote_v" == "unavailable" ]]; then
|
||||
echo "unknown"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "$local_v" == "$remote_v" ]]; then
|
||||
echo "current"
|
||||
else
|
||||
local local_parts=(${local_v//./ })
|
||||
local remote_parts=(${remote_v//./ })
|
||||
|
||||
for i in 0 1 2; do
|
||||
local l=${local_parts[$i]:-0}
|
||||
local r=${remote_parts[$i]:-0}
|
||||
if (( l < r )); then
|
||||
echo "behind"
|
||||
return
|
||||
elif (( l > r )); then
|
||||
echo "ahead"
|
||||
return
|
||||
fi
|
||||
done
|
||||
echo "current"
|
||||
fi
|
||||
[[ -d "${DOTFILES_DIR}/.git" ]] && { cd "$DOTFILES_DIR"; git log -1 --format="%ci" 2>/dev/null | cut -d' ' -f1 || echo "unknown"; } || echo "unknown"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -161,66 +79,23 @@ compare_versions() {
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
local local_version=$(get_local_version)
|
||||
local local_commit=$(get_local_commit)
|
||||
local local_date=$(get_local_date)
|
||||
local remote_version=$(get_remote_version)
|
||||
local remote_commit=$(get_remote_commit)
|
||||
local commits_behind=$(get_commits_behind)
|
||||
local version_status=$(compare_versions "$local_version" "$remote_version")
|
||||
|
||||
if [[ "$CHECK_ONLY" == true ]]; then
|
||||
if [[ "$commits_behind" -gt 0 ]]; then
|
||||
echo "Updates available: $commits_behind commit(s) behind"
|
||||
exit 1
|
||||
else
|
||||
echo "Up to date"
|
||||
exit 0
|
||||
fi
|
||||
echo "Version: $DOTFILES_VERSION ($local_commit)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
print_header
|
||||
|
||||
echo -e "${DF_CYAN}Local:${DF_NC}"
|
||||
echo -e " Version: ${DF_GREEN}${local_version}${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
|
||||
|
||||
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 "${DF_CYAN}Status:${DF_NC}"
|
||||
|
||||
case "$version_status" in
|
||||
current)
|
||||
echo -e " Version: ${DF_GREEN}✓ Up to date${DF_NC}"
|
||||
;;
|
||||
behind)
|
||||
echo -e " Version: ${DF_YELLOW}⚠ New version available: ${remote_version}${DF_NC}"
|
||||
;;
|
||||
ahead)
|
||||
echo -e " Version: ${DF_CYAN}ℹ Local is ahead of remote${DF_NC}"
|
||||
;;
|
||||
*)
|
||||
echo -e " Version: ${DF_YELLOW}? Cannot determine${DF_NC}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$commits_behind" -gt 0 ]]; then
|
||||
echo -e " Commits: ${DF_YELLOW}⚠ ${commits_behind} commit(s) behind${DF_NC}"
|
||||
echo
|
||||
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: ${DF_GREEN}✓ Up to date${DF_NC}"
|
||||
fi
|
||||
|
||||
echo -e " Width: ${DF_WIDTH}"
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user