From 501726d3841f365a0c339ef0aa8edc455f1c6d7e Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 18 Jun 2017 14:56:52 +0200 Subject: pkgs: init urlencode --- krebs/5pkgs/simple/urlencode/default.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 krebs/5pkgs/simple/urlencode/default.nix (limited to 'krebs/5pkgs/simple') diff --git a/krebs/5pkgs/simple/urlencode/default.nix b/krebs/5pkgs/simple/urlencode/default.nix new file mode 100644 index 000000000..afa42b83f --- /dev/null +++ b/krebs/5pkgs/simple/urlencode/default.nix @@ -0,0 +1,22 @@ +{ jq, gnused, writeBashBin, ... }: + +writeBashBin "urlencode" '' + set -efu + + decode() { + printf %b "$(${gnused}/bin/sed 's/ /+/g; s/%/\\x/g')" + } + + encode() { + ${jq}/bin/jq -Rr '@uri "\(.)"' + } + + # shellcheck disable=SC2048 + case $* in + -d) decode;; + "") encode;; + *) + echo "$0: error: your argument is invalid" >&2 + exit 1 + esac +'' -- cgit v1.2.3