vimconfig/import
2024-07-03 20:25:29 +09:30

50 lines
993 B
Bash
Executable File

#! /bin/bash
set -eu
function check_clean() {
if ! git diff-index --quiet HEAD -- ; then
echo "Git repository is dirty, aborting."
git status --short --untracked-files=no
exit 1
fi
}
function dry_run() {
rsync -HPrlm \
--itemize-changes \
--dry-run \
--files-from=./tracked-files \
--exclude-from=./.gitignore \
"${source}" "${destination}"
}
source=${HOME}
repo_root=$(git rev-parse --show-toplevel)
destination="${1:-$repo_root}"
echo "Importing working dotfiles to $destination"
dry_run
if [ -z "${1+x}" ]; then
echo "Performing git repository check..."
check_clean
fi
if [ -z "${2+x}" ]; then
read -r -p "Are you sure? [y/N] " response
response=${response,,}
else
response=$2
fi
if [[ "$response" =~ ^(yes|y)$ ]]; then
rsync -HPrlm \
--itemize-changes \
--files-from=./tracked-files \
--exclude-from=./.gitignore \
"${source}" "${destination}"
fi