From e42edc2dcf7716a4e89e0fc3c4b2254256e0704d Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Mon, 16 Oct 2023 10:40:56 +0300 Subject: [PATCH] chore(scripts): update cheat install scripts --- scripts/install-cheat-purebashbible.sh | 13 +++++++------ scripts/install-cheat-tldr.sh | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/install-cheat-purebashbible.sh b/scripts/install-cheat-purebashbible.sh index b567a93..ecdc737 100755 --- a/scripts/install-cheat-purebashbible.sh +++ b/scripts/install-cheat-purebashbible.sh @@ -14,13 +14,19 @@ PBB_SYNTAX="syntax: bash" PBB_TAGS="tags: [bash]" PBB_TEMP_PREFIX=$(basename "$0") -PBB_TEMP_DIR="/tmp/pbb-$(rnd)" +PBB_TEMP_DIR="$XDG_CACHE_HOME/cheat/pbb" # If there's no .git, clone the folder if [ ! -d "$PBB_TEMP_DIR/.git" ]; then msg_run "Starting to clone $PBB_GIT" git clone --depth 1 --single-branch -q "$PBB_GIT" "$PBB_TEMP_DIR" \ && msg_yay "Cloned $PBB_GIT" +else + # Update the repo + msg_run "Starting to update $PBB_GIT" + git -C "$PBB_TEMP_DIR" reset --hard origin/master + git -C "$PBB_TEMP_DIR" pull -q \ + && msg_yay "Updated $PBB_GIT" fi PBB_CHAPTERS=$(ls -1v "$PBB_TEMP_DIR"/manuscript/chapter*) @@ -50,8 +56,3 @@ for f in ${PBB_CHAPTERS[@]}; do echo -e "---\n$T---\n$(cat "$CHEAT_FILE")" > "$CHEAT_FILE" fi done - -# Cleanup -if [ -d "$PBB_TEMP_DIR" ]; then - rm -rf "$PBB_TEMP_DIR" -fi diff --git a/scripts/install-cheat-tldr.sh b/scripts/install-cheat-tldr.sh index b749616..e852c46 100755 --- a/scripts/install-cheat-tldr.sh +++ b/scripts/install-cheat-tldr.sh @@ -13,13 +13,19 @@ TLDR_SOURCE="source: $TLDR_GIT" TLDR_SYNTAX="syntax: markdown" TLDR_TEMP_PREFIX=$(basename "$0") -TLDR_TEMP_DIR="/tmp/cheat-tldr-$(rnd)" +TLDR_TEMP_DIR="$XDG_CACHE_HOME/cheat/tldr" # If there's no .git, clone the folder if [ ! -d "$TLDR_TEMP_DIR/.git" ]; then msg_run "Starting to clone $TLDR_GIT" git clone --depth 1 --single-branch -q "$TLDR_GIT" "$TLDR_TEMP_DIR" \ && msg_done "Cloned $TLDR_GIT" +else + # Update the repo + msg_run "Starting to update $TLDR_GIT" + git -C "$TLDR_TEMP_DIR" reset --hard origin/main + git -C "$TLDR_TEMP_DIR" pull -q \ + && msg_done "Updated $TLDR_GIT" fi # Fetch the destination directory from cheat defined directories. @@ -67,8 +73,3 @@ for d in "$TLDR_TEMP_DIR"/pages/*; do done done - -# Cleanup -if [ -d "$TLDR_TEMP_DIR" ]; then - rm -rf "$TLDR_TEMP_DIR" -fi