From d30a9455809842944c097f5cddeeec6719952999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20Healy?= Date: Sun, 19 Apr 2026 22:37:53 +0100 Subject: [PATCH] Make the script work out-of-directory. --- git-portfolio | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/git-portfolio b/git-portfolio index cf5f101..33e1464 100755 --- a/git-portfolio +++ b/git-portfolio @@ -1,12 +1,42 @@ #!/usr/bin/bash +repos="/tmp/repos-$(cat /dev/urandom | base64 | tr -d '=+/' | head -c 8)" +mkdir -p "$repos" +function safely_remove_tmp_repos() { + if [ "$repos" ] && [ -d "$repos" ]; then + if [ "$(find -name .git -type d | wc -l)" -eq 0 ]; then + echo "Warning: No git repositories found in '$repos'. Not deleting to prevent data loss." + rmdir "$repos" 2>/dev/null + return + fi + rm -rf "$repos" + fi +} function cleanup() { - rm -rf repos tmp-portfolio + safely_remove_tmp_repos + rm -rf tmp-portfolio } directory="$1" +script_dir="$(dirname "$0")" if [ ! "$directory" ]; then echo "Usage: $0 " exit 1 fi +if ! command -v pass >/dev/null 2>&1; then + echo "Error: 'pass' command not found. Please install 'pass' and set up your Gitea API token." + exit 1 +fi +if ! command -v jq >/dev/null 2>&1; then + echo "Error: 'jq' command not found. Please install 'jq' to process JSON data." + exit 1 +fi +if ! command -v Rscript >/dev/null 2>&1; then + echo "Error: 'Rscript' command not found. Please install R to generate language distribution plots." + exit 1 +fi +if ! command -v quarto >/dev/null 2>&1; then + echo "Error: 'quarto' command not found. Please install Quarto to render project pages." + exit 1 +fi trap cleanup EXIT GIT_URL='https://git.seanhealy.ie' GIT_USER=sean @@ -44,7 +74,7 @@ while read project; do awk -v total="$total_bytes" '{print $2 / total"\t"$1}' | sort -n -r ) - git clone --depth 1 -b main --single-branch "$GIT_URL/$GIT_USER/$name" "repos/$name" 2>/dev/null >/dev/null + git clone --depth 1 -b main --single-branch "$GIT_URL/$GIT_USER/$name" "$repos/$name" 2>/dev/null >/dev/null echo $'Percentage\tLanguages' > /tmp/languages.tsv echo "$languages_percentages" >> /tmp/languages.tsv (cat > /tmp/plot.R) < "$name.qmd") < "$name.qmd") <