pkgs: init urlencode
This commit is contained in:
parent
aad8594ad9
commit
501726d384
22
krebs/5pkgs/simple/urlencode/default.nix
Normal file
22
krebs/5pkgs/simple/urlencode/default.nix
Normal 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
|
||||
''
|
Loading…
Reference in New Issue
Block a user