diff options
author | lassulus <lass@lassul.us> | 2017-06-18 14:56:52 +0200 |
---|---|---|
committer | lassulus <lass@lassul.us> | 2017-06-18 14:57:28 +0200 |
commit | 501726d3841f365a0c339ef0aa8edc455f1c6d7e (patch) | |
tree | df3279911816ef7dae6d94bb57d00cb45315bc36 /krebs/5pkgs/simple/urlencode/default.nix | |
parent | aad8594ad92c3aca8219fb402c29985788ad5749 (diff) |
pkgs: init urlencode
Diffstat (limited to 'krebs/5pkgs/simple/urlencode/default.nix')
-rw-r--r-- | krebs/5pkgs/simple/urlencode/default.nix | 22 |
1 files changed, 22 insertions, 0 deletions
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 +'' |