Add update-dotfiles utility
This commit is contained in:
parent
7fd2bc4192
commit
c91d7e0450
2 changed files with 85 additions and 2 deletions
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
export XDG_CACHE_HOME="$HOME/.cache"
|
||||
export XDG_CONFIG_HOME="$HOME/.config"
|
||||
export XDG_DATA_HOME="$HOME/.local/share" # also set in ~/.local/bin/{generate-shell-completions,install-dotfiles}
|
||||
export XDG_DATA_HOME="$HOME/.local/share" # also set in ~/.local/bin/{generate-shell-completions,install-dotfiles,update-dotfiles}
|
||||
export XDG_STATE_HOME="$HOME/.local/state" # also set in ~/.local/bin/generate-shell-completions
|
||||
|
||||
# Make up a XDG directory for binaries (that does not exist in the standard)
|
||||
|
|
@ -17,7 +17,7 @@ export XDG_BIN_HOME="$HOME/.local/bin" # also set in ~/.local/bin/install-dotfi
|
|||
|
||||
# Convenient names for various places in the system
|
||||
|
||||
export DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.local/bin/install-dotfiles
|
||||
export DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.local/bin/{install-dotfiles,update-dotfiles}
|
||||
|
||||
|
||||
# Generic shell configs
|
||||
|
|
|
|||
83
.local/bin/update-dotfiles
Executable file
83
.local/bin/update-dotfiles
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Replace the local `dotfiles` repository with a fresh install
|
||||
# by downloading and re-running the latest `install-dotfiles`
|
||||
#
|
||||
# Refuses to run if there are uncommitted or unpushed changes,
|
||||
# unless called with `--force`
|
||||
|
||||
set -eu
|
||||
|
||||
|
||||
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" # also set in ~/.config/shell/env
|
||||
|
||||
DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.config/shell/env
|
||||
|
||||
INSTALLER_URL="https://code.webartifex.de/alexander/dotfiles/raw/branch/main/.local/bin/install-dotfiles"
|
||||
|
||||
|
||||
force=0
|
||||
[ "${1:-}" = "--force" ] && force=1
|
||||
|
||||
|
||||
_git() {
|
||||
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" "$@"
|
||||
}
|
||||
|
||||
|
||||
branch="main"
|
||||
|
||||
|
||||
if [ -d "$DOTFILES_DIR" ]; then
|
||||
|
||||
# Keep the machine on its current branch (e.g., "desktop")
|
||||
branch=$(_git symbolic-ref --short HEAD)
|
||||
|
||||
if [ "$force" -ne 1 ]; then
|
||||
|
||||
if [ -n "$(_git status --porcelain)" ]; then
|
||||
echo ""
|
||||
echo "There are uncommitted changes!" >&2
|
||||
echo "" >&2
|
||||
_git --no-pager diff HEAD --stat >&2
|
||||
echo "" >&2
|
||||
echo "=> Commit and push them, or re-run with --force" >&2
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if _git rev-parse --verify --quiet "origin/$branch" >/dev/null \
|
||||
&& [ -n "$(_git log --oneline "origin/$branch..$branch")" ]; then
|
||||
echo ""
|
||||
echo "There are unpushed commits!" >&2
|
||||
echo "" >&2
|
||||
_git --no-pager log --oneline "origin/$branch..$branch" >&2
|
||||
echo "" >&2
|
||||
echo "=> Push them, or re-run with --force" >&2
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
installer=$(mktemp)
|
||||
trap 'rm -f "$installer"' EXIT
|
||||
|
||||
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fsSL "$INSTALLER_URL" -o "$installer"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -q "$INSTALLER_URL" -O "$installer"
|
||||
else
|
||||
echo ""
|
||||
echo "Neither curl nor wget are installed!" >&2
|
||||
echo "=> Install one of them" >&2
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
DOTFILES_BRANCH="$branch" FORCE_INSTALL=1 sh "$installer"
|
||||
Loading…
Reference in a new issue