From 0f2eae6e639ce5f16de3d868aa945a8a7bcd02ec Mon Sep 17 00:00:00 2001 From: PowerUser64 Date: Tue, 4 Oct 2022 17:53:42 -0700 Subject: [PATCH] upd: check if working tree is dirty --- .config/shell/bin/upd | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.config/shell/bin/upd b/.config/shell/bin/upd index 92512d3..a927d19 100755 --- a/.config/shell/bin/upd +++ b/.config/shell/bin/upd @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -eu # Check for git if ! command -v git > /dev/null; then @@ -10,25 +10,36 @@ fi # Set colors if command -v tput > /dev/null; then + YELLOW="$(tput setaf 3)" GREEN="$(tput setaf 2)" NC="$(tput sgr0)" elif [ -n "$TERMUX_VERSION" ]; then + YELLOW="" GREEN="" NC="(B" fi +# Avoiding copy pasting this over and over +g() { git -C "$REPO" "$@"; } + +# shellcheck disable=SC2016 +REPO_ABBR='echo ${REPO/"$HOME"/"~"}' + # `git pull` everything mentioned in the REPOS_TO_UPDATE variable -IFS=: read -ra REPOS_TO_UPDATE_ARR <<< "$REPOS_TO_UPDATE:$DOCS_DIR:$HOME/bin" +IFS=: read -ra REPOS_TO_UPDATE_ARR <<< "${REPOS_TO_UPDATE:-}:$DOCS_DIR:$HOME/bin" for REPO in "${REPOS_TO_UPDATE_ARR[@]}"; do if [ -n "$REPO" ]; then - if git -C "$REPO" rev-parse > /dev/null 2>&1; then - echo " ${GREEN}Pulling ${REPO/"$HOME"/"~"}‥${NC}" - git -C "$REPO" pull + 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 + UPDATED_STUFF=true done # check for dotfiles updates -echo +${UPDATED_STUFF:-false} && echo echo " ${GREEN}Updating dotfiles…${NC}" dotfiles pull +dotfiles diff --quiet || echo "${YELLOW}Warning: Working tree for dotfiles is dirty${NC}"