1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| | From f9e4306cba875999a44286bd8c585ef9e84a7a88 Mon Sep 17 00:00:00 2001
From: Daniel Sockwell <daniel@codesections.com>
Date: Fri, 30 Sep 2022 17:43:04 -0400
Subject: [PATCH 4/4] Improve support for env vars in config.json
The "StoreDir" and "TempDir" previously allowed for limited
interpolation (limited to $*HOME and $*TMPDIR). This commit adds
interpolation of $*XDG_DATA_HOME, $*XDG_CONFIG_HOME, and
$*XDG_STATE_HOME with default values from the XDG spec, see
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
It also extends the interpolation for the same values to "DefaultCUR",
which also specifies a path.
---
lib/Zef/Config.rakumod | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/Zef/Config.rakumod b/lib/Zef/Config.rakumod
index f77c6be..4362b17 100644
--- a/lib/Zef/Config.rakumod
+++ b/lib/Zef/Config.rakumod
@@ -4,8 +4,15 @@ module Zef::Config {
our sub parse-file($path) {
my %config = %(Zef::from-json( $path.IO.slurp ));
- for %config.grep(*.key.ends-with('Dir')) {
- %config{$_.key} = $_.value.subst(/'{$*HOME}' || '$*HOME'/, $*HOME // $*TMPDIR, :g);
+ for %config.grep({.key.ends-with('Dir') || .key eq 'DefaultCUR'}) {
+ my $home = $*HOME // $*TMPDIR;
+ %config{$_.key} = $_.value.subst(/'{$*XDG_DATA_HOME}' || '$*XDG_DATA_HOME'/,
+ %*ENV<XDG_DATA_HOME> // "$home/.local/share", :g);
+ %config{$_.key} = $_.value.subst(/'{$*XDG_CONFIG_HOME}' || '$*XDG_CONFIG_HOME'/,
+ %*ENV<XDG_CONFIG_HOME> // "$home/.config", :g);
+ %config{$_.key} = $_.value.subst(/'{$*XDG_STATE_HOME}' || '$*XDG_STATE_HOME'/,
+ %*ENV<XDG_STATE_HOME> // "$home/.local/bin", :g);
+ %config{$_.key} = $_.value.subst(/'{$*HOME}' || '$*HOME'/, $home, :g);
%config{$_.key} = $_.value.subst(/'{$*TMPDIR}' || '$*TMPDIR'/, $*TMPDIR, :g);
}
--
2.37.3
|