mirror of
https://cgit.krebsco.de/krops
synced 2024-11-23 03:29:48 +01:00
lib: add shell.quote
This commit is contained in:
parent
e8505f71ff
commit
50868155fd
1 changed files with 10 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue