summaryrefslogtreecommitdiffstats
path: root/.local/bin/shutup
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2022-04-09 00:10:29 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2022-04-09 00:13:36 +0200
commit472a06e38139679a2815d312a72efe76af7b82c6 (patch)
tree3a4dce209cb89c041d34e9c19c1d53fe9445e66d /.local/bin/shutup
parentin progress (diff)
downloaddotfiles-bsd-472a06e38139679a2815d312a72efe76af7b82c6.tar.gz
dotfiles-bsd-472a06e38139679a2815d312a72efe76af7b82c6.tar.bz2
dotfiles-bsd-472a06e38139679a2815d312a72efe76af7b82c6.tar.xz
dotfiles-bsd-472a06e38139679a2815d312a72efe76af7b82c6.tar.zst
dotfiles-bsd-472a06e38139679a2815d312a72efe76af7b82c6.zip
Good
Diffstat (limited to '.local/bin/shutup')
-rwxr-xr-x.local/bin/shutup85
1 files changed, 69 insertions, 16 deletions
diff --git a/.local/bin/shutup b/.local/bin/shutup
index 6c53484..ccb6888 100755
--- a/.local/bin/shutup
+++ b/.local/bin/shutup
@@ -7,43 +7,96 @@ use File::HomeDir qw(home);
use constant {
BSDSETSID_PATH => '/usr/local/bin/bsdsetsid',
DUNSTRC_PATH => home() . '/.config/dunst/dunstrc',
- DUNSTRC_PATH => '/usr/local/bin/dunst',
- MPD_NOTIFICATION_PATH => '/usr/local/bin/mpd-notification',
+ DUNST_PATH => '/usr/local/bin/dunst',
+ MPDNOTIFICATION_PATH => '/usr/local/bin/mpd-notification',
NOTIFYSEND_PATH => '/usr/local/bin/notify-send',
PKILL_PATH => '/bin/pkill'
};
-sub kill_programs() {
+sub kill_programs
+{
system(PKILL_PATH, 'espeak');
system(PKILL_PATH, 'mpd-notification');
system(PKILL_PATH, 'dunst');
}
-sub start_programs() {
+sub start_programs
+{
system(BSDSETSID_PATH, DUNST_PATH);
- system(BSDSETSID_PATH, MPD_NOTIFICATION_PATH);
+ system(BSDSETSID_PATH, MPDNOTIFICATION_PATH);
}
-sub main()
+sub get_buffer
{
- my $i;
my @lines;
- kill_programs();
open(FH, '<', DUNSTRC_PATH) or die $!;
- @lines = do {
- local $/;
- <FH>
- };
+ @lines = <FH>;
close(FH);
- for ($i = 0; $i < @lines, $i++) {
- last if $lines[$i];
+ return @lines;
+}
+
+sub notify
+{
+ my ($notif) = @_;
+
+ if ($notif) {
+ system(NOTIFYSEND_PATH,
+ '-u', 'normal',
+ '-t', '1750',
+ 'espeak', '墳 espeak restored');
+ }
+ else {
+ system(NOTIFYSEND_PATH,
+ '-u', 'normal',
+ '-t', '1750',
+ 'espeak', '婢 espeak silenced');
}
- print $lines[$i];
- open(FH, '>', home() . '/tmp') or die $!;
+}
+
+sub write_config
+{
+ my (@lines) = @_;
+
+ open(FH, '>', DUNSTRC_PATH) or die $!;
print FH @lines;
close(FH);
+}
+
+sub toggle_config
+{
+ my (@lines) = @_;
+ my $ret;
+ my $i;
+ my $j;
+
+ for ($i = 0; $i < @lines; $i++) {
+ last if $lines[$i] =~ m/# >shutup/;
+ }
+ $j = 0;
+ while ($j < 2) {
+ if ($lines[$i + $j] =~ m/^#/) {
+ $lines[$i + $j] =~ s/^#//;
+ $ret = 1;
+ }
+ else {
+ $lines[$i + $j] =~ s/^/#/;
+ $ret = 0;
+ }
+ $j++;
+ }
+ write_config(@lines);
+ return $ret;
+}
+
+sub main
+{
+ my $notif;
+
+ kill_programs();
+ $notif = toggle_config(get_buffer());
start_programs();
+ notify($notif);
return;
}