1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-12-23 10:19:52 +01:00

lib: add shell.quote

This commit is contained in:
tv 2018-07-12 14:14:47 +02:00
parent e8505f71ff
commit 50868155fd

View file

@ -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;