Dotfiles update 2025-12-22 00:39
This commit is contained in:
@@ -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,6 +214,8 @@ push_changes() {
|
||||
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
|
||||
|
||||
@@ -194,6 +223,7 @@ push_changes() {
|
||||
print_error "Commit cancelled"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
print_status "Committing: $commit_msg"
|
||||
git commit -m "$commit_msg"
|
||||
@@ -241,41 +271,61 @@ watch_sync() {
|
||||
# ============================================================================
|
||||
|
||||
main() {
|
||||
print_header
|
||||
|
||||
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
|
||||
;;
|
||||
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 " 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
|
||||
|
||||
37
install.sh
37
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<h_pad; i++)); do h_spaces+=" "; done
|
||||
|
||||
echo ""
|
||||
printf "${CYAN}+ ${NC}%-20s %30s %25s\n" "$user@$hostname" "install.sh" "$timestamp"
|
||||
echo -e "${_M_GREY}╒${hline}╕${_M_RESET}"
|
||||
echo -e "${_M_GREY}│${_M_RESET} ${_M_BOLD}${_M_BLUE}${h_left}${_M_RESET}${h_spaces}${_M_DIM}${h_center}${h_spaces}${h_right}${_M_RESET} ${_M_GREY}│${_M_RESET}"
|
||||
echo -e "${_M_GREY}╘${hline}╛${_M_RESET}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Helper Functions
|
||||
# ============================================================================
|
||||
|
||||
print_step() {
|
||||
echo -e "${GREEN}==>${NC} $1"
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 "$@"; }
|
||||
|
||||
Reference in New Issue
Block a user