feat: configfile

This commit is contained in:
2026-03-12 08:24:13 +01:00
parent 3210a8bbcf
commit 60f763df19
2 changed files with 14 additions and 0 deletions

11
src/sh/config.sh Normal file
View File

@@ -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"