summaryrefslogtreecommitdiffstats
path: root/.local/bin
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-11-02 16:12:14 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-11-02 16:12:14 +0100
commite0fcf65c9e7ab50d1b524fb9a72d14724502a911 (patch)
treeea25343c5bca5acd6c86db614851ef190d4c1588 /.local/bin
parentRenamed again (diff)
downloaddotfiles-bsd-e0fcf65c9e7ab50d1b524fb9a72d14724502a911.tar.gz
dotfiles-bsd-e0fcf65c9e7ab50d1b524fb9a72d14724502a911.tar.bz2
dotfiles-bsd-e0fcf65c9e7ab50d1b524fb9a72d14724502a911.tar.xz
dotfiles-bsd-e0fcf65c9e7ab50d1b524fb9a72d14724502a911.tar.zst
dotfiles-bsd-e0fcf65c9e7ab50d1b524fb9a72d14724502a911.zip
linkview update
Diffstat (limited to '')
-rwxr-xr-x.local/bin/linkview148
-rwxr-xr-x.local/bin/mpview15
2 files changed, 120 insertions, 43 deletions
diff --git a/.local/bin/linkview b/.local/bin/linkview
index 2a16c03..4612860 100755
--- a/.local/bin/linkview
+++ b/.local/bin/linkview
@@ -3,55 +3,118 @@
use strict;
use warnings;
use Scalar::Util qw(looks_like_number);
-use Term::ANSIColor;
+use File::HomeDir qw(home);
+use Term::ReadKey;
+use Term::ANSIColor qw(colored);
use constant {
- MPV_PATH => '/home/jozan/.local/bin/mpview',
- FETCH_PATH => '/usr/bin/fetch'
+ 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'
};
-# ext="${1##*.}"
-# mpvFiles="mkv mp4 gif"
-# sxivFiles="png jpg jpeg jpe xpm"
-# wgetFiles="flac mp3 mp3?source=feed opus pdf doc docx"
-#
-# cd ~/dl || exit
-#
-# if echo "$sxivFiles" | grep -w "$ext" > /dev/null; then
-# nohup sxiv "$1" > /dev/null &
-# elif echo "$mpvFiles" | grep -w "$ext" > /dev/null; then
-# nohup mpv --loop --quiet "$1" > /dev/null &
-# elif echo "$wgetFiles" | grep -w "$ext" > /dev/null; then
-# clear
-# fetch "$1"
-# else
-# clear
-# mpv-view.pl "$1"
-# fi
-
sub open_link
{
- my ($answer) = @_;
+ 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 ($url) = @_;
my $answer;
- print 'URL: ' . colored($url, 'red') . "\n\n" .
+ $answer = -1;
+ print
"Open with?\n" .
- "0) mpv\n" .
- "1) fetch\n" .
- "2) sxiv\n" .
- "3) zathura\n" .
- "4) w3m\n" .
- "5) firefox\n\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" .
"> ";
- $answer = <STDIN>;
- if (!looks_like_number($answer) || $answer == 0 || $answer == 1 || $answer > 6) {
- $answer = -1;
+ open(TTY, "</dev/tty");
+ ReadMode "raw";
+ $answer = ReadKey 0, *TTY;
+ ReadMode "normal";
+ close(TTY);
+ print "\n\n";
+ if ($answer eq "\n") {
+ return 1;
+ }
+ if (
+ !looks_like_number($answer) ||
+ $answer < 0 ||
+ $answer > 8
+ ) {
+ print "linkview: bad answer\n";
+ return -1;
}
return $answer;
}
@@ -60,17 +123,20 @@ sub main
{
my $answer;
- system('tput', 'clear');
if (@ARGV == 0) {
- print STDERR "linkview: URL needed\n";
+ print STDERR "linkview: no URL\n";
exit 1;
}
- $answer = prompt($ARGV[0]);
- if ($answer == -1) {
- print STDERR "linkview: Bad answer\n";
- exit 2;
+ 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);
+ open_link($answer, $ARGV[0]);
return;
}
diff --git a/.local/bin/mpview b/.local/bin/mpview
index a66a75b..65fe97e 100755
--- a/.local/bin/mpview
+++ b/.local/bin/mpview
@@ -3,6 +3,7 @@
use strict;
use warnings;
use Scalar::Util qw(looks_like_number);
+use Term::ReadKey;
use Term::ANSIColor;
sub get_size
@@ -21,8 +22,18 @@ sub get_size
"6) 1080\n" .
"\n" .
"> ";
- $answer = <STDIN>;
- if (!looks_like_number($answer) || $answer == 0 || $answer == 1 || $answer > 6) {
+ open(TTY, "</dev/tty");
+ ReadMode "raw";
+ $answer = ReadKey 0, *TTY;
+ ReadMode "normal";
+ close(TTY);
+ print "\n";
+ if (
+ !looks_like_number($answer) ||
+ $answer == 0 ||
+ $answer == 1 ||
+ $answer > 6
+ ) {
$size = 0;
}
elsif ($answer == 2) {