Dotfiles update 2025-12-22 00:39
This commit is contained in:
@@ -141,6 +141,31 @@ show_status() {
|
|||||||
fi
|
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() {
|
show_diff() {
|
||||||
print_section "Local Changes"
|
print_section "Local Changes"
|
||||||
|
|
||||||
@@ -175,6 +200,8 @@ pull_changes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
push_changes() {
|
push_changes() {
|
||||||
|
local commit_msg="$1"
|
||||||
|
|
||||||
print_section "Pushing Changes"
|
print_section "Pushing Changes"
|
||||||
|
|
||||||
cd "$DOTFILES_HOME"
|
cd "$DOTFILES_HOME"
|
||||||
@@ -187,12 +214,15 @@ push_changes() {
|
|||||||
print_status "Staging changes..."
|
print_status "Staging changes..."
|
||||||
git add -A
|
git add -A
|
||||||
|
|
||||||
print_status "Enter commit message (or press Ctrl+C to cancel):"
|
# If no commit message provided, prompt for one
|
||||||
read -p " > " commit_msg
|
|
||||||
|
|
||||||
if [[ -z "$commit_msg" ]]; then
|
if [[ -z "$commit_msg" ]]; then
|
||||||
print_error "Commit cancelled"
|
print_status "Enter commit message (or press Ctrl+C to cancel):"
|
||||||
return 1
|
read -p " > " commit_msg
|
||||||
|
|
||||||
|
if [[ -z "$commit_msg" ]]; then
|
||||||
|
print_error "Commit cancelled"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "Committing: $commit_msg"
|
print_status "Committing: $commit_msg"
|
||||||
@@ -241,41 +271,61 @@ watch_sync() {
|
|||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
print_header
|
|
||||||
|
|
||||||
check_git_repo
|
check_git_repo
|
||||||
check_git_config
|
check_git_config
|
||||||
|
|
||||||
case "${1:-status}" in
|
case "${1:-status}" in
|
||||||
status)
|
status)
|
||||||
show_status
|
if [[ "$2" == "-s" || "$2" == "--short" ]]; then
|
||||||
show_diff
|
show_status_short
|
||||||
|
else
|
||||||
|
print_header
|
||||||
|
show_status
|
||||||
|
show_diff
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
push)
|
push)
|
||||||
push_changes
|
print_header
|
||||||
|
shift
|
||||||
|
push_changes "$*"
|
||||||
;;
|
;;
|
||||||
pull)
|
pull)
|
||||||
|
print_header
|
||||||
pull_changes
|
pull_changes
|
||||||
;;
|
;;
|
||||||
diff)
|
diff)
|
||||||
|
print_header
|
||||||
show_diff
|
show_diff
|
||||||
;;
|
;;
|
||||||
auto)
|
auto)
|
||||||
auto_sync
|
auto_sync
|
||||||
;;
|
;;
|
||||||
watch)
|
watch)
|
||||||
|
print_header
|
||||||
watch_sync "${2:-300}"
|
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 ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " status Show sync status (default)"
|
echo " status Show sync status (default)"
|
||||||
echo " push Push local changes"
|
echo " status -s Show abbreviated one-line status"
|
||||||
echo " pull Pull remote changes"
|
echo " push [message] Push local changes (prompts if no message)"
|
||||||
echo " diff Show local changes"
|
echo " pull Pull remote changes"
|
||||||
echo " auto Automatically sync (pull remote)"
|
echo " diff Show local changes"
|
||||||
echo " watch [sec] Auto-sync every N seconds (default: 300)"
|
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
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
37
install.sh
37
install.sh
@@ -123,19 +123,48 @@ CYAN='\033[0;36m'
|
|||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Helper Functions
|
# MOTD-style header
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
|
_M_WIDTH=66
|
||||||
|
|
||||||
print_header() {
|
print_header() {
|
||||||
local user="${USER:-root}"
|
local user="${USER:-root}"
|
||||||
local hostname="${HOSTNAME:-localhost}"
|
local hostname="${HOSTNAME:-$(hostname -s 2>/dev/null)}"
|
||||||
local timestamp=$(date '+%a %b %d %H:%M')
|
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 ""
|
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 ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Helper Functions
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
print_step() {
|
print_step() {
|
||||||
echo -e "${GREEN}==>${NC} $1"
|
echo -e "${GREEN}==>${NC} $1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -305,8 +305,8 @@ _background_tasks() {
|
|||||||
# Check for dotfiles updates
|
# Check for dotfiles updates
|
||||||
if [[ "${DOTFILES_AUTO_SYNC_CHECK:-true}" == "true" ]]; then
|
if [[ "${DOTFILES_AUTO_SYNC_CHECK:-true}" == "true" ]]; then
|
||||||
# Use full path to avoid command_not_found issues
|
# Use full path to avoid command_not_found issues
|
||||||
local sync_script="$_dotfiles_dir/bin/dotfiles-sync.sh"
|
$_dotfiles_dir/bin/dotfiles-sync.sh status -s 2> /dev/null
|
||||||
[[ -x "$sync_script" ]] && "$sync_script" --auto 2>/dev/null &!
|
#[[ -x "$sync_script" ]] && "$sync_script" --auto 2>/dev/null &!
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check number of available updates and export.
|
# Check number of available updates and export.
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ dffix() { _df_run dotfiles-doctor.sh --fix "$@"; }
|
|||||||
# Sync - multi-machine synchronization
|
# Sync - multi-machine synchronization
|
||||||
dfs() { _df_run dotfiles-sync.sh "$@"; }
|
dfs() { _df_run dotfiles-sync.sh "$@"; }
|
||||||
dfsync() { _df_run dotfiles-sync.sh "$@"; }
|
dfsync() { _df_run dotfiles-sync.sh "$@"; }
|
||||||
dfpush() { _df_run dotfiles-sync.sh --push "$@"; }
|
dfpush() { _df_run dotfiles-sync.sh push "${1:-Dotfiles update $(date '+%Y-%m-%d %H:%M')}"; }
|
||||||
dfpull() { _df_run dotfiles-sync.sh --pull "$@"; }
|
dfpull() { _df_run dotfiles-sync.sh pull "$@"; }
|
||||||
dfstatus() { _df_run dotfiles-sync.sh --status "$@"; }
|
dfstatus() { _df_run dotfiles-sync.sh status "$@"; }
|
||||||
|
|
||||||
# Update - pull latest and reinstall
|
# Update - pull latest and reinstall
|
||||||
dfu() { _df_run dotfiles-update.sh "$@"; }
|
dfu() { _df_run dotfiles-update.sh "$@"; }
|
||||||
|
|||||||
Reference in New Issue
Block a user