Dotfiles update 2025-12-25 12:04
This commit is contained in:
132
refactor_backup/bin/dotfiles-compile.sh
Executable file
132
refactor_backup/bin/dotfiles-compile.sh
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env zsh
|
||||
# ============================================================================
|
||||
# Dotfiles Compile - Pre-compile zsh files for faster loading
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
|
||||
|
||||
# Source shared colors and utils (provides DF_WIDTH)
|
||||
source "$DOTFILES_DIR/zsh/lib/utils.zsh" 2>/dev/null || \
|
||||
source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
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'
|
||||
}
|
||||
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
typeset -g WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-compile "
|
||||
else
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOST:-$(hostname -s 2>/dev/null)}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local hline=""
|
||||
for ((i=0; i<WIDTH; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
echo "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}✦ ${user}@${hostname}${DF_NC} ${DF_DIM}dotfiles-compile${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
compile_file() {
|
||||
local file="$1"
|
||||
if [[ -f "$file" ]]; then
|
||||
if [[ ! -f "${file}.zwc" ]] || [[ "$file" -nt "${file}.zwc" ]]; then
|
||||
zcompile "$file" 2>/dev/null && \
|
||||
echo -e "${DF_GREEN}✓${DF_NC} Compiled: ${file##*/}" || \
|
||||
echo -e "${DF_YELLOW}⚠${DF_NC} Skipped: ${file##*/}"
|
||||
else
|
||||
echo -e "${DF_CYAN}○${DF_NC} Current: ${file##*/}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
clean_compiled() {
|
||||
echo "Removing compiled files..."
|
||||
|
||||
local count=0
|
||||
|
||||
for zwc in "$DOTFILES_DIR"/**/*.zwc(N); do
|
||||
rm -f "$zwc"
|
||||
((count++))
|
||||
done
|
||||
|
||||
rm -f ~/.zshrc.zwc ~/.zshenv.zwc ~/.zprofile.zwc 2>/dev/null
|
||||
|
||||
echo -e "${DF_GREEN}✓${DF_NC} Removed $count compiled files"
|
||||
}
|
||||
|
||||
compile_all() {
|
||||
echo -e "${DF_CYAN}Compiling zsh files for faster startup...${DF_NC}"
|
||||
echo
|
||||
|
||||
echo "Core files:"
|
||||
compile_file ~/.zshrc
|
||||
compile_file ~/.zshenv
|
||||
compile_file ~/.zprofile
|
||||
echo
|
||||
|
||||
echo "Dotfiles:"
|
||||
compile_file "$DOTFILES_DIR/zsh/.zshrc"
|
||||
compile_file "$DOTFILES_DIR/zsh/aliases.zsh"
|
||||
|
||||
for file in "$DOTFILES_DIR/zsh/lib"/*.zsh(N); do
|
||||
compile_file "$file"
|
||||
done
|
||||
|
||||
for file in "$DOTFILES_DIR/zsh/functions"/*.zsh(N); do
|
||||
compile_file "$file"
|
||||
done
|
||||
|
||||
for file in "$DOTFILES_DIR/zsh/themes"/*.zsh-theme(N); do
|
||||
compile_file "$file"
|
||||
done
|
||||
echo
|
||||
|
||||
if [[ -d ~/.oh-my-zsh ]]; then
|
||||
echo "Oh-My-Zsh (optional):"
|
||||
compile_file ~/.oh-my-zsh/oh-my-zsh.sh
|
||||
echo
|
||||
fi
|
||||
|
||||
echo -e "${DF_GREEN}✓${DF_NC} Compilation complete"
|
||||
echo
|
||||
echo "To measure startup time:"
|
||||
echo " time zsh -i -c exit"
|
||||
echo " hyperfine 'zsh -i -c exit' # More accurate"
|
||||
}
|
||||
|
||||
show_help() {
|
||||
echo "Usage: dotfiles-compile.sh [OPTIONS]"
|
||||
echo
|
||||
echo "Compile zsh files to bytecode for faster shell startup."
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " (none) Compile all zsh files"
|
||||
echo " --clean Remove all compiled (.zwc) files"
|
||||
echo " --help Show this help"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
print_header
|
||||
|
||||
case "${1:-}" in
|
||||
--clean|-c) clean_compiled ;;
|
||||
--help|-h) show_help ;;
|
||||
*) compile_all ;;
|
||||
esac
|
||||
184
refactor_backup/bin/dotfiles-doctor.sh
Executable file
184
refactor_backup/bin/dotfiles-doctor.sh
Executable file
@@ -0,0 +1,184 @@
|
||||
#!/usr/bin/env bash
|
||||
# ============================================================================
|
||||
# Dotfiles Health Check (Arch/CachyOS)
|
||||
# ============================================================================
|
||||
# Usage:
|
||||
# dotfiles-doctor.sh # Run all checks
|
||||
# dotfiles-doctor.sh --fix # Attempt automatic fixes
|
||||
# dotfiles-doctor.sh --quick # Quick essential checks only
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# Source Configuration
|
||||
# ============================================================================
|
||||
# utils.zsh sources config.zsh which sources dotfiles.conf
|
||||
# This gives us access to all settings including DF_WIDTH, DOTFILES_VERSION, etc.
|
||||
|
||||
_df_source_config() {
|
||||
local locations=(
|
||||
"${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/utils.zsh"
|
||||
"$HOME/.dotfiles/zsh/lib/utils.zsh"
|
||||
)
|
||||
for loc in "${locations[@]}"; do
|
||||
[[ -f "$loc" ]] && { source "$loc"; return 0; }
|
||||
done
|
||||
|
||||
# Fallback defaults if utils.zsh not found
|
||||
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
|
||||
# ============================================================================
|
||||
|
||||
DO_FIX=false
|
||||
QUICK_MODE=false
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--fix) DO_FIX=true ;;
|
||||
--quick) QUICK_MODE=true ;;
|
||||
--help|-h)
|
||||
echo "Usage: dotfiles-doctor.sh [OPTIONS]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --fix Attempt automatic fixes for issues"
|
||||
echo " --quick Run quick essential checks only"
|
||||
echo " --help Show this help"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Track results
|
||||
TOTAL_CHECKS=0
|
||||
PASSED_CHECKS=0
|
||||
FAILED_CHECKS=0
|
||||
WARNING_CHECKS=0
|
||||
FIXED_CHECKS=0
|
||||
|
||||
# ============================================================================
|
||||
# Header (uses DF_WIDTH from config)
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-doctor"
|
||||
else
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local width="${DF_WIDTH:-66}"
|
||||
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo -e "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
echo -e "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}✦ ${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-doctor${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Check Functions
|
||||
# ============================================================================
|
||||
|
||||
print_section() { echo -e "\n${DF_BLUE}▶${DF_NC} $1"; }
|
||||
check_pass() { PASSED_CHECKS=$((PASSED_CHECKS + 1)); TOTAL_CHECKS=$((TOTAL_CHECKS + 1)); echo -e " ${DF_GREEN}✓${DF_NC} $1"; }
|
||||
check_fail() { FAILED_CHECKS=$((FAILED_CHECKS + 1)); TOTAL_CHECKS=$((TOTAL_CHECKS + 1)); echo -e " ${DF_RED}✗${DF_NC} $1"; }
|
||||
check_warn() { WARNING_CHECKS=$((WARNING_CHECKS + 1)); TOTAL_CHECKS=$((TOTAL_CHECKS + 1)); echo -e " ${DF_YELLOW}⚠${DF_NC} $1"; }
|
||||
check_fixed() { FIXED_CHECKS=$((FIXED_CHECKS + 1)); echo -e " ${DF_CYAN}⚙${DF_NC} Fixed: $1"; }
|
||||
|
||||
check_os() {
|
||||
print_section "Operating System"
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
if grep -qi "cachyos" /etc/os-release 2>/dev/null; then
|
||||
check_pass "Running CachyOS"
|
||||
elif grep -qi "arch" /etc/os-release 2>/dev/null; then
|
||||
check_pass "Running Arch Linux"
|
||||
else
|
||||
check_fail "Not running on Arch/CachyOS"
|
||||
fi
|
||||
else
|
||||
check_fail "Not running on Linux"
|
||||
fi
|
||||
check_pass "Kernel: $(uname -r)"
|
||||
}
|
||||
|
||||
check_shell() {
|
||||
print_section "Shell Configuration"
|
||||
[[ -f "$HOME/.zshrc" ]] && check_pass "Zsh configuration exists" || check_fail "Zsh configuration missing"
|
||||
[[ "$SHELL" == *"zsh"* ]] && check_pass "Zsh is default shell" || check_warn "Zsh is not default shell"
|
||||
command -v zsh &>/dev/null && check_pass "Zsh version: $(zsh --version | awk '{print $2}')"
|
||||
}
|
||||
|
||||
check_symlinks() {
|
||||
print_section "Symlinks"
|
||||
for symlink in ~/.zshrc ~/.gitconfig ~/.vimrc ~/.tmux.conf; do
|
||||
if [[ -L "$symlink" ]]; then
|
||||
[[ -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
|
||||
}
|
||||
|
||||
check_pacman() {
|
||||
print_section "Package Manager"
|
||||
command -v pacman &>/dev/null && check_pass "Pacman available" || { check_fail "Pacman not found"; return; }
|
||||
command -v paru &>/dev/null && check_pass "AUR helper: paru" || \
|
||||
command -v yay &>/dev/null && check_pass "AUR helper: yay" || check_warn "No AUR helper installed"
|
||||
}
|
||||
|
||||
check_optional_tools() {
|
||||
print_section "Optional Tools"
|
||||
command -v fzf &>/dev/null && check_pass "fzf" || check_warn "fzf not installed"
|
||||
command -v bat &>/dev/null && check_pass "bat" || check_warn "bat not installed"
|
||||
command -v eza &>/dev/null && check_pass "eza" || check_warn "eza not installed"
|
||||
command -v tmux &>/dev/null && check_pass "tmux" || check_warn "tmux not installed"
|
||||
}
|
||||
|
||||
check_dotfiles_dir() {
|
||||
print_section "Dotfiles Directory"
|
||||
[[ -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() {
|
||||
local width="${DF_WIDTH:-66}"
|
||||
echo ""
|
||||
printf "${DF_CYAN}─%.0s${DF_NC}" $(seq 1 $width); echo ""
|
||||
if [[ $FAILED_CHECKS -eq 0 ]]; then
|
||||
echo -e "${DF_GREEN}✓${DF_NC} All checks passed ($PASSED_CHECKS/$TOTAL_CHECKS)"
|
||||
else
|
||||
echo -e "${DF_RED}✗${DF_NC} Issues found: $FAILED_CHECKS failed, $WARNING_CHECKS warnings"
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
print_header
|
||||
check_os
|
||||
check_pacman
|
||||
check_shell
|
||||
check_dotfiles_dir
|
||||
check_symlinks
|
||||
[[ "$QUICK_MODE" != true ]] && check_optional_tools
|
||||
print_summary
|
||||
}
|
||||
|
||||
main "$@"
|
||||
80
refactor_backup/bin/dotfiles-stats.sh
Executable file
80
refactor_backup/bin/dotfiles-stats.sh
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
# ============================================================================
|
||||
# Dotfiles Shell Analytics (Arch/CachyOS)
|
||||
# ============================================================================
|
||||
|
||||
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 || {
|
||||
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'
|
||||
}
|
||||
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
readonly WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-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"
|
||||
echo -e "${DF_CYAN}─────────────────────────────────────────────────────────────${DF_NC}"
|
||||
}
|
||||
|
||||
get_history() {
|
||||
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
|
||||
}
|
||||
|
||||
show_dashboard() {
|
||||
print_section "Command History Dashboard"
|
||||
local total=$(get_history | wc -l)
|
||||
local unique=$(get_history | sort | uniq | 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"
|
||||
done
|
||||
echo ""
|
||||
}
|
||||
|
||||
main() {
|
||||
print_header
|
||||
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 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
169
refactor_backup/bin/dotfiles-sync.sh
Executable file
169
refactor_backup/bin/dotfiles-sync.sh
Executable file
@@ -0,0 +1,169 @@
|
||||
#!/usr/bin/env bash
|
||||
# ============================================================================
|
||||
# Dotfiles Synchronization (Arch/CachyOS)
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# ============================================================================
|
||||
# Source Configuration
|
||||
# ============================================================================
|
||||
|
||||
_df_source_config() {
|
||||
local locations=(
|
||||
"${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/utils.zsh"
|
||||
"$HOME/.dotfiles/zsh/lib/utils.zsh"
|
||||
)
|
||||
for loc in "${locations[@]}"; do
|
||||
[[ -f "$loc" ]] && { source "$loc"; return 0; }
|
||||
done
|
||||
|
||||
# Fallback defaults
|
||||
DF_RED=$'\033[0;31m' DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m'
|
||||
DF_BLUE=$'\033[0;34m' DF_CYAN=$'\033[0;36m' DF_NC=$'\033[0m'
|
||||
DF_GREY=$'\033[38;5;242m' DF_LIGHT_BLUE=$'\033[38;5;39m'
|
||||
DF_BOLD=$'\033[1m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
DF_WIDTH="${DF_WIDTH:-66}"
|
||||
}
|
||||
|
||||
_df_source_config
|
||||
|
||||
# ============================================================================
|
||||
# Header
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-sync"
|
||||
else
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local width="${DF_WIDTH:-66}"
|
||||
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo -e "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
echo -e "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}✦ ${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-sync${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Helper Functions
|
||||
# ============================================================================
|
||||
|
||||
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
|
||||
# ============================================================================
|
||||
|
||||
check_git_repo() {
|
||||
git -C "$DOTFILES_HOME" rev-parse --git-dir > /dev/null 2>&1 || { print_error "Not a git repository: $DOTFILES_HOME"; exit 1; }
|
||||
}
|
||||
|
||||
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')"
|
||||
|
||||
local status=$(get_sync_status)
|
||||
local local_commits="${status%:*}"
|
||||
local remote_commits="${status#*:}"
|
||||
|
||||
echo ""
|
||||
[[ $local_commits -gt 0 ]] && print_warning "$local_commits commit(s) ahead of remote"
|
||||
[[ $remote_commits -gt 0 ]] && print_warning "$remote_commits commit(s) behind remote"
|
||||
[[ $local_commits -eq 0 && $remote_commits -eq 0 ]] && print_success "In sync with remote"
|
||||
}
|
||||
|
||||
show_status_short() {
|
||||
cd "$DOTFILES_HOME"
|
||||
local changes=$(git status --porcelain | wc -l)
|
||||
local status=$(get_sync_status)
|
||||
local local_commits="${status%:*}"
|
||||
local remote_commits="${status#*:}"
|
||||
|
||||
if [[ $changes -gt 0 ]]; then
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Dotfiles: ${changes} local change(s) not pushed"
|
||||
elif [[ $local_commits -gt 0 ]]; then
|
||||
echo -e " ${DF_YELLOW}⚠${DF_NC} Dotfiles: ${local_commits} commit(s) not pushed"
|
||||
elif [[ $remote_commits -gt 0 ]]; then
|
||||
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
|
||||
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 -q .; then
|
||||
print_warning "No local changes to push"
|
||||
return
|
||||
fi
|
||||
|
||||
print_status "Staging changes..."
|
||||
git add -A
|
||||
|
||||
if [[ -z "$commit_msg" ]]; then
|
||||
read -p "Commit message: " commit_msg
|
||||
[[ -z "$commit_msg" ]] && { print_error "Commit cancelled"; return 1; }
|
||||
fi
|
||||
|
||||
git commit -m "$commit_msg"
|
||||
git push origin
|
||||
print_success "Changes pushed"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
check_git_repo
|
||||
|
||||
case "${1:-status}" in
|
||||
status)
|
||||
[[ "$2" == "-s" || "$2" == "--short" ]] && show_status_short || { print_header; show_status; }
|
||||
;;
|
||||
push)
|
||||
print_header; shift; push_changes "$*"
|
||||
;;
|
||||
pull)
|
||||
print_header; pull_changes
|
||||
;;
|
||||
-s|--short)
|
||||
show_status_short
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {status [-s]|push [message]|pull}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
111
refactor_backup/bin/dotfiles-update.sh
Executable file
111
refactor_backup/bin/dotfiles-update.sh
Executable file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env bash
|
||||
# ============================================================================
|
||||
# Update Dotfiles Script
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
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 ;;
|
||||
--help|-h)
|
||||
echo "Usage: dotfiles-update.sh [OPTIONS]"
|
||||
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"
|
||||
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"
|
||||
|
||||
if [[ -f "$DOTFILES_CONF" ]]; then
|
||||
source "$DOTFILES_CONF"
|
||||
else
|
||||
DOTFILES_DIR="$HOME/.dotfiles"
|
||||
DOTFILES_BRANCH="main"
|
||||
DOTFILES_RAW_URL="https://raw.githubusercontent.com/adlee-was-taken/dotfiles/main"
|
||||
fi
|
||||
|
||||
# Source shared colors and utils (provides DF_WIDTH)
|
||||
source "$DOTFILES_DIR/zsh/lib/utils.zsh" 2>/dev/null || \
|
||||
source "$DOTFILES_DIR/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m' DF_RED=$'\033[0;31m'
|
||||
DF_BLUE=$'\033[0;34m' DF_CYAN=$'\033[0;36m' DF_NC=$'\033[0m'
|
||||
DF_GREY=$'\033[38;5;242m' DF_LIGHT_BLUE=$'\033[38;5;39m'
|
||||
DF_BOLD=$'\033[1m' DF_DIM=$'\033[2m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
}
|
||||
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
readonly WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-update"
|
||||
else
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local hline="" && for ((i=0; i<WIDTH; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo -e "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
echo -e "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}✦ ${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-update${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
print_success() { echo -e "${DF_GREEN}✓${DF_NC} $1"; }
|
||||
print_warning() { echo -e "${DF_YELLOW}⚠${DF_NC} $1"; }
|
||||
print_error() { echo -e "${DF_RED}✗${DF_NC} $1"; }
|
||||
print_step() { echo -e "${DF_GREEN}==>${DF_NC} $1"; }
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
print_header
|
||||
|
||||
if [ ! -d "$DOTFILES_DIR" ]; then
|
||||
print_error "Dotfiles directory not found: $DOTFILES_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$DOTFILES_DIR"
|
||||
|
||||
print_step "Updating dotfiles from repository..."
|
||||
git pull origin "$DOTFILES_BRANCH"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Dotfiles updated successfully"
|
||||
|
||||
if [[ "$PULL_ONLY" == true ]]; then
|
||||
echo
|
||||
print_success "Pull complete (--pull-only mode)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo
|
||||
print_success "Update complete!"
|
||||
echo -e "Reload your shell: ${DF_CYAN}reload${DF_NC} or ${DF_CYAN}source ~/.zshrc${DF_NC}"
|
||||
else
|
||||
print_error "Failed to update dotfiles"
|
||||
exit 1
|
||||
fi
|
||||
90
refactor_backup/bin/dotfiles-vault.sh
Executable file
90
refactor_backup/bin/dotfiles-vault.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
# ============================================================================
|
||||
# Dotfiles Secrets Vault (Arch/CachyOS)
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
readonly DOTFILES_HOME="${DOTFILES_HOME:-$HOME/.dotfiles}"
|
||||
readonly VAULT_DIR="${HOME}/.dotfiles/vault"
|
||||
readonly VAULT_FILE="${VAULT_DIR}/secrets.enc"
|
||||
|
||||
# Source shared colors and utils (provides DF_WIDTH)
|
||||
source "$DOTFILES_HOME/zsh/lib/utils.zsh" 2>/dev/null || \
|
||||
source "$DOTFILES_HOME/zsh/lib/colors.zsh" 2>/dev/null || {
|
||||
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'
|
||||
}
|
||||
|
||||
# Use DF_WIDTH from utils.zsh or default to 66
|
||||
readonly WIDTH="${DF_WIDTH:-66}"
|
||||
|
||||
# ============================================================================
|
||||
# MOTD-style header
|
||||
# ============================================================================
|
||||
|
||||
print_header() {
|
||||
if declare -f df_print_header &>/dev/null; then
|
||||
df_print_header "dotfiles-vault "
|
||||
else
|
||||
local user="${USER:-root}"
|
||||
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||
local datetime=$(date '+%a %b %d %H:%M')
|
||||
local hline="" && for ((i=0; i<WIDTH; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo -e "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
echo -e "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}✦ ${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-vault${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
print_success() { echo -e "${DF_GREEN}✓${DF_NC} $1"; }
|
||||
print_error() { echo -e "${DF_RED}✗${DF_NC} $1" >&2; }
|
||||
print_section() { echo ""; echo -e "${DF_BLUE}▶${DF_NC} $1"; }
|
||||
|
||||
get_cipher() {
|
||||
command -v age &> /dev/null && echo "age" || \
|
||||
command -v gpg &> /dev/null && echo "gpg" || \
|
||||
{ print_error "No encryption tool available"; exit 1; }
|
||||
}
|
||||
|
||||
init_vault() {
|
||||
print_section "Initializing Vault"
|
||||
mkdir -p "$VAULT_DIR"
|
||||
chmod 700 "$VAULT_DIR"
|
||||
[[ ! -f "$VAULT_FILE" ]] && { echo "{}" > "$VAULT_FILE"; print_success "Vault initialized"; } || print_success "Vault exists"
|
||||
}
|
||||
|
||||
vault_list() {
|
||||
print_section "Secrets"
|
||||
[[ -f "$VAULT_FILE" ]] && cat "$VAULT_FILE" | grep -o '"[^"]*":' | sed 's/"//g;s/:$//' | while read key; do
|
||||
echo -e " ${DF_CYAN}•${DF_NC} $key"
|
||||
done || print_error "No vault file"
|
||||
echo ""
|
||||
}
|
||||
|
||||
vault_status() {
|
||||
print_section "Vault Status"
|
||||
[[ -d "$VAULT_DIR" ]] || { echo -e " ${DF_YELLOW}⚠${DF_NC} Vault not initialized"; return; }
|
||||
[[ -f "$VAULT_FILE" ]] || { echo -e " ${DF_YELLOW}⚠${DF_NC} Vault file not found"; return; }
|
||||
echo -e " ${DF_CYAN}Location:${DF_NC} $VAULT_FILE"
|
||||
echo -e " ${DF_CYAN}Encryption:${DF_NC} $(get_cipher)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
main() {
|
||||
print_header
|
||||
[[ ! -d "$VAULT_DIR" ]] && init_vault
|
||||
case "${1:-list}" in
|
||||
init) init_vault ;;
|
||||
list|ls) vault_list ;;
|
||||
status) vault_status ;;
|
||||
*) echo "Usage: $0 {init|list|status}"; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
102
refactor_backup/bin/dotfiles-version.sh
Executable file
102
refactor_backup/bin/dotfiles-version.sh
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env bash
|
||||
# ============================================================================
|
||||
# Dotfiles Version Checker
|
||||
# ============================================================================
|
||||
|
||||
# ============================================================================
|
||||
# Source Configuration
|
||||
# ============================================================================
|
||||
|
||||
_df_source_config() {
|
||||
local locations=(
|
||||
"${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/utils.zsh"
|
||||
"$HOME/.dotfiles/zsh/lib/utils.zsh"
|
||||
)
|
||||
for loc in "${locations[@]}"; do
|
||||
[[ -f "$loc" ]] && { source "$loc"; return 0; }
|
||||
done
|
||||
|
||||
# Fallback defaults
|
||||
DF_GREEN=$'\033[0;32m' DF_YELLOW=$'\033[1;33m' DF_CYAN=$'\033[0;36m'
|
||||
DF_NC=$'\033[0m' DF_GREY=$'\033[38;5;242m' DF_LIGHT_BLUE=$'\033[38;5;39m'
|
||||
DF_BOLD=$'\033[1m' DF_LIGHT_GREEN=$'\033[38;5;82m'
|
||||
DOTFILES_DIR="${DOTFILES_DIR:-$HOME/.dotfiles}"
|
||||
DOTFILES_VERSION="${DOTFILES_VERSION:-unknown}"
|
||||
DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
|
||||
DF_WIDTH="${DF_WIDTH:-66}"
|
||||
}
|
||||
|
||||
_df_source_config
|
||||
|
||||
# ============================================================================
|
||||
# Parse Arguments
|
||||
# ============================================================================
|
||||
|
||||
CHECK_ONLY=false
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--check|-c) CHECK_ONLY=true ;;
|
||||
--help|-h) echo "Usage: dotfiles-version.sh [--check]"; exit 0 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ============================================================================
|
||||
# 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="${DF_WIDTH:-66}"
|
||||
local hline="" && for ((i=0; i<width; i++)); do hline+="═"; done
|
||||
|
||||
echo ""
|
||||
echo -e "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||
echo -e "${DF_GREY}│${DF_NC} ${DF_BOLD}${DF_LIGHT_BLUE}✦ ${user}@${hostname}${DF_NC} ${DF_LIGHT_GREEN}dotfiles-version${DF_NC} ${datetime} ${DF_GREY}│${DF_NC}"
|
||||
echo -e "${DF_GREY}╘${hline}╛${DF_NC}"
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Version Info
|
||||
# ============================================================================
|
||||
|
||||
get_local_commit() {
|
||||
[[ -d "${DOTFILES_DIR}/.git" ]] && { cd "$DOTFILES_DIR"; git rev-parse --short HEAD 2>/dev/null || echo "unknown"; } || echo "not a git repo"
|
||||
}
|
||||
|
||||
get_local_date() {
|
||||
[[ -d "${DOTFILES_DIR}/.git" ]] && { cd "$DOTFILES_DIR"; git log -1 --format="%ci" 2>/dev/null | cut -d' ' -f1 || echo "unknown"; } || echo "unknown"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Main
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
local local_commit=$(get_local_commit)
|
||||
local local_date=$(get_local_date)
|
||||
|
||||
if [[ "$CHECK_ONLY" == true ]]; then
|
||||
echo "Version: $DOTFILES_VERSION ($local_commit)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
print_header
|
||||
|
||||
echo -e "${DF_CYAN}Local:${DF_NC}"
|
||||
echo -e " Version: ${DF_GREEN}${DOTFILES_VERSION}${DF_NC}"
|
||||
echo -e " Commit: ${local_commit}"
|
||||
echo -e " Date: ${local_date}"
|
||||
echo -e " Path: ${DOTFILES_DIR}"
|
||||
echo -e " Branch: ${DOTFILES_BRANCH}"
|
||||
echo -e " Width: ${DF_WIDTH}"
|
||||
echo
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user