diff options
Diffstat (limited to '.local')
-rwxr-xr-x | .local/bin/linkview | 108 | ||||
-rwxr-xr-x | .local/bin/mic | 35 |
2 files changed, 48 insertions, 95 deletions
diff --git a/.local/bin/linkview b/.local/bin/linkview index a4183c3..097d8be 100755 --- a/.local/bin/linkview +++ b/.local/bin/linkview @@ -48,6 +48,17 @@ use constant QUAL_LIST => "" . "240" . "\n" . "144" . "\n"; +sub notify +{ + my ($str) = @_; + + my $pid = fork(); + if (not $pid) { + exec(NOTIFYSEND_PATH, $str); + } + return; +}; + sub vid { my ($url, $article_name) = @_; @@ -58,15 +69,9 @@ sub vid if (not $pid) { setsid(); close_io(); - system( - NOTIFYSEND_PATH, - ' playing ' . $article_name - ); + notify(' playing ' . $article_name); if (system(MPV_PATH, "--force-window=yes", $url) != 0) { - exec( - NOTIFYSEND_PATH, - ' failed to open ' . $url - ); + notify(' failed to open ' . $url); } return; } @@ -93,28 +98,19 @@ sub img_pdf $file_name = $url; $file_name =~ s/.+\///g; if (is_yt($url) != 0) { - system( - NOTIFYSEND_PATH, - ' fetching thumbnail for ' . $article_name - ); + notify(' fetching thumbnail for ' . $article_name); ($tmp, undef, $ret) = capture { system(YTDL_PATH, '--get-thumbnail', $url); }; chomp $tmp; if ($ret != 0) { - system( - NOTIFYSEND_PATH, - ' failed to get thumbail for ' . $article_name - ); + notify(' failed to get thumbail for ' . $article_name); return; } $url = $tmp; } else { - system( - NOTIFYSEND_PATH, - ' fetching ' . $file_name . ' to /tmp' - ); + notify(' fetching ' . $file_name . ' to /tmp'); } $file_name = $url; $file_name =~ s/.+\///g; @@ -136,10 +132,7 @@ sub img_pdf $ret = system(ZATHURA_PATH, $new_file_name); } if ($ret != 0) { - system( - NOTIFYSEND_PATH, - ' failed to open file /tmp/'. $new_file_name - ); + notify(' failed to open file /tmp/'. $new_file_name); } unlink($new_file_name); return; @@ -204,10 +197,7 @@ sub dl $file_name .= "[...]"; } $file_name =~ s/^[0-9]+/\[\.\.\.\]/; - system( - NOTIFYSEND_PATH, - ' downloading ' . $file_name - ); + notify(' downloading ' . $file_name); if (is_yt($url) != 0) { $tmpfile = `mktemp`; chomp $tmpfile; @@ -231,24 +221,15 @@ sub dl } }; if ($ret == 0) { - system( - NOTIFYSEND_PATH, - ' ' . $file_name . ' downloaded successfully to ' . $pwd - ); + notify(' ' . $file_name . ' downloaded successfully to ' . $pwd); } else { - system( - NOTIFYSEND_PATH, - ' failed to download ' . $file_name - ); + notify(' failed to download ' . $file_name); } return; } elsif ($pid2 < 0) { - system( - NOTIFYSEND_PATH, - ' failed to fork(2)' - ); + notify(' failed to fork(2)'); return; } else { @@ -256,11 +237,8 @@ sub dl while (1) { $val = `tail -n 1 "$tmpfile" | awk '{print \$2}' | tr -d '%'`; if (looks_like_number($val) != 0) { - system( - NOTIFYSEND_PATH, - ' downloading ' . $file_name . ': - ' . $val - ); + notify(' downloading ' . $file_name . ': + ' . $val); if ($val == 100 || system('pgrep yt-dlp >/dev/null 2>&1') != 0) { last; } @@ -286,25 +264,16 @@ sub dl } }; if ($ret == 0) { - system( - NOTIFYSEND_PATH, - ' ' . $file_name . ' downloaded successfully to ' . $pwd - ); + notify(' ' . $file_name . ' downloaded successfully to ' . $pwd); } else { - system( - NOTIFYSEND_PATH, - ' failed to download ' . $file_name - ); + notify(' failed to download ' . $file_name); } } return; } elsif ($pid < 0) { - system( - NOTIFYSEND_PATH, - ' failed to fork(2)' - ); + notify(' failed to fork(2)'); return; } return; @@ -319,10 +288,7 @@ sub audio if (not $pid) { setsid(); close_io(); - system( - NOTIFYSEND_PATH, - ' playing ' . $article_name - ); + notify(' playing ' . $article_name); if (system( TERMINAL_PATH, "-e", @@ -332,10 +298,7 @@ sub audio "--no-video", $url ) != 0) { - exec( - NOTIFYSEND_PATH, - ' failed to open ' . $url - ); + notify(' failed to open ' . $url); } return; } @@ -352,10 +315,7 @@ sub w3m setsid(); close_io(); if (system(TERMINAL_PATH, '-e', W3M_PATH, $url) != 0) { - exec( - NOTIFYSEND_PATH, - ' failed to open ' . $url - ); + notify(' failed to open ' . $url); } return; } @@ -407,10 +367,7 @@ sub clip exec(COPYQ_PATH, "copy", $url); } } - system( - NOTIFYSEND_PATH, - ' clipped url' - ); + notify(' clipped url'); return; } @@ -442,10 +399,7 @@ sub get_yt_vid_name my ($url) = @_; my $file_name; - system( - NOTIFYSEND_PATH, - ' looking for video name' - ); + notify(' looking for video name'); $file_name = `yt-dlp -e $url`; if (not $file_name) { $file_name = "yt video"; diff --git a/.local/bin/mic b/.local/bin/mic index 31c9f43..19a0fd6 100755 --- a/.local/bin/mic +++ b/.local/bin/mic @@ -10,7 +10,18 @@ use constant { NOTIF_PATH => '/usr/local/bin/herbe' }; -sub main +sub notify +{ + my ($str) = @_; + + my $pid = fork(); + if (not $pid) { + exec(NOTIF_PATH, $str); + } + return; +}; + +sub mic { my $rec_vol; my $host; @@ -21,16 +32,10 @@ sub main my $muted = `/usr/bin/pactl get-source-mute \@DEFAULT_SOURCE\@ | awk '{print \$2}'`; chomp $muted; if ($muted eq "yes") { - system( - '/usr/local/bin/herbe', - ' muted' - ); + notify(' muted'); } else { - system( - '/usr/local/bin/herbe', - ' restored' - ); + notify(' restored'); } exit; } @@ -40,24 +45,18 @@ sub main capture { system(MIXER_PATH, 'rec', '100'); }; - system( - NOTIF_PATH, - ' microphone restored' - ); + notify(' microphone restored'); } else { capture { system(MIXER_PATH, 'rec', '0'); - system( - NOTIF_PATH, - ' microphone muted' - ); + notify(' microphone muted'); }; } system('kill -68 $(pidof dwmblocks)'); return; } -main(); +mic(); __END__ |