1
0
Fork 0
dotfiles/.local/bin/dotsync

59 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-03-28 14:24:58 +02:00
#!/bin/sh
GREEN='\033[1;32m'
BLUE='\033[1;34m'
RED='\033[1;30m'
NC='\033[0m'
2023-03-28 19:13:13 +02:00
dotfiles="${1:-$HOME/.dotfiles}"
2023-03-28 14:24:58 +02:00
2023-03-29 00:08:17 +02:00
printf "${BLUE}Changing directory to $dotfiles${NC}\n"
2023-03-28 19:13:13 +02:00
if ! cd "$dotfiles"; then
2023-03-29 00:08:17 +02:00
printf "${RED}Could not CD into $dotfiles${NC}\n"
2023-03-28 19:16:12 +02:00
exit
2023-03-28 19:13:13 +02:00
fi
2023-03-29 00:08:17 +02:00
printf "\n"
2023-03-28 14:24:58 +02:00
2023-03-29 00:08:17 +02:00
printf "${BLUE}Stashing existing changes...${NC}\n"
2023-03-28 14:24:58 +02:00
stash_result=$(git stash push -m "sync-dotfiles: Before syncing dotfiles")
needs_pop=1
if [ "$stash_result" = "No local changes to save" ]; then
2023-03-28 19:16:12 +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-03-29 00:08:17 +02:00
printf "${BLUE}Pulling updates from dotfiles repo...${NC}\n"
2023-03-28 14:24:58 +02:00
git pull origin main
2023-03-28 20:58:23 +02:00
git submodule update --remote --recursive --init
2023-03-29 00:08:17 +02:00
printf "\n"
2023-03-28 14:24:58 +02:00
if [ $needs_pop -eq 1 ]; then
2023-03-29 00:08:17 +02:00
printf "${BLUE}Popping stashed changes...${NC}\n"
2023-03-28 19:16:12 +02:00
git 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
unmerged_files=$(git diff --name-only --diff-filter=U)
if [ -n "$unmerged_files" ]; then
2023-03-29 00:08:17 +02:00
printf "${RED}The following files have merge conflicts after popping the stash:${NC}\n"
printf "\n"
printf %"s\n" "$unmerged_files\n"
2023-03-28 14:24:58 +02:00
else
2023-03-29 00:08:17 +02:00
stow -t "$HOME" . || printf "${RED}Stow uninstalled or not in path!${NC}\n"
2023-03-28 14:24:58 +02:00
fi
2023-03-29 00:08:17 +02:00
printf "${BLUE}Generating librewolf profiles...${NC}\n"
$dotfiles/.librewolf/generate.sh
printf "\n"
printf "Recompile/Install src files? [y/N] \n"
read ans
[ $ans = "y" ] && for f in $dotfiles/.local/src/*; do
if ! cd "$f"; then
printf "${RED}Could not CD into $f${NC}\n"
exit
fi
sudo make install
done
printf "${GREEN}Dotfiles Synced Successfully!${NC}\n"