#!/usr/local/bin/perl use strict; use warnings; use Scalar::Util qw(looks_like_number); use File::HomeDir qw(home); use Term::ReadKey; use Term::ANSIColor qw(colored); use constant { MPVIEW_PATH => '/home/jozan/.local/bin/mpview', MPV_PATH => '/usr/local/bin/mpv', YTDL_PATH => '/usr/local/bin/youtube-dl', FETCH_PATH => '/usr/bin/fetch', SXIV_PATH => '/usr/local/bin/sxiv', ZATHURA_PATH => '/usr/local/bin/zathura', W3M_PATH => '/usr/local/bin/w3m', FIREFOX_PATH => '/usr/local/bin/firefox' }; sub open_link { my ($a, $url) = @_; if ($a == 1) { exec( MPVIEW_PATH, $url ); } elsif ($a == 2 || $a == 3) { chdir home() . "/dl" or chdir home() . "/Downloads" or chdir home() or die $!; if ($a == 2) { exec( YTDL_PATH, $url ); } else { exec( FETCH_PATH, $url ); } } elsif ($a == 4) { exec( SXIV_PATH, '-b', $url ); } elsif ($a == 5) { exec( ZATHURA_PATH, $url ); } elsif ($a == 6) { exec( MPV_PATH, '--really-quiet', '--loop', $url ); } elsif ($a == 7) { exec( W3M_PATH, $url ); } elsif ($a == 8) { exec( FIREFOX_PATH, $url ); } return; } sub prompt { my $answer; $answer = -1; print "Open with?\n" . "1) mpv (default)\n" . "2) youtube-dl\n" . "3) fetch\n" . "4) sxiv\n" . "5) zathura\n" . "6) mpv-loop\n" . "7) w3m\n" . "8) firefox\n" . "0) quit\n" . "\n" . "> "; open(TTY, " 8 ) { print "linkview: bad answer\n"; return -1; } return $answer; } sub main { my $answer; if (@ARGV == 0) { print STDERR "linkview: no URL\n"; exit 1; } system('tput', 'clear'); print 'URL: ' . colored($ARGV[0], 'red') . "\n\n"; $answer = -1; while ($answer == -1) { $answer = prompt(); } if ($answer == 0) { exit 0; } open_link($answer, $ARGV[0]); return; } main(); __END__