blob: afa42b83ff56824e9435c7c0efa6c81b01f91885 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
''
|