pkgs: init urlencode

This commit is contained in:
lassulus 2017-06-18 14:56:52 +02:00
parent aad8594ad9
commit 501726d384

View File

@ -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
''