From 60f763df195049bfdd5b4bde00e2bbd8be811983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Thu, 12 Mar 2026 08:24:13 +0100 Subject: [PATCH] feat: configfile --- src/main.sh | 3 +++ src/sh/config.sh | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/sh/config.sh diff --git a/src/main.sh b/src/main.sh index 0cbdd03..a35490c 100755 --- a/src/main.sh +++ b/src/main.sh @@ -5,6 +5,9 @@ set -eu # Application info . "sh/info.sh" +# Configuration +. "sh/config.sh" + # Theme . "sh/theme.sh" diff --git a/src/sh/config.sh b/src/sh/config.sh new file mode 100644 index 0000000..b71d2be --- /dev/null +++ b/src/sh/config.sh @@ -0,0 +1,11 @@ +# Main application configuration. This application does not require a +# configuration file. However, a configuration file may be stored as +# `CONFIGFILE_DEFAULT`. If that file exists, it will be sourced. The path to +# the file may be overwritten by specifying the environment variable +# `CONFIGFILE`. If a configuration file is specified, then it must also exist. +# A configuration file comprises the specification of environment variables +# that are allowed to be set. +CONFIGFILE_DEFAULT="${XDG_CONFIG_HOME:-"$HOME/.config"}/$APP_NAME/config" +CONFIGFILE="${CONFIGFILE:-"$CONFIGFILE_DEFAULT"}" +[ "$CONFIGFILE" != "$CONFIGFILE_DEFAULT" ] && [ ! -f "$CONFIGFILE" ] && err "The configuration file manually specified with the environment variable CONFIGFILE=($CONFIGFILE) does not exist." && exit 1 +[ -f "$CONFIGFILE" ] && . "$CONFIGFILE"