diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-11-01 20:19:21 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-11-01 20:19:21 +0100 |
commit | 1739341e87cf7b1b80f76b78eb0a48912d47a705 (patch) | |
tree | fede94876a0daf1198a8e08ffefc3fb19a4270b3 /.local/bin/linkview | |
parent | Renamed (diff) | |
download | dotfiles-bsd-1739341e87cf7b1b80f76b78eb0a48912d47a705.tar.gz dotfiles-bsd-1739341e87cf7b1b80f76b78eb0a48912d47a705.tar.bz2 dotfiles-bsd-1739341e87cf7b1b80f76b78eb0a48912d47a705.tar.xz dotfiles-bsd-1739341e87cf7b1b80f76b78eb0a48912d47a705.tar.zst dotfiles-bsd-1739341e87cf7b1b80f76b78eb0a48912d47a705.zip |
Renamed again
Diffstat (limited to '')
-rwxr-xr-x | .local/bin/linkview (renamed from .local/bin/linkview.pl) | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/.local/bin/linkview.pl b/.local/bin/linkview index 8baf8c0..2a16c03 100755 --- a/.local/bin/linkview.pl +++ b/.local/bin/linkview @@ -2,6 +2,7 @@ use strict; use warnings; +use Scalar::Util qw(looks_like_number); use Term::ANSIColor; use constant { @@ -28,16 +29,48 @@ use constant { # mpv-view.pl "$1" # fi +sub open_link +{ + my ($answer) = @_; + return; +} + +sub prompt +{ + my ($url) = @_; + my $answer; + + print 'URL: ' . colored($url, 'red') . "\n\n" . + "Open with?\n" . + "0) mpv\n" . + "1) fetch\n" . + "2) sxiv\n" . + "3) zathura\n" . + "4) w3m\n" . + "5) firefox\n\n" . + "> "; + $answer = <STDIN>; + if (!looks_like_number($answer) || $answer == 0 || $answer == 1 || $answer > 6) { + $answer = -1; + } + return $answer; +} + sub main { my $answer; + system('tput', 'clear'); if (@ARGV == 0) { - print STDERR "URL needed\n"; + print STDERR "linkview: URL needed\n"; exit 1; } - print colored($ARGV[0], 'bold_green') . "\n"; - $answer = <STDIN>; + $answer = prompt($ARGV[0]); + if ($answer == -1) { + print STDERR "linkview: Bad answer\n"; + exit 2; + } + open_link($answer); return; } |