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