From a37c926cd52e3078c62938e925c4656f0fc81aa2 Mon Sep 17 00:00:00 2001 From: Jonas Kattendick Date: Wed, 15 Nov 2023 02:15:32 +0100 Subject: [PATCH] fix: set env vars like described in the manpage Also remove the mention of AGENDA_NEXT, since we don't actually set that... --- agenda | 51 +++++++++++++++++++++++++++++++++------------------ agenda.1 | 6 ------ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/agenda b/agenda index cb43646..f750baf 100644 --- a/agenda +++ b/agenda @@ -149,6 +149,18 @@ __edit() { fi done + # These values are (potentially) used by the AGENDA_EDITOR and AGENDA_TEMPLATE + # processes. + AGENDA_FILE=$file + AGENDA_DATE=$base + AGENDA_NAME=$opt_t + AGENDA_SLUG=$slug + AGENDA_FILE=$file + AGENDA_LAST=$(__agenda_last "$file" "$opt_t") + + # Make shellcheck happy... + export AGENDA_FILE AGENDA_DATE AGENDA_NAME AGENDA_SLUG AGENDA_FILE AGENDA_LAST + if ! [ -f "$file" ]; then if [ "$opt_c" = "yes" ]; then __agenda_create "$file" "$opt_b" "$opt_t" "$slug" "$base" @@ -159,7 +171,6 @@ __edit() { fi if [ "$opt_E" = "no" ]; then - export AGENDA_FILE="$file" exec $AGENDA_EDITOR "$file" else echo "$file" @@ -305,26 +316,10 @@ __agenda_create() { tmp_err=$(mktemp) if [ "$backlog" = "no" ]; then - local last - while read -r REPLY; do - if [ "$REPLY" = "$file" ]; then - break - else - last=$REPLY - fi - done < <( - { - echo "$file" - find "$AGENDA_DIR/$name" -type f - } | sort - ) - # Capture exit code of the template command. local code set +e - AGENDA_DATE=$date AGENDA_NAME=$name AGENDA_SLUG=$slug \ - AGENDA_FILE=$file AGENDA_LAST=${last:-} \ - "$AGENDA_TEMPLATE" > "$tmp" 2> "$tmp_err" + "$AGENDA_TEMPLATE" > "$tmp" 2> "$tmp_err" code=$? set -e @@ -362,6 +357,26 @@ __agenda_default_template() { esac } +__agenda_last() { + local file=$1 name=$2 + + local last + while read -r REPLY; do + if [ "$REPLY" = "$file" ]; then + break + else + last=$REPLY + fi + done < <( + { + echo "$file" + find "$AGENDA_DIR/$name" -type f + } | sort + ) + + echo "${last:-}" +} + # https://stackoverflow.com/a/49035906 __slugify() { echo "$1" \ diff --git a/agenda.1 b/agenda.1 index 6f4b2d9..3b4424c 100644 --- a/agenda.1 +++ b/agenda.1 @@ -190,12 +190,6 @@ The file path of the agenda note. The last agenda file. Can be empty if no previous agenda note exists. .PP .RE -\# -\fBAGENDA_NEXT\fP -.RS 4 -The next agenda file. Can be empty if no next agenda note exists. -.PP -.RE \#============================================================================= .SH "SEE ALSO" \fBxdg-user-dir(1)\fP