aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanix <danix@danix.xyz>2026-06-11 09:44:51 +0200
committerdanix <danix@danix.xyz>2026-06-11 09:44:51 +0200
commit5d5da3a1b50eedb3c30aa209eb24aa7f579dc701 (patch)
tree365200bfb958482e41064ba1e7440dd56b5b55f3
parent104ec07c142ac74e68ee2d72df662a0adcd5b9c5 (diff)
downloadwallp-5d5da3a1b50eedb3c30aa209eb24aa7f579dc701.tar.gz
wallp-5d5da3a1b50eedb3c30aa209eb24aa7f579dc701.zip
feat: parse_conf key=value config loader
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
-rw-r--r--tests/wallp.bats17
-rw-r--r--wallp19
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/wallp.bats b/tests/wallp.bats
index 1307eeb..3445ddb 100644
--- a/tests/wallp.bats
+++ b/tests/wallp.bats
@@ -37,3 +37,20 @@ teardown() {
run expand_tilde '/abs/b.png'
[ "$output" = "/abs/b.png" ]
}
+
+@test "parse_conf reads keys and expands tilde in paths" {
+ conf="$HOME/c.conf"
+ printf '%s\n' \
+ '# comment' '' \
+ 'THEME=mytheme' \
+ 'OUTPUT_H=DP-1' \
+ 'OUTPUT_V=DP-3' \
+ 'DEFAULT_H=~/p/h.png' \
+ 'DEFAULT_V=/abs/v.png' > "$conf"
+ parse_conf "$conf"
+ [ "$CONF_THEME" = "mytheme" ]
+ [ "$CONF_OUTPUT_H" = "DP-1" ]
+ [ "$CONF_OUTPUT_V" = "DP-3" ]
+ [ "$CONF_DEFAULT_H" = "$HOME/p/h.png" ]
+ [ "$CONF_DEFAULT_V" = "/abs/v.png" ]
+}
diff --git a/wallp b/wallp
index 31680f4..f7cf70b 100644
--- a/wallp
+++ b/wallp
@@ -12,6 +12,25 @@ expand_tilde() {
esac
}
+# Parse key=value conf into CONF_* globals. Ignores blanks and #-comments.
+# Expands ~ in DEFAULT_* path values. Does not validate (see require_conf_keys).
+CONF_THEME="" CONF_OUTPUT_H="" CONF_OUTPUT_V="" CONF_DEFAULT_H="" CONF_DEFAULT_V=""
+parse_conf() {
+ local file="$1" line key val
+ while IFS= read -r line || [ -n "$line" ]; do
+ case "$line" in ''|'#'*) continue ;; esac
+ key="${line%%=*}"
+ val="${line#*=}"
+ case "$key" in
+ THEME) CONF_THEME="$val" ;;
+ OUTPUT_H) CONF_OUTPUT_H="$val" ;;
+ OUTPUT_V) CONF_OUTPUT_V="$val" ;;
+ DEFAULT_H) CONF_DEFAULT_H="$(expand_tilde "$val")" ;;
+ DEFAULT_V) CONF_DEFAULT_V="$(expand_tilde "$val")" ;;
+ esac
+ done < "$file"
+}
+
main() {
return 0
}