fix: set env vars like described in the manpage

Also remove the mention of AGENDA_NEXT, since we don't actually set
that...
This commit is contained in:
2023-11-15 02:15:32 +01:00
parent fbea958363
commit a37c926cd5
2 changed files with 33 additions and 24 deletions

49
agenda
View File

@@ -149,6 +149,18 @@ __edit() {
fi fi
done 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 ! [ -f "$file" ]; then
if [ "$opt_c" = "yes" ]; then if [ "$opt_c" = "yes" ]; then
__agenda_create "$file" "$opt_b" "$opt_t" "$slug" "$base" __agenda_create "$file" "$opt_b" "$opt_t" "$slug" "$base"
@@ -159,7 +171,6 @@ __edit() {
fi fi
if [ "$opt_E" = "no" ]; then if [ "$opt_E" = "no" ]; then
export AGENDA_FILE="$file"
exec $AGENDA_EDITOR "$file" exec $AGENDA_EDITOR "$file"
else else
echo "$file" echo "$file"
@@ -305,25 +316,9 @@ __agenda_create() {
tmp_err=$(mktemp) tmp_err=$(mktemp)
if [ "$backlog" = "no" ]; then 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. # Capture exit code of the template command.
local code local code
set +e 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=$? code=$?
set -e set -e
@@ -362,6 +357,26 @@ __agenda_default_template() {
esac 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 # https://stackoverflow.com/a/49035906
__slugify() { __slugify() {
echo "$1" \ echo "$1" \

View File

@@ -190,12 +190,6 @@ The file path of the agenda note.
The last agenda file. Can be empty if no previous agenda note exists. The last agenda file. Can be empty if no previous agenda note exists.
.PP .PP
.RE .RE
\#
\fBAGENDA_NEXT\fP
.RS 4
The next agenda file. Can be empty if no next agenda note exists.
.PP
.RE
\#============================================================================= \#=============================================================================
.SH "SEE ALSO" .SH "SEE ALSO"
\fBxdg-user-dir(1)\fP \fBxdg-user-dir(1)\fP