2023-03-28 14:24:58 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-01-31 00:55:55 +01:00
|
|
|
BOLD="$(tput bold)"
|
|
|
|
RED="$(tput setaf 1)"
|
|
|
|
GREEN="$(tput setaf 2)"
|
|
|
|
BLUE="$(tput setaf 4)"
|
|
|
|
NC="$(tput sgr0)"
|
2023-05-29 22:20:46 +02:00
|
|
|
|
2024-05-23 18:26:13 +02:00
|
|
|
target=$HOME
|
|
|
|
gitdir=$target/.local/share/dots
|
|
|
|
|
|
|
|
mkdir -p "$(dirname "$gitdir")"
|
|
|
|
|
|
|
|
baregit() {
|
|
|
|
git --git-dir="$gitdir" --work-tree="$target" "$@"
|
2023-12-14 13:48:10 +01:00
|
|
|
}
|
2023-03-28 14:24:58 +02:00
|
|
|
|
2024-05-23 18:26:13 +02:00
|
|
|
[ -e "$gitdir" ] || {
|
|
|
|
printf "%b" "${BOLD}${BLUE}Cloning dotfiles...$NC\n"
|
|
|
|
|
|
|
|
git clone --bare git@git.snaile.de:luca/dotfiles "$gitdir"
|
|
|
|
baregit checkout
|
2024-05-23 18:57:09 +02:00
|
|
|
# baregit config status.showUntrackedFiles no
|
2024-05-23 18:26:13 +02:00
|
|
|
|
|
|
|
cd "$target" || exit
|
|
|
|
for f in *; do
|
|
|
|
[ "$f" = ".config" ] || [ "$f" = ".local" ] && {
|
|
|
|
echo "$f" >>"$gitdir/info/exclude"
|
|
|
|
rm -rf "$f"
|
|
|
|
}
|
|
|
|
done
|
|
|
|
cd - || exit
|
2024-05-23 18:57:09 +02:00
|
|
|
cat <<EOF >>"$gitdir/info/exclude"
|
|
|
|
/*
|
2024-05-23 18:26:13 +02:00
|
|
|
|
2024-05-23 18:57:09 +02:00
|
|
|
!/\.config
|
|
|
|
|
|
|
|
!/\.local
|
|
|
|
/\.local/share/dots
|
|
|
|
/\.local/share/service
|
|
|
|
EOF
|
2024-05-23 18:26:13 +02:00
|
|
|
echo ".local/share/dots" >>"$gitdir/info/exclude"
|
|
|
|
}
|
2023-11-23 21:26:03 +01:00
|
|
|
|
2023-12-14 13:48:10 +01:00
|
|
|
printf "%b" "${BOLD}${BLUE}Stashing existing changes...$NC\n"
|
2024-05-23 18:26:13 +02:00
|
|
|
stash_result=$(baregit stash push)
|
2023-03-28 14:24:58 +02:00
|
|
|
needs_pop=1
|
|
|
|
if [ "$stash_result" = "No local changes to save" ]; then
|
2024-05-23 18:26:13 +02:00
|
|
|
needs_pop=0
|
2023-03-28 14:24:58 +02:00
|
|
|
fi
|
2023-03-29 00:08:17 +02:00
|
|
|
printf "\n"
|
2023-03-28 14:24:58 +02:00
|
|
|
|
2023-12-14 13:48:10 +01:00
|
|
|
printf "%b" "${BOLD}${BLUE}Pulling updates from dotfiles repo...$NC\n"
|
2024-05-23 18:26:13 +02:00
|
|
|
old_commit="$(baregit rev-parse HEAD)"
|
|
|
|
baregit pull origin main
|
|
|
|
baregit submodule update --remote --merge
|
2023-03-29 00:08:17 +02:00
|
|
|
printf "\n"
|
2023-03-28 14:24:58 +02:00
|
|
|
|
2023-03-28 14:31:21 +02:00
|
|
|
if [ $needs_pop -eq 1 ]; then
|
2024-05-23 18:26:13 +02:00
|
|
|
printf "%b" "${BOLD}${BLUE}Popping stashed changes...$NC\n"
|
|
|
|
baregit stash pop
|
2023-03-28 14:24:58 +02:00
|
|
|
fi
|
2023-03-29 00:08:17 +02:00
|
|
|
printf "\n"
|
2023-03-28 14:24:58 +02:00
|
|
|
|
2024-05-23 18:26:13 +02:00
|
|
|
unmerged_files=$(baregit diff --name-only --diff-filter=U)
|
2023-03-28 14:31:21 +02:00
|
|
|
if [ -n "$unmerged_files" ]; then
|
2024-05-23 18:26:13 +02:00
|
|
|
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"
|
|
|
|
baregit checkout "$old_commit"
|
2023-03-28 14:24:58 +02:00
|
|
|
fi
|
|
|
|
|
2023-12-14 13:48:10 +01:00
|
|
|
printf "%b" "${BOLD}${GREEN}Dotfiles synced successfully!$NC\n"
|
2024-05-23 18:26:13 +02:00
|
|
|
|
|
|
|
# BOLD="$(tput bold)"
|
|
|
|
# RED="$(tput setaf 1)"
|
|
|
|
# GREEN="$(tput setaf 2)"
|
|
|
|
# BLUE="$(tput setaf 4)"
|
|
|
|
# NC="$(tput sgr0)"
|
|
|
|
#
|
|
|
|
# dgit() {
|
|
|
|
# git -C "$STOW_DIR/$DOTS_PACKAGE" "$@"
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# printf "%b" "${BOLD}${BLUE}Removing dotfile symlinks...$NC\n\n"
|
|
|
|
# stow -D -d "$STOW_DIR" -t "$HOME" "$DOTS_PACKAGE" || printf "%b" "${RED}Failed to run stow!$NC\n"
|
|
|
|
#
|
|
|
|
# printf "%b" "${BOLD}${BLUE}Stashing existing changes...$NC\n"
|
|
|
|
# stash_result=$(dgit stash push)
|
|
|
|
# needs_pop=1
|
|
|
|
# if [ "$stash_result" = "No local changes to save" ]; then
|
|
|
|
# needs_pop=0
|
|
|
|
# fi
|
|
|
|
# printf "\n"
|
|
|
|
#
|
|
|
|
# printf "%b" "${BOLD}${BLUE}Pulling updates from dotfiles repo...$NC\n"
|
|
|
|
# old_commit="$(dgit rev-parse HEAD)"
|
|
|
|
# dgit pull origin main
|
|
|
|
# dgit submodule update --remote --merge
|
|
|
|
# printf "\n"
|
|
|
|
#
|
|
|
|
# if [ $needs_pop -eq 1 ]; then
|
|
|
|
# printf "%b" "${BOLD}${BLUE}Popping stashed changes...$NC\n"
|
|
|
|
# dgit stash pop
|
|
|
|
# fi
|
|
|
|
# printf "\n"
|
|
|
|
#
|
|
|
|
# unmerged_files=$(dgit 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"
|
|
|
|
# dgit checkout "$old_commit"
|
|
|
|
# fi
|
|
|
|
#
|
|
|
|
# printf "%b" "${BOLD}${BLUE}Symlinking dotfiles...$NC\n\n"
|
|
|
|
# stow -d "$STOW_DIR" -t "$HOME" "$DOTS_PACKAGE" || printf "%b" "${RED}Failed to run stow!$NC\n"
|
|
|
|
#
|
|
|
|
# printf "%b" "${BOLD}${GREEN}Dotfiles synced successfully!$NC\n"
|