From 50868155fd600ab2a3c0ae483e047b8a49ba17d0 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 12 Jul 2018 14:14:47 +0200 Subject: lib: add shell.quote --- lib/default.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; -- cgit v1.2.3