diff --git a/bin/dotfiles-sync.sh b/bin/dotfiles-sync.sh index cab6f23..2ea914b 100755 --- a/bin/dotfiles-sync.sh +++ b/bin/dotfiles-sync.sh @@ -141,6 +141,31 @@ show_status() { fi } +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}" + 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" + 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 +} + show_diff() { print_section "Local Changes" @@ -175,6 +200,8 @@ pull_changes() { } push_changes() { + local commit_msg="$1" + print_section "Pushing Changes" cd "$DOTFILES_HOME" @@ -187,12 +214,15 @@ push_changes() { print_status "Staging changes..." git add -A - print_status "Enter commit message (or press Ctrl+C to cancel):" - read -p " > " commit_msg - + # If no commit message provided, prompt for one if [[ -z "$commit_msg" ]]; then - print_error "Commit cancelled" - return 1 + 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 fi print_status "Committing: $commit_msg" @@ -241,41 +271,61 @@ watch_sync() { # ============================================================================ main() { - print_header - check_git_repo check_git_config case "${1:-status}" in status) - show_status - show_diff + if [[ "$2" == "-s" || "$2" == "--short" ]]; then + show_status_short + else + print_header + show_status + show_diff + fi ;; push) - 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}" ;; + -s|--short) + show_status_short + ;; *) - echo "Usage: $0 {status|push|pull|diff|auto|watch [interval]}" + echo "Usage: $0 {status [-s]|push [message]|pull|diff|auto|watch [interval]}" echo "" echo "Commands:" - echo " status Show sync status (default)" - echo " push Push local changes" - 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 " 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" exit 1 ;; esac diff --git a/install.sh b/install.sh index 0d66a60..712b86f 100755 --- a/install.sh +++ b/install.sh @@ -123,19 +123,48 @@ CYAN='\033[0;36m' NC='\033[0m' # ============================================================================ -# Helper Functions +# MOTD-style header # ============================================================================ +_M_WIDTH=66 + print_header() { local user="${USER:-root}" - local hostname="${HOSTNAME:-localhost}" - local timestamp=$(date '+%a %b %d %H:%M') + local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}" + local script_name="install.sh" + local datetime=$(date '+%a %b %d %H:%M') + + # Colors + local _M_RESET=$'\033[0m' + local _M_BOLD=$'\033[1m' + local _M_DIM=$'\033[2m' + local _M_BLUE=$'\033[38;5;39m' + local _M_GREY=$'\033[38;5;242m' + + # Build horizontal line + local hline="" + for ((i=0; i<_M_WIDTH; i++)); do hline+="═"; done + local inner=$((_M_WIDTH - 2)) + + # Header content + local h_left="✦ ${user}@${hostname}" + local h_center="${script_name}" + local h_right="${datetime}" + local h_pad=$(((inner - ${#h_left} - ${#h_center} - ${#h_right}) / 2)) + local h_spaces="" + for ((i=0; i${NC} $1" } diff --git a/zsh/.zshrc b/zsh/.zshrc index 8f6aa07..7dbbcb8 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -305,8 +305,8 @@ _background_tasks() { # Check for dotfiles updates if [[ "${DOTFILES_AUTO_SYNC_CHECK:-true}" == "true" ]]; then # Use full path to avoid command_not_found issues - local sync_script="$_dotfiles_dir/bin/dotfiles-sync.sh" - [[ -x "$sync_script" ]] && "$sync_script" --auto 2>/dev/null &! + $_dotfiles_dir/bin/dotfiles-sync.sh status -s 2> /dev/null + #[[ -x "$sync_script" ]] && "$sync_script" --auto 2>/dev/null &! fi # Check number of available updates and export. diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index e4a0877..454c4b0 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -43,9 +43,9 @@ dffix() { _df_run dotfiles-doctor.sh --fix "$@"; } # Sync - multi-machine synchronization dfs() { _df_run dotfiles-sync.sh "$@"; } dfsync() { _df_run dotfiles-sync.sh "$@"; } -dfpush() { _df_run dotfiles-sync.sh --push "$@"; } -dfpull() { _df_run dotfiles-sync.sh --pull "$@"; } -dfstatus() { _df_run dotfiles-sync.sh --status "$@"; } +dfpush() { _df_run dotfiles-sync.sh push "${1:-Dotfiles update $(date '+%Y-%m-%d %H:%M')}"; } +dfpull() { _df_run dotfiles-sync.sh pull "$@"; } +dfstatus() { _df_run dotfiles-sync.sh status "$@"; } # Update - pull latest and reinstall dfu() { _df_run dotfiles-update.sh "$@"; }