Dotfiles update 2025-12-25 12:04
This commit is contained in:
@@ -5,50 +5,15 @@
|
||||
|
||||
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
|
||||
# Source bootstrap (provides colors, config, and utility functions)
|
||||
source "${DOTFILES_HOME:-$HOME/.dotfiles}/zsh/lib/bootstrap.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_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
|
||||
df_print_header() { echo "=== $1 ==="; }
|
||||
df_print_success() { echo -e "${DF_GREEN}✓${DF_NC} $1"; }
|
||||
df_print_error() { echo -e "${DF_RED}✗${DF_NC} $1" >&2; }
|
||||
df_print_warning() { echo -e "${DF_YELLOW}⚠${DF_NC} $1"; }
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -56,9 +21,6 @@ print_header() {
|
||||
# ============================================================================
|
||||
|
||||
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"; }
|
||||
|
||||
# ============================================================================
|
||||
@@ -66,7 +28,10 @@ print_section() { echo ""; echo -e "${DF_BLUE}▶${DF_NC} $1"; }
|
||||
# ============================================================================
|
||||
|
||||
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; }
|
||||
if ! git -C "$DOTFILES_HOME" rev-parse --git-dir > /dev/null 2>&1; then
|
||||
df_print_error "Not a git repository: $DOTFILES_HOME"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
get_sync_status() {
|
||||
@@ -79,6 +44,7 @@ get_sync_status() {
|
||||
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')"
|
||||
|
||||
@@ -87,9 +53,9 @@ show_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"
|
||||
[[ $local_commits -gt 0 ]] && df_print_warning "$local_commits commit(s) ahead of remote"
|
||||
[[ $remote_commits -gt 0 ]] && df_print_warning "$remote_commits commit(s) behind remote"
|
||||
[[ $local_commits -eq 0 && $remote_commits -eq 0 ]] && df_print_success "In sync with remote"
|
||||
}
|
||||
|
||||
show_status_short() {
|
||||
@@ -111,9 +77,15 @@ show_status_short() {
|
||||
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"
|
||||
|
||||
if git pull origin; then
|
||||
df_print_success "Changes pulled"
|
||||
else
|
||||
df_print_success "Already up to date"
|
||||
fi
|
||||
}
|
||||
|
||||
push_changes() {
|
||||
@@ -122,7 +94,7 @@ push_changes() {
|
||||
cd "$DOTFILES_HOME"
|
||||
|
||||
if ! git status --porcelain | grep -q .; then
|
||||
print_warning "No local changes to push"
|
||||
df_print_warning "No local changes to push"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -131,12 +103,12 @@ push_changes() {
|
||||
|
||||
if [[ -z "$commit_msg" ]]; then
|
||||
read -p "Commit message: " commit_msg
|
||||
[[ -z "$commit_msg" ]] && { print_error "Commit cancelled"; return 1; }
|
||||
[[ -z "$commit_msg" ]] && { df_print_error "Commit cancelled"; return 1; }
|
||||
fi
|
||||
|
||||
git commit -m "$commit_msg"
|
||||
git push origin
|
||||
print_success "Changes pushed"
|
||||
df_print_success "Changes pushed"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
@@ -148,19 +120,40 @@ main() {
|
||||
|
||||
case "${1:-status}" in
|
||||
status)
|
||||
[[ "$2" == "-s" || "$2" == "--short" ]] && show_status_short || { print_header; show_status; }
|
||||
if [[ "$2" == "-s" || "$2" == "--short" ]]; then
|
||||
show_status_short
|
||||
else
|
||||
df_print_header "dotfiles-sync"
|
||||
show_status
|
||||
fi
|
||||
;;
|
||||
push)
|
||||
print_header; shift; push_changes "$*"
|
||||
df_print_header "dotfiles-sync"
|
||||
shift
|
||||
push_changes "$*"
|
||||
;;
|
||||
pull)
|
||||
print_header; pull_changes
|
||||
df_print_header "dotfiles-sync"
|
||||
pull_changes
|
||||
;;
|
||||
-s|--short)
|
||||
show_status_short
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: dotfiles-sync.sh [COMMAND]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " status [-s] Show sync status (default)"
|
||||
echo " push [message] Push changes to remote"
|
||||
echo " pull Pull changes from remote"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -s, --short Short status output"
|
||||
echo " --help Show this help"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {status [-s]|push [message]|pull}"
|
||||
echo "Unknown command: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user