refactor: simplify dotfiles configuration
check / validate (push) Canceled after 0s

This commit is contained in:
2026-08-12 15:57:01 +00:00
parent 56b90dad19
commit 2928ef3bc0
97 changed files with 740 additions and 5610 deletions
+34 -11
View File
@@ -1,18 +1,41 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
app_dir="$HOME/dotfiles"
set -Eeuo pipefail
warn() {
echo "$1" >&2
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" 2>/dev/null && pwd -P || true)"
if [[ -n "$SCRIPT_DIR" && -e "$SCRIPT_DIR/.git" ]]; then
APP_PATH="${APP_PATH:-$SCRIPT_DIR}"
else
APP_PATH="${APP_PATH:-$HOME/.dotfiles}"
fi
readonly APP_PATH
readonly MANAGED_START='# >>> dotfiles >>>'
readonly MANAGED_END='# <<< dotfiles <<<'
remove_managed_link() {
local target=$1 expected=$2
if [[ -L "$target" && "$(readlink "$target")" == "$expected" ]]; then
rm -- "$target"
printf 'Removed %s\n' "$target"
fi
}
die() {
warn "$1"
exit 1
remove_managed_block() {
local file=$1 temp
[[ -f "$file" ]] || return
temp=$(mktemp)
awk -v start="$MANAGED_START" -v end="$MANAGED_END" '
$0 == start { managed = 1; next }
$0 == end { managed = 0; next }
!managed { print }
' "$file" > "$temp"
cat "$temp" > "$file"
rm -f "$temp"
}
rm $HOME/.vimrc
rm $HOME/.vimrc.bundles
rm $HOME/.vim
remove_managed_link "$HOME/.vimrc" "$APP_PATH/.vimrc"
remove_managed_link "$HOME/.tmux.conf" "$APP_PATH/.tmux.conf"
remove_managed_block "$HOME/.bashrc"
rm -rf $app_dir
printf '%s\n' 'Dotfile links and the managed Bash block were removed.'
printf '%s\n' 'The repository, Vim data/plugins, TPM, and backups were retained.'