summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/urlencode
diff options
context:
space:
mode:
Diffstat (limited to 'krebs/5pkgs/simple/urlencode')
-rw-r--r--krebs/5pkgs/simple/urlencode/default.nix22
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
+''