-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlcode.sh
executable file
·39 lines (37 loc) · 1.06 KB
/
urlcode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
#
# urlcode
# command line encode/decode of urls to clean http refs
#
# args:
# - invoke as urlencode or urldecode
# - send as lines on stdin, or pass as command line args, or both
#
# deps:
# - uses php's rawurlencode() and rawurldecode(), respectively
#
# todo:
# - url arg (ie after `+') maybe urlencode() not raw variant
# - just write this in php itself using its `-R'
# - we tack on a newline at end; perhaps only if stdout isatty?
#
# scott@smemsh.net
# https://github.com/smemsh/utilsh/
# https://spdx.org/licenses/GPL-2.0
#
##############################################################################
name=$(basename $0); usage="
$name: write ${name}d lines to stdout
- invoke as either \`urlencode', or \`urldecode'
- send either stdin, or pass in arguments, or both
- each line is then raw${name}d to stdout
"
usage_exit () { cat <<< "$usage"; exit; }
xxcode () { php -r "printf(\"%s\\n\", raw$name(\"$1\"));"; }
main ()
{
readarray -t stdin
set -- "$@" "${stdin[@]}"
for each; do xxcode "$each"; done
}
main "$@"