diff options
author | tv <tv@krebsco.de> | 2017-06-18 16:12:54 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2017-06-18 16:12:54 +0200 |
commit | faea33e1cb18010ac60f677ac2c18e813e284cc7 (patch) | |
tree | 5ab4189768992e16aa2ed9bc4a509157b544bba6 /krebs/5pkgs/simple/urlencode | |
parent | 9f75e81c5f91aa4236f86c29437de190503ad586 (diff) | |
parent | bf62457ec2655ba4d6ef24c1eb801a80cb7b96bf (diff) |
Merge remote-tracking branch 'prism/master'
Diffstat (limited to 'krebs/5pkgs/simple/urlencode')
-rw-r--r-- | krebs/5pkgs/simple/urlencode/default.nix | 22 |
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 +'' |