diff options
author | EuAndreh <eu@euandre.org> | 2022-08-15 15:52:53 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-08-15 16:11:23 -0300 |
commit | a3ebbfb1b340d926e0b7ad9a4ace380f2fff5a94 (patch) | |
tree | d1dd5aeb0fafa6d956acd9a0e41fb2aca33e8668 | |
parent | etc/guix/home.scm: Remove Anki Qt package (diff) | |
download | dotfiles-a3ebbfb1b340d926e0b7ad9a4ace380f2fff5a94.tar.gz dotfiles-a3ebbfb1b340d926e0b7ad9a4ace380f2fff5a94.tar.xz |
bin/uri: Add working version
-rwxr-xr-x | bin/uri | 69 | ||||
-rw-r--r-- | etc/guix/home.scm | 1 |
2 files changed, 70 insertions, 0 deletions
@@ -0,0 +1,69 @@ +#!/usr/bin/env perl + +use v5.34; +use strict; +use warnings; +use feature 'signatures'; +no warnings 'experimental'; +use Getopt::Std (); +use URI::Escape (); + +sub usage($fh) { + print $fh <<~'EOF' + Usage: + uri [-e|-d] + 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 + + + Get a string from STDIN and convert it to/from URL encoding. + + + Examples: + + Encode the URL: + + $ echo 'https://euandre.org' | uri + + + 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; +Getopt::Std::getopts('edh', \%opts); + +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; +} elsif ($opts{d}) { + print URI::Escape::uri_unescape(<STDIN>); +} else { + print URI::Escape::uri_escape(<STDIN>); +} diff --git a/etc/guix/home.scm b/etc/guix/home.scm index cc79b1a..ddf1266 100644 --- a/etc/guix/home.scm +++ b/etc/guix/home.scm @@ -332,6 +332,7 @@ perl-regexp-grammars perl-commonmark perl-aliased + perl-uri-escape ruby python python-slixmpp |