cleanup dotsync script
This commit is contained in:
parent
562a9196de
commit
692b6e9e4d
|
@ -21,6 +21,7 @@ export LESS_TERMCAP_us="$(printf '%b' '[1;32m')"
|
|||
export LESS_TERMCAP_ue="$(printf '%b' '[0m')"
|
||||
export LESSOPEN="| /usr/bin/highlight -O ansi %s 2>/dev/null"
|
||||
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
|
||||
export NEWT_COLORS='
|
||||
|
@ -64,7 +65,6 @@ export XDG_CACHE_HOME="$HOME/.cache"
|
|||
export XDG_STATE_HOME="$HOME/.local/state"
|
||||
export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc"
|
||||
export STOW_DIR="$XDG_DATA_HOME/stow"
|
||||
export DOTS_DIR="$STOW_DIR/dots"
|
||||
|
||||
export WORKON_HOME="$XDG_DATA_HOME/virtualenv"
|
||||
export ZSH_COMPDUMP="$XDG_CACHE_HOME/zcompdump"
|
||||
|
|
|
@ -6,42 +6,42 @@ BLUE='\033[34m'
|
|||
RED='\033[31m'
|
||||
NC='\033[0m'
|
||||
|
||||
printf "%b" "$BOLD${BLUE}Changing directory to $DOTS_DIR$NC\n"
|
||||
if ! cd "$DOTS_DIR"; then
|
||||
printf "%b" "${RED}Could not CD into $DOTS_DIR$NC\n"
|
||||
exit
|
||||
fi
|
||||
printf "\n"
|
||||
dgit(){
|
||||
git -C "$STOW_DIR/$DOTS_PACKAGE" $@
|
||||
}
|
||||
|
||||
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"
|
||||
stash_result=$(git stash push -m "sync-dotfiles: Before syncing dotfiles")
|
||||
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"
|
||||
git pull origin main
|
||||
git submodule update --remote --merge
|
||||
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"
|
||||
git stash pop
|
||||
printf "%b" "${BOLD}${BLUE}Popping stashed changes...$NC\n"
|
||||
dgit stash pop
|
||||
fi
|
||||
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
|
||||
printf "%b" "${RED}The following files have merge conflicts after popping the stash:$NC\n"
|
||||
printf "\n"
|
||||
printf "%s" "$unmerged_files\n"
|
||||
else
|
||||
printf "%b" "$BOLD${BLUE}Symlinking dotfiles...$NC\n\n"
|
||||
stow -t "$HOME" dots || printf "%b" "${RED}Failed to run stow!$NC\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" "${BOLD}${BLUE}Reverting to previous commit...$NC"
|
||||
dgit checkout "$old_commit"
|
||||
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"
|
||||
|
|
Loading…
Reference in New Issue