From 015720ef89b81d3d17b3aa7dcaa1e1489c0f87a8 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 28 Aug 2015 20:09:54 +0200 Subject: {tv/4lib shell-escape,krebs/4lib/shell.nix escape} --- krebs/4lib/shell.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 krebs/4lib/shell.nix (limited to 'krebs/4lib/shell.nix') diff --git a/krebs/4lib/shell.nix b/krebs/4lib/shell.nix new file mode 100644 index 000000000..48b220f87 --- /dev/null +++ b/krebs/4lib/shell.nix @@ -0,0 +1,15 @@ +{ lib, ... }: + +with builtins; +with lib; + +rec { + escape = + let + isSafeChar = c: match "[-./0-9_a-zA-Z]" c != null; + in + stringAsChars (c: + if isSafeChar c then c + else if c == "\n" then "'\n'" + else "\\${c}"); +} -- cgit v1.2.3 From f6997378c91be84432703183397f8675143030e9 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 28 Aug 2015 20:11:03 +0200 Subject: krebs shell: add cat --- krebs/4lib/shell.nix | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'krebs/4lib/shell.nix') diff --git a/krebs/4lib/shell.nix b/krebs/4lib/shell.nix index 48b220f87..2a6da5c16 100644 --- a/krebs/4lib/shell.nix +++ b/krebs/4lib/shell.nix @@ -12,4 +12,11 @@ rec { if isSafeChar c then c else if c == "\n" then "'\n'" else "\\${c}"); + + # + # shell script generators + # + + # example: "${cat (toJSON { foo = "bar"; })} | jq -r .foo" + cat = s: "printf '%s' ${escape s}"; } -- cgit v1.2.3