diff options
author | EuAndreh <eu@euandre.org> | 2023-04-03 13:16:15 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-04-03 13:25:07 -0300 |
commit | 9f102978dc4ced7f1e846aa793a4b146c447d082 (patch) | |
tree | ec04e22aae9f481279cc580cb84261d9126428f4 /bin/uri | |
parent | opt/bin-dirs/euandre.org: Remove symlink, link pb(1) directly (diff) | |
download | dotfiles-9f102978dc4ced7f1e846aa793a4b146c447d082.tar.gz dotfiles-9f102978dc4ced7f1e846aa793a4b146c447d082.tar.xz |
bin/uri: Allow string argument to be given instead of STDIN
BONUS: Make reading from STDIN streaming instead of all at once.
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($_); } |