diff options
Diffstat (limited to 'bin/uri')
| -rwxr-xr-x | bin/uri | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -10,7 +10,7 @@ use URI::Escape (); sub usage($fh) { print $fh <<~'EOF' Usage: - uri [-e|-d] + uri [-e|-d] [CONTENT...] uri -h EOF } @@ -23,15 +23,18 @@ sub help($fh) { -d decode the string -h, --help show this message + CONTENT a literal string to be escaped - Get a string from STDIN and convert it to/from URL encoding. + + Convert data to/from URL encoding. If CONTENT is not given, get + data from STDIN. Examples: Encode the URL: - $ echo "https://euandre.org/?q=$(printf '%s' 'a param' | uri)" + $ echo "https://euandre.org/?q=$(uri 'a param')" https://euandre.org/?q=a%20param @@ -68,8 +71,8 @@ if ($opts{h}) { } -if ($opts{d}) { - print URI::Escape::uri_unescape(<STDIN>); -} else { - print URI::Escape::uri_escape(<STDIN>); +my $fn = $opts{d} ? \&URI::Escape::uri_unescape : \&URI::Escape::uri_escape; + +for (@ARGV ? @ARGV : <STDIN>) { + say &$fn($_); } |
