dot/update.sh

38 lines
1.2 KiB
Bash
Raw Normal View History

2024-06-18 11:40:44 +00:00
#!/bin/bash
#
# minimal dotfile manager
# tracks files / copies them into the repo, sorted by hostname
#
2024-06-18 13:41:09 +00:00
# note: assumes pwd is this repo before running this script
2024-06-18 13:28:13 +00:00
set -u
2024-06-18 11:40:44 +00:00
# array of files [relative to home] to include
DOTS=(
'.vimrc'
'.config/nvim/init.vim'
'.config/nvim/coc-settings.json'
2024-06-18 13:28:13 +00:00
'.config/autostart-i3ipc.yml'
'.config/sway'
2024-06-18 11:40:44 +00:00
)
# ensure the host running this script/updating dotfiles has a directory
# ... then temporarily change into it for working, or exit.
# if it couldn't be made/entered [for whatever reason], we won't be able to copy.
[ -d "$HOSTNAME" ] || mkdir -v "$HOSTNAME"
pushd "$HOSTNAME" || exit
2024-06-18 13:28:13 +00:00
echo "Changed working dir to $PWD"
2024-06-18 11:40:44 +00:00
# now that the host/working dir is managed, process the dotfiles
# ensure their directory structure is retained, then recursively copy
for DOT in "${DOTS[@]}"; do
DOT_DIR="$(dirname "$DOT")"
[ -d "$DOT_DIR" ] || mkdir -vp "$DOT_DIR"
2024-06-18 13:28:13 +00:00
# naively 'copy' with rsync; rely on git to tell us about changes. TODO: reconsider
echo "Copying '$HOME/$DOT' to '$DOT'"
rsync -aqv "$HOME/$DOT" "$DOT" || echo "Couldn't copy '$DOT', got rc: $?"
2024-06-18 11:40:44 +00:00
done
# return where we were
popd || exit