summaryrefslogtreecommitdiff
path: root/src/lib/conf.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/conf.sh')
-rw-r--r--src/lib/conf.sh29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/lib/conf.sh b/src/lib/conf.sh
index c2904de..47a93c7 100644
--- a/src/lib/conf.sh
+++ b/src/lib/conf.sh
@@ -29,7 +29,7 @@ if [[ -z ${XDG_CACHE_HOME:-} ]]; then
export XDG_CACHE_HOME="${LIBREHOME}/.cache"
fi
-# Generic functions ############################################################
+# Low-level generic functions ##################################################
# Usage: list_files $slug
# Lists the configuration files to be considered for $slug.
@@ -77,6 +77,8 @@ list_envvars() {
esac
}
+# High-level generic functions #################################################
+
# Usage: load_files $slug
# Loads the configuration files for $slug in the proper order.
load_files() {
@@ -130,24 +132,25 @@ check_vars() {
fi
}
-# makepkg configuration ########################################################
-
-# Usage: get_conf_makepkg <var_name> <default_value>
+# Usage: get_var <slug> <var_name> <default_value>
# Does not work with arrays
-get_conf_makepkg() (
+get_var() (
set +euE
- local setting=$1
- local default=$2
- load_files makepkg
- printf '%s\n' "${!setting:-${default}}"
+ local slug=$1
+ local setting=$2
+ local default=$3
+ load_files "$slug"
+ printf '%s' "${!setting:-${default}}"
)
+# Usage: set_var <slug> <var_name> <value>
# Does not work with arrays
-set_conf_makepkg() {
- local key=$1
- local val=$2
+set_var() {
+ local slug=$1
+ local key=$2
+ local val=$3
local file
- for file in $(list_files makepkg|tac); do
+ for file in $(list_files "$slug"|tac); do
if [[ -w $file ]]; then
sed -i "/^\s*$key=/d" "$file"
printf '%s=%q\n' "$key" "$val" >> "$file"