From fd81499c83a616ff4fecfdd44fd6ca332c364b53 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Fri, 18 Jul 2025 16:28:59 +0300 Subject: [PATCH 1/9] Handle missing argument in strict mode --- .local/bin/take-screenshot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.local/bin/take-screenshot b/.local/bin/take-screenshot index f2cf7c2..32f4eaf 100755 --- a/.local/bin/take-screenshot +++ b/.local/bin/take-screenshot @@ -30,7 +30,7 @@ recording_filename() { echo ~/Pictures/screenshots/recording-"$(ts)".mp4 } -if [ -z "$1" ]; then +if [ -z "${1+exists}" ]; then option=$(listopts | fuzzel --dmenu) else option="$1" From a804440f0198e8a124ee2f5299681f40a0e70b4a Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Sat, 12 Jul 2025 23:32:20 +0300 Subject: [PATCH 2/9] Refactor the repo sync script to work in strict mode --- .local/bin/sync-git-repos | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/.local/bin/sync-git-repos b/.local/bin/sync-git-repos index d1fce9e..6b93770 100755 --- a/.local/bin/sync-git-repos +++ b/.local/bin/sync-git-repos @@ -1,4 +1,7 @@ -#! /usr/bin/sh +#! /usr/bin/bash + +set -euo pipefail +IFS=$'\n\t' REPO_ROOT_FILE="$(systemd-path user-state-private)"/repo-roots/repo-roots @@ -12,18 +15,25 @@ sync_repo () { repo=$1 echo git-sync "${repo}" - ( cd "${repo}" && "$(systemd-path user-state-private)"/git-sync/git-sync sync ) + ( cd "${repo}" && "$(systemd-path user-state-private)"/git-sync/git-sync sync ) || true echo } -if [ "list" = "$1" ]; then - while read -r repo_root; do - list_repos "${repo_root}" - done < "${REPO_ROOT_FILE}" -else - while read -r repo_root; do - for repo in $(list_repos "${repo_root}"); do - sync_repo "${repo}" - done - done < "${REPO_ROOT_FILE}" -fi +case "${1:-sync}" in + "list") + while read -r repo_root; do + list_repos "${repo_root}" + done < "${REPO_ROOT_FILE}" + ;; + "sync") + while read -r repo_root; do + for repo in $(list_repos "${repo_root}"); do + sync_repo "${repo}" + done + done < "${REPO_ROOT_FILE}" + ;; + *) + echo Unknown option \""$1"\" + exit 1 + ;; +esac From 777b88a37f1b81e63d7c9f8d186aa5f87cc1c17f Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 16 Jul 2025 22:05:54 +0300 Subject: [PATCH 3/9] Set the default go directories to align with the XDG paths --- .config/go/env | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .config/go/env diff --git a/.config/go/env b/.config/go/env new file mode 100644 index 0000000..129f62f --- /dev/null +++ b/.config/go/env @@ -0,0 +1,2 @@ +GOBIN=/home/ohad/.local/state/go/bin +GOPATH=/home/ohad/.cache/go From b0ad2744612cd4f41ea3459430b4aa3bb9a6750e Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 16 Jul 2025 22:12:37 +0300 Subject: [PATCH 4/9] Create a dedicated folder for the daily NASA pictures --- .local/bin/get-nasa-apod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index f0f2724..f069a4d 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -8,7 +8,7 @@ if [ "${API_KEY}" = "DEMO_KEY" ]; then echo "No API key set! using demo key." fi -WALLPAPERS="$(systemd-path user)"/Wallpapers +WALLPAPERS="$(systemd-path user)"/Pictures/nasa mkdir --parents "${WALLPAPERS}" From 277b60c13e0f6a5d4fb1bb4f5ed83eb48b8800e9 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Fri, 18 Jul 2025 16:30:28 +0300 Subject: [PATCH 5/9] Fix the service name in the timer --- .config/systemd/user/get-nasa-apod.timer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/systemd/user/get-nasa-apod.timer b/.config/systemd/user/get-nasa-apod.timer index 4cac963..0f0ab94 100644 --- a/.config/systemd/user/get-nasa-apod.timer +++ b/.config/systemd/user/get-nasa-apod.timer @@ -3,7 +3,7 @@ Description=Daily NASA wallpaper fetch Requires=get-nasa-apod.service [Timer] -Unit=nasa-apod.service +Unit=get-nasa-apod.service OnCalendar=daily [Install] From ec2016c6d1b132aa4cc0fb1077e8096c6bbd6f7c Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Fri, 18 Jul 2025 17:05:43 +0300 Subject: [PATCH 6/9] Update the wallpaper even if the image file already exists --- .local/bin/get-nasa-apod | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index f069a4d..bd69600 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -23,16 +23,16 @@ outfile="${WALLPAPERS}/${filename}" if [ -f "${outfile}" ]; then echo "Target file already exists" - exit 0 +else + tempfile="$(mktemp)" + curl \ + --location \ + --output "${tempfile}" \ + --silent \ + "${picture_url}" + mv "${tempfile}" "${outfile}" fi -tempfile="$(mktemp)" -curl \ - --location \ - --output "${tempfile}" \ - --silent \ - "${picture_url}" -mv "${tempfile}" "${outfile}" ln \ --force \ --symbolic \ From c352ad925ca81d6c3e5b78e01e90920bfdda125f Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Fri, 18 Jul 2025 17:02:33 +0300 Subject: [PATCH 7/9] Add logging to the NASA APOD download script --- .local/bin/get-nasa-apod | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index bd69600..e6f91b2 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -13,10 +13,16 @@ WALLPAPERS="$(systemd-path user)"/Pictures/nasa mkdir --parents "${WALLPAPERS}" APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}" +echo "Fetching data from API" response="$(curl --silent "${APOD_URL}")" +echo "Received response from API" +# shellcheck disable=SC2005 +echo "$(printf '%s' "${response}" | jq '.')" +echo "Parsing data" picture_date="$(printf '%s' "${response}" | jq --raw-output .date)" picture_url="$(printf '%s' "${response}" | jq --raw-output .hdurl)" +echo "Generating output filename" extension="${picture_url##*.}" filename="${picture_date}.${extension}" outfile="${WALLPAPERS}/${filename}" @@ -24,18 +30,23 @@ outfile="${WALLPAPERS}/${filename}" if [ -f "${outfile}" ]; then echo "Target file already exists" else + echo "Creating temporary file" tempfile="$(mktemp)" + echo "Fetching the daily picture" curl \ --location \ --output "${tempfile}" \ --silent \ "${picture_url}" + echo "Transaction-like file update" mv "${tempfile}" "${outfile}" fi +echo "Updating the wallpaper image" ln \ --force \ --symbolic \ "${outfile}" \ "${WALLPAPERS}/today" +echo "Refreshing the desktop background" swaymsg output "*" bg "${SWAY_WALLPAPER}" fill From 18ab3487f562cb43a1a39c9959efb6c648656643 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Fri, 18 Jul 2025 17:08:13 +0300 Subject: [PATCH 8/9] Check the API rate limit --- .local/bin/get-nasa-apod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index e6f91b2..c873456 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -14,13 +14,15 @@ mkdir --parents "${WALLPAPERS}" APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}" echo "Fetching data from API" -response="$(curl --silent "${APOD_URL}")" +response="$(curl --silent --write-out '{"rate-limit": %header{x-ratelimit-remaining}}' "${APOD_URL}" | jq --slurp add)" echo "Received response from API" # shellcheck disable=SC2005 echo "$(printf '%s' "${response}" | jq '.')" echo "Parsing data" picture_date="$(printf '%s' "${response}" | jq --raw-output .date)" picture_url="$(printf '%s' "${response}" | jq --raw-output .hdurl)" +rate_remaining="$(printf '%s' "${response}" | jq '."rate-limit"')" +echo "Remaining requests until rate limit: ${rate_remaining}" echo "Generating output filename" extension="${picture_url##*.}" From 1b278acd2b9a5eedb8ee5ec42bbb5bdccaee5a6b Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Fri, 18 Jul 2025 16:30:52 +0300 Subject: [PATCH 9/9] Wait for network connection before fetching the daily NASA picture --- .config/systemd/user/get-nasa-apod.service | 1 + .config/systemd/user/get-nasa-apod.timer | 1 + 2 files changed, 2 insertions(+) diff --git a/.config/systemd/user/get-nasa-apod.service b/.config/systemd/user/get-nasa-apod.service index 1da3c26..a3bf8d7 100644 --- a/.config/systemd/user/get-nasa-apod.service +++ b/.config/systemd/user/get-nasa-apod.service @@ -1,5 +1,6 @@ [Unit] Description=Refresh the wallpaper using the NASA Astronomy Picture of the Day +After=network-online.target Wants=get-nasa-apod.timer [Service] diff --git a/.config/systemd/user/get-nasa-apod.timer b/.config/systemd/user/get-nasa-apod.timer index 0f0ab94..2585e34 100644 --- a/.config/systemd/user/get-nasa-apod.timer +++ b/.config/systemd/user/get-nasa-apod.timer @@ -1,5 +1,6 @@ [Unit] Description=Daily NASA wallpaper fetch +After=network-online.target Requires=get-nasa-apod.service [Timer]