aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2018-07-12 14:14:47 +0200
committertv <tv@krebsco.de>2018-07-12 14:14:47 +0200
commit50868155fd600ab2a3c0ae483e047b8a49ba17d0 (patch)
tree502be5803408914fd10cf5e1ac7c8025700a94d6
parente8505f71ff4741156fc3ce05542dd3aa70798214 (diff)
lib: add shell.quote
-rw-r--r--lib/default.nix10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix
index ae1cef9..3ebefdc 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -51,6 +51,16 @@ let {
path = default "/var/src" /* no default? */ (elemAt' parse 6);
};
+ shell = let
+ isSafeChar = lib.testString "[-+./0-9:=A-Z_a-z]";
+ quoteChar = c:
+ if isSafeChar c then c
+ else if c == "\n" then "'\n'"
+ else "\\${c}";
+ in {
+ quote = x: if x == "" then "''" else lib.stringAsChars quoteChar x;
+ };
+
test = re: x: lib.isString x && lib.testString re x;
testString = re: x: lib.match re x != null;