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

60 lines
1.5 KiB
Text
Raw Normal View History

2023-03-28 14:24:58 +02:00
#!/bin/sh
2023-04-12 11:37:10 +02:00
GREEN='\e[1;32m'
BLUE='\e[1;34m'
RED='\e[1;30m'
NC='\e[0m'
2023-03-28 19:13:13 +02:00
dotfiles="${1:-$HOME/.dotfiles}"
2023-03-28 14:24:58 +02:00
2023-03-30 14:47:43 +02:00
printf "%bChanging directory to %s %b\n" "$BLUE" "$dotfiles" "$NC"
2023-03-28 19:13:13 +02:00
if ! cd "$dotfiles"; then
2023-04-12 11:37:10 +02:00
printf "%bCould not CD into %s%b\n" "$RED" "$dotfiles" "$NC"
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-30 14:47:43 +02:00
printf "%bStashing existing changes...%b\n" "$BLUE" "$NC"
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-04-12 11:37:10 +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-30 14:47:43 +02:00
printf "%bPulling updates from dotfiles repo...%b\n" "$BLUE" "$NC"
2023-03-28 14:24:58 +02:00
git pull origin main
2023-04-19 16:17:13 +02:00
git submodule update --remote --recursive
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-04-12 11:37:10 +02:00
printf "%bPopping stashed changes...%b\n" "$BLUE" "$NC"
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-04-12 11:37:10 +02:00
printf "%bThe following files have merge conflicts after popping the stash:%b\n" "$RED" "$NC"
printf "\n"
printf %"s\n" "$unmerged_files\n"
2023-03-28 14:24:58 +02:00
else
2023-04-12 11:37:10 +02:00
stow -t "$HOME" . || printf "%bStow uninstalled or not in path!%b\n" "$RED" "$NC"
2023-03-28 14:24:58 +02:00
fi
2023-04-25 16:35:34 +02:00
printf "%bGenerating firefox profiles...%b\n" "$BLUE" "$NC"
"$dotfiles"/.mozilla/firefox/generate.sh
2023-03-29 00:08:17 +02:00
printf "\n"
printf "Recompile/Install src files? [y/N] \n"
2023-03-30 14:47:43 +02:00
read -r ans
[ "$ans" = "y" ] && for f in "$dotfiles"/.local/src/*; do
2023-04-12 11:37:10 +02:00
if ! cd "$f"; then
printf "%bCould not CD into %s%b\n" "$RED" "$f" "$NC"
exit
fi
sudo make install
2023-03-29 00:09:07 +02:00
make clean
2023-03-29 00:08:17 +02:00
done
2023-03-30 14:47:43 +02:00
printf "%bDotfiles Synced Successfully!%b\n" "$GREEN" "$NC"