dotfiles/.config/shell/bin/upd

47 lines
1.3 KiB
Text
Raw Normal View History

#!/bin/bash
2024-01-17 03:42:55 -08:00
# updates some important repositories in my home folder (and elsewhere) that exist on multiple devices
2022-10-04 17:53:42 -07:00
set -eu
# Check for git
if ! command -v git > /dev/null; then
echo "git is not installed, please install git and try again"
exit 1
fi
# Set colors
if command -v tput > /dev/null; then
2022-10-04 17:53:42 -07:00
YELLOW="$(tput setaf 3)"
GREEN="$(tput setaf 2)"
NC="$(tput sgr0)"
2022-06-22 11:12:33 -07:00
elif [ -n "$TERMUX_VERSION" ]; then
2022-10-04 17:53:42 -07:00
YELLOW=""
GREEN=""
NC="(B"
fi
2022-10-04 17:53:42 -07:00
# Avoiding copy pasting this over and over
g() { git -C "$REPO" "$@"; }
# shellcheck disable=SC2016
REPO_ABBR='echo ${REPO/"$HOME"/"~"}'
2022-05-24 22:28:03 -07:00
# `git pull` everything mentioned in the REPOS_TO_UPDATE variable
2024-06-06 03:43:45 -07:00
IFS=: read -ra REPOS_TO_UPDATE_ARR <<< "${REPOS_TO_UPDATE:-}:${DOCS_DIR:-}:$HOME/bin:${NIXOS_DIR:-}:$HOME/code/faust-ideas:$HOME/.config/home-manager"
for REPO in "${REPOS_TO_UPDATE_ARR[@]}"; do
if [ -n "$REPO" ]; then
2022-10-04 17:53:42 -07:00
if g rev-parse > /dev/null 2>&1; then
echo " ${GREEN}Pulling $(eval "$REPO_ABBR")‥${NC}"
g pull
g diff --quiet || echo "${YELLOW}Warning: Working tree for $(eval "$REPO_ABBR") is dirty${NC}"
fi
fi
2022-10-04 17:53:42 -07:00
UPDATED_STUFF=true
done
# check for dotfiles updates
2022-10-04 17:53:42 -07:00
${UPDATED_STUFF:-false} && echo
echo " ${GREEN}Updating dotfiles…${NC}"
dotfiles pull
2022-10-04 17:53:42 -07:00
dotfiles diff --quiet || echo "${YELLOW}Warning: Working tree for dotfiles is dirty${NC}"