export variables and use them in subprocesses

This commit is contained in:
2025-06-04 23:46:32 +02:00
parent 83061bd54b
commit 5144465792

View File

@@ -5,77 +5,96 @@ set -eu
err() { err() {
echo "$1" >/dev/tty echo "$1" >/dev/tty
} }
# Read configuration
CONFIGFILE="$HOME/.config/fzf-vjour/config"
if [ ! -f "$CONFIGFILE" ]; then
err "Configuration '$CONFIGFILE' not found."
exit 1
fi
# shellcheck source=/dev/null
. "$CONFIGFILE"
if [ -z "${ROOT:-}" ] || [ -z "${SYNC_CMD:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
err "Configuration is incomplete."
exit 1
fi
# Tools if [ -z "${FZF_VJOUR_USE_EXPORTED:-}" ]; then
if command -v "fzf" >/dev/null; then # Read configuration
FZF="fzf" CONFIGFILE="$HOME/.config/fzf-vjour/config"
else if [ ! -f "$CONFIGFILE" ]; then
err "Did not find the command-line fuzzy finder fzf." err "Configuration '$CONFIGFILE' not found."
exit 1 exit 1
fi fi
if command -v "uuidgen" >/dev/null; then # shellcheck source=/dev/null
UUIDGEN="uuidgen" . "$CONFIGFILE"
else if [ -z "${ROOT:-}" ] || [ -z "${SYNC_CMD:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
err "Did not find the uuidgen command." err "Configuration is incomplete."
exit 1 exit 1
fi fi
if command -v "bat" >/dev/null; then export ROOT
CAT="bat" export SYNC_CMD
elif command -v "batcat" >/dev/null; then export COLLECTION_LABELS
CAT="batcat"
fi
CAT=${CAT:+$CAT --color=always --style=numbers --language=md}
CAT=${CAT:-cat}
### AWK SCRIPTS # Tools
AWK_ALTERTODO=$( if command -v "fzf" >/dev/null; then
cat <<'EOF' FZF="fzf"
else
err "Did not find the command-line fuzzy finder fzf."
exit 1
fi
export FZF
if command -v "uuidgen" >/dev/null; then
UUIDGEN="uuidgen"
else
err "Did not find the uuidgen command."
exit 1
fi
export UUIDGEN
if command -v "bat" >/dev/null; then
CAT="bat"
elif command -v "batcat" >/dev/null; then
CAT="batcat"
fi
CAT=${CAT:+$CAT --color=always --style=numbers --language=md}
CAT=${CAT:-cat}
export CAT
### AWK SCRIPTS
AWK_ALTERTODO=$(
cat <<'EOF'
@@include src/awk/altertodo.awk @@include src/awk/altertodo.awk
EOF EOF
) )
export AWK_ALTERTODO
AWK_EXPORT=$( AWK_EXPORT=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/export.awk @@include src/awk/export.awk
EOF EOF
) )
export AWK_EXPORT
AWK_GET=$( AWK_GET=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/get.awk @@include src/awk/get.awk
EOF EOF
) )
export AWK_GET
AWK_LIST=$( AWK_LIST=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/list.awk @@include src/awk/list.awk
EOF EOF
) )
export AWK_LIST
AWK_NEW=$( AWK_NEW=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/new.awk @@include src/awk/new.awk
EOF EOF
) )
export AWK_NEW
AWK_UPDATE=$( AWK_UPDATE=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/update.awk @@include src/awk/update.awk
EOF EOF
) )
### END OF AWK SCRIPTS export AWK_UPDATE
### END OF AWK SCRIPTS
FZF_VJOUR_USE_EXPORTED="yes"
export FZF_VJOUR_USE_EXPORTED
fi
__lines() { __lines() {
find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \ find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \
@@ -133,7 +152,7 @@ if [ "${1:-}" = "--delete" ]; then
file=$(__filepath_from_selection "$2") file=$(__filepath_from_selection "$2")
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file") summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file")
while true; do while true; do
printf "Do you want to delete the entry with the title \"%s\"? (yes/no)" "$summary" >/dev/tty printf "Do you want to delete the entry with the title \"%s\"? (yes/no): " "$summary" >/dev/tty
read -r yn read -r yn
case $yn in case $yn in
"yes") "yes")