1
0
Fork 0

cleanup dotsync script

This commit is contained in:
Luca Bilke 2023-12-14 13:48:10 +01:00
parent 562a9196de
commit 692b6e9e4d
2 changed files with 23 additions and 23 deletions

View File

@ -21,6 +21,7 @@ export LESS_TERMCAP_us="$(printf '%b' '')"
export LESS_TERMCAP_ue="$(printf '%b' '')" export LESS_TERMCAP_ue="$(printf '%b' '')"
export LESSOPEN="| /usr/bin/highlight -O ansi %s 2>/dev/null" export LESSOPEN="| /usr/bin/highlight -O ansi %s 2>/dev/null"
export ANSIBLE_NOCOWS=1 # Stop those fucking cows in Ansible export ANSIBLE_NOCOWS=1 # Stop those fucking cows in Ansible
export DOTS_PACKAGE="dots"
# Color palette for console dialogs in tools such as nmtui and whiptail # Color palette for console dialogs in tools such as nmtui and whiptail
export NEWT_COLORS=' export NEWT_COLORS='
@ -64,7 +65,6 @@ export XDG_CACHE_HOME="$HOME/.cache"
export XDG_STATE_HOME="$HOME/.local/state" export XDG_STATE_HOME="$HOME/.local/state"
export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc" export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc"
export STOW_DIR="$XDG_DATA_HOME/stow" export STOW_DIR="$XDG_DATA_HOME/stow"
export DOTS_DIR="$STOW_DIR/dots"
export WORKON_HOME="$XDG_DATA_HOME/virtualenv" export WORKON_HOME="$XDG_DATA_HOME/virtualenv"
export ZSH_COMPDUMP="$XDG_CACHE_HOME/zcompdump" export ZSH_COMPDUMP="$XDG_CACHE_HOME/zcompdump"

View File

@ -6,42 +6,42 @@ BLUE='\033[34m'
RED='\033[31m' RED='\033[31m'
NC='\033[0m' NC='\033[0m'
printf "%b" "$BOLD${BLUE}Changing directory to $DOTS_DIR$NC\n" dgit(){
if ! cd "$DOTS_DIR"; then git -C "$STOW_DIR/$DOTS_PACKAGE" $@
printf "%b" "${RED}Could not CD into $DOTS_DIR$NC\n" }
exit
fi
printf "\n"
stow -D -t "$HOME" dots || printf "%b" "${RED}Failed to run stow!$NC\n" 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" printf "%b" "${BOLD}${BLUE}Stashing existing changes...$NC\n"
stash_result=$(git stash push -m "sync-dotfiles: Before syncing dotfiles") stash_result=$(dgit 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"
printf "%b" "$BOLD${BLUE}Pulling updates from dotfiles repo...$NC\n" printf "%b" "${BOLD}${BLUE}Pulling updates from dotfiles repo...$NC\n"
git pull origin main old_commit="$(dgit rev-parse HEAD)"
git submodule update --remote --merge dgit pull origin main
dgit 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"
git stash pop dgit stash pop
fi fi
printf "\n" printf "\n"
unmerged_files=$(git diff --name-only --diff-filter=U) unmerged_files=$(dgit 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" printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n\n"
printf "\n" printf "%s" "$unmerged_files\n\n"
printf "%s" "$unmerged_files\n" printf "%s" "${BOLD}${BLUE}Reverting to previous commit...$NC"
else dgit checkout "$old_commit"
printf "%b" "$BOLD${BLUE}Symlinking dotfiles...$NC\n\n"
stow -t "$HOME" dots || printf "%b" "${RED}Failed to run stow!$NC\n"
fi fi
printf "%b" "$BOLD${BLUE}Dotfiles Synced Successfully!$NC\n" 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"