diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix index 7197fe9..3ebefdc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -34,6 +34,12 @@ let { if lib.length y != 1 then throw "malformed /etc/hostname" else lib.elemAt y 0; + isLocalTarget = let + origin = lib.mkTarget ""; + in target: + target.user == origin.user && + lib.elem target.host [origin.host "localhost"]; + mkTarget = s: let default = defVal: val: if val != null then val else defVal; parse = lib.match "(([^@]+)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s; @@ -45,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; |