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 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 4cac963..2585e34 100644 --- a/.config/systemd/user/get-nasa-apod.timer +++ b/.config/systemd/user/get-nasa-apod.timer @@ -1,9 +1,10 @@ [Unit] Description=Daily NASA wallpaper fetch +After=network-online.target Requires=get-nasa-apod.service [Timer] -Unit=nasa-apod.service +Unit=get-nasa-apod.service OnCalendar=daily [Install] diff --git a/.local/bin/get-nasa-apod b/.local/bin/get-nasa-apod index f0f2724..c873456 100755 --- a/.local/bin/get-nasa-apod +++ b/.local/bin/get-nasa-apod @@ -8,34 +8,47 @@ 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}" APOD_URL="https://api.nasa.gov/planetary/apod?api_key=${API_KEY}" -response="$(curl --silent "${APOD_URL}")" +echo "Fetching data from API" +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##*.}" filename="${picture_date}.${extension}" outfile="${WALLPAPERS}/${filename}" if [ -f "${outfile}" ]; then echo "Target file already exists" - exit 0 +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 -tempfile="$(mktemp)" -curl \ - --location \ - --output "${tempfile}" \ - --silent \ - "${picture_url}" -mv "${tempfile}" "${outfile}" +echo "Updating the wallpaper image" ln \ --force \ --symbolic \ "${outfile}" \ "${WALLPAPERS}/today" +echo "Refreshing the desktop background" swaymsg output "*" bg "${SWAY_WALLPAPER}" fill 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 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"