diff options
author | pacien | 2022-11-15 01:14:22 +0100 |
---|---|---|
committer | pacien | 2022-11-15 01:14:22 +0100 |
commit | c2b18e3f862bdb61486d8027de4d8dd5b6114012 (patch) | |
tree | 28e7cfa21f7fb3962e8367782c401c94e904ca5f | |
parent | 7551a8cf7f234249a806fa37c9e7bb7700be6301 (diff) | |
download | flaky-utils-c2b18e3f862bdb61486d8027de4d8dd5b6114012.tar.gz |
lib/shell: expose util functions
-rw-r--r-- | lib/shell.nix | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/shell.nix b/lib/shell.nix index 63ef41a..a5b321d 100644 --- a/lib/shell.nix +++ b/lib/shell.nix | |||
@@ -4,10 +4,13 @@ flake: | |||
4 | 4 | ||
5 | with pkgs.lib; | 5 | with pkgs.lib; |
6 | 6 | ||
7 | let | 7 | rec { |
8 | mapAttrsToLines = mapping: attrs: | 8 | mapAttrsToLines = mapping: attrs: |
9 | concatStringsSep "\n" (mapAttrsToList mapping attrs); | 9 | concatStringsSep "\n" (mapAttrsToList mapping attrs); |
10 | 10 | ||
11 | ifSomeAttrs = attrs: f: pkgs.lib.optionalString (attrs != {}) (f attrs); | ||
12 | ifSomeList = list: f: pkgs.lib.optionalString (list != []) (f list); | ||
13 | |||
11 | fmt = rec { | 14 | fmt = rec { |
12 | codeBlock = code: text: ''"\e[${code}m"${escapeShellArg text}"\e[0m"''; | 15 | codeBlock = code: text: ''"\e[${code}m"${escapeShellArg text}"\e[0m"''; |
13 | keyword = codeBlock "1;36"; | 16 | keyword = codeBlock "1;36"; |
@@ -15,10 +18,6 @@ let | |||
15 | printSectionTitle = title: ''echo -e "\n"${section title}''; | 18 | printSectionTitle = title: ''echo -e "\n"${section title}''; |
16 | }; | 19 | }; |
17 | 20 | ||
18 | in rec { | ||
19 | ifSomeAttrs = attrs: f: pkgs.lib.optionalString (attrs != {}) (f attrs); | ||
20 | ifSomeList = list: f: pkgs.lib.optionalString (list != []) (f list); | ||
21 | |||
22 | exportEnvVar = k: v: '' | 21 | exportEnvVar = k: v: '' |
23 | export ${escapeShellArg k}="${v}" | 22 | export ${escapeShellArg k}="${v}" |
24 | ''; | 23 | ''; |