diff options
author | EuAndreh <eu@euandre.org> | 2024-11-14 00:21:09 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-11-14 00:21:09 -0300 |
commit | f2a9bee4af2a9cfc8865df91edbbcd5fe69ac36f (patch) | |
tree | dc3905470a30405c78a61286002664bdc62919ed /bin/uri | |
parent | bin/forever: Add "-n" option, remove long options (diff) | |
download | dotfiles-f2a9bee4af2a9cfc8865df91edbbcd5fe69ac36f.tar.gz dotfiles-f2a9bee4af2a9cfc8865df91edbbcd5fe69ac36f.tar.xz |
Move bin/{htmlesc,shesc,uri} to eut
Diffstat (limited to 'bin/uri')
-rwxr-xr-x | bin/uri | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/bin/uri b/bin/uri deleted file mode 100755 index bbe67ef..0000000 --- a/bin/uri +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env perl - -use v5.34; -use warnings; -use feature 'signatures'; -no warnings ('experimental::signatures'); -use Getopt::Std (); -use URI::Escape (); - -sub usage($fh) { - print $fh <<~'EOF'; - Usage: - uri [-e|-d] [CONTENT...] - uri -h - EOF -} - -sub help($fh) { - print $fh <<~'EOF'; - - - Options: - -e encode the string (the default action) - -d decode the string - -h, --help show this message - - CONTENT a literal string to be escaped - - - Convert data to/from URL encoding. If CONTENT is not given, get - data from STDIN. - - - Examples: - - Encode the URL: - - $ echo "https://euandre.org/?q=$(uri 'a param')" - https://euandre.org/?q=a%20param - - - Decode the content from the file: - - $ uri -d < file - EOF -} - -for (@ARGV) { - last if $_ eq '--'; - if ($_ eq '--help') { - usage *STDOUT; - help *STDOUT; - exit; - } -} - -my %opts; -if (!Getopt::Std::getopts('edh', \%opts)) { - usage *STDERR; - exit 2; -} - -if ($opts{h}) { - usage *STDOUT; - help *STDOUT; - exit; -} elsif ($opts{e} and $opts{d}) { - say STDERR 'Both -e and -d given. Pick one.'; - say STDERR ''; - usage *STDERR; - exit 2; -} - - -my $fn = $opts{d} ? \&URI::Escape::uri_unescape : \&URI::Escape::uri_escape; - -$|++; - -while ($_ = (@ARGV ? @ARGV : <STDIN>)) { - print &$fn($_); -} |