1
0
Fork 0

dotsync: use tabs rather than spaces

This commit is contained in:
Luca Bilke 2024-10-17 11:17:22 +02:00
commit b4ad04e6be
Signed by: luca
GPG key ID: F6E11C9BAA7C82F5

View file

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
# vim: set noexpandtab:
BOLD="$(tput bold)" BOLD="$(tput bold)"
RED="$(tput setaf 1)" RED="$(tput setaf 1)"
@ -7,71 +8,71 @@ BLUE="$(tput setaf 4)"
NC="$(tput sgr0)" NC="$(tput sgr0)"
stow_git() { stow_git() {
git -C "$STOW_DIR" "$@" git -C "$STOW_DIR" "$@"
} }
multi_stow() { multi_stow() {
ret=0 ret=0
hostname=$(hostname) hostname=$(hostname)
if [ -e "${STOW_DIR}/$hostname" ]; then if [ -e "${STOW_DIR}/$hostname" ]; then
host_package=$hostname host_package=$hostname
else else
host_package="fallback" host_package="fallback"
fi fi
for package in common ${host_package}; do for package in common ${host_package}; do
stow --no-folding -d "$STOW_DIR" -t "$HOME" "$@" "$package" stow --no-folding -d "$STOW_DIR" -t "$HOME" "$@" "$package"
ret=$((ret + $?)) ret=$((ret + $?))
done done
return $ret return $ret
} }
first_clone() { first_clone() {
[ -r "${HOME}/.secrets/dotfile-secrets.json" ] || { [ -r "${HOME}/.secrets/dotfile-secrets.json" ] || {
echo "Please ensure ${HOME}/.secrets/dotfile-secrets.json exists and is readable" echo "Please ensure ${HOME}/.secrets/dotfile-secrets.json exists and is readable"
exit 1 exit 1
} }
which jq >/dev/null || { which jq >/dev/null || {
echo "Please ensure jq is installed" echo "Please ensure jq is installed"
exit 1 exit 1
} }
filter_file=$(mktemp) filter_file=$(mktemp)
cat <<'EOF' >"$filter_file" cat <<-'EOF' >"$filter_file"
#!/bin/sh #!/bin/sh
FS="#" FS="#"
GS="|" GS="|"
map=$(jq -r 'to_entries[] | "\(.key)'"$FS"'\(.value)"' "${HOME}/.secrets/dotfile-secrets.json") map=$(jq -r 'to_entries[] | "\(.key)'"$FS"'\(.value)"' "${HOME}/.secrets/dotfile-secrets.json")
if [ "$1" = "clean" ]; then if [ "$1" = "clean" ]; then
sed "$(echo "$map" | awk -F"$FS" -v d="$GS" '{printf "s%s%s%s<#%s#>%sg;", d, $2, d, $1, d }')" sed "$(echo "$map" | awk -F"$FS" -v d="$GS" '{printf "s%s%s%s<#%s#>%sg;", d, $2, d, $1, d }')"
elif [ "$1" = "smudge" ]; then elif [ "$1" = "smudge" ]; then
sed "$(echo "$map" | awk -F"$FS" -v d="$GS" '{printf "s%s<#%s#>%s%s%sg;", d, $1, d, $2, d }')" sed "$(echo "$map" | awk -F"$FS" -v d="$GS" '{printf "s%s<#%s#>%s%s%sg;", d, $1, d, $2, d }')"
fi fi
EOF EOF
chmod +x "$filter_file" chmod +x "$filter_file"
touch "${HOME}/.gitconfig" touch "${HOME}/.gitconfig"
git config --global filter.redact.clean "$filter_file clean" git config --global filter.redact.clean "$filter_file clean"
git config --global filter.redact.smudge "$filter_file smudge" git config --global filter.redact.smudge "$filter_file smudge"
git clone -j4 --recursive "$STOW_REPO" "$STOW_DIR" git clone -j4 --recursive "$STOW_REPO" "$STOW_DIR"
rm "$filter_file" "${HOME}/.gitconfig" rm "$filter_file" "${HOME}/.gitconfig"
} }
{ [ -n "$STOW_DIR" ] && [ -n "$STOW_REPO" ] && [ -n "$STOW_BRANCH" ]; } || { { [ -n "$STOW_DIR" ] && [ -n "$STOW_REPO" ] && [ -n "$STOW_BRANCH" ]; } || {
echo "Please set STOW_DIR, STOW_REPO, and STOW_BRANCH" echo "Please set STOW_DIR, STOW_REPO, and STOW_BRANCH"
exit 1 exit 1
} }
mkdir -p "$STOW_DIR" mkdir -p "$STOW_DIR"
# First run # First run
if [ ! -e "$STOW_DIR/.git" ]; then if [ ! -e "$STOW_DIR/.git" ]; then
printf "%b" "${BOLD}${BLUE}Cloning dotfiles...$NC\n\n" printf "%b" "${BOLD}${BLUE}Cloning dotfiles...$NC\n\n"
first_clone first_clone
multi_stow || printf "%b" "${RED}Failed to run stow!$NC\n" multi_stow || printf "%b" "${RED}Failed to run stow!$NC\n"
exit 0 exit 0
fi fi
printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...$NC\n\n" printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...$NC\n\n"
@ -81,7 +82,7 @@ printf "%b" "${BOLD}${BLUE}Stashing existing changes...$NC\n"
stash_result=$(stow_git stash push) stash_result=$(stow_git stash push)
needs_pop=1 needs_pop=1
if [ "$stash_result" = "No local changes to save" ]; then if [ "$stash_result" = "No local changes to save" ]; then
needs_pop=0 needs_pop=0
fi fi
printf "\n" printf "\n"
@ -92,17 +93,17 @@ stow_git submodule update --remote --merge
printf "\n" printf "\n"
if [ $needs_pop -eq 1 ]; then if [ $needs_pop -eq 1 ]; then
printf "%b" "${BOLD}${BLUE}Popping stashed changes...$NC\n" printf "%b" "${BOLD}${BLUE}Popping stashed changes...$NC\n"
stow_git stash pop stow_git stash pop
fi fi
printf "\n" printf "\n"
unmerged_files=$(stow_git diff --name-only --diff-filter=U) unmerged_files=$(stow_git diff --name-only --diff-filter=U)
if [ -n "$unmerged_files" ]; then if [ -n "$unmerged_files" ]; then
printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n\n" printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n\n"
printf "%s" "$unmerged_files\n\n" printf "%s" "$unmerged_files\n\n"
printf "%s" "${BOLD}${BLUE}Reverting to previous commit...$NC" printf "%s" "${BOLD}${BLUE}Reverting to previous commit...$NC"
stow_git checkout "$old_commit" stow_git checkout "$old_commit"
fi fi
printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...$NC\n\n" printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...$NC\n\n"