stockholm/krebs/5pkgs/simple/urlencode/default.nix

23 lines
365 B
Nix
Raw Normal View History

2017-06-18 12:56:52 +00:00
{ 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
''