]> git.sev.monster Git - dotfiles.git/blob - bin/i3subscribe
prompt_arrows_setup: make comment more readable
[dotfiles.git] / bin / i3subscribe
1 #!/usr/bin/env perl
2
3 BEGIN { $| = 1 } # flush \n
4
5 use strict;
6 use warnings;
7 use Data::Dumper;
8 use AnyEvent::I3;
9 use v5.10;
10
11 my $i3 = i3();
12 $i3->connect->recv or die "Error connecting to i3";
13
14 sub subscribe {
15     my $ev = $_[0];
16     my $dump = $_[1];
17     if($i3->subscribe({
18         $ev => sub {
19             my ($msg) = @_;
20             say "$ev:$msg->{'change'}";
21             if($dump) {
22                 print Dumper($msg);
23             }
24         }
25     })->recv->{success}) {
26         say "Successfully subscribed to $ev event";
27     }
28 }
29
30 my $nextArg = shift;
31 if(!$nextArg) {
32     say "Subscribe to i3 events";
33     say "Usage:   $0 workspace|output|mode|window|barconfig_update|binding [dump]";
34     say "Example: $0 workspace dump window binding dump";
35     exit 1;
36 }
37 while($nextArg) {
38     my $arg = $nextArg;
39     $nextArg = shift;
40     my $dump = 0;
41     if($nextArg and $nextArg eq "dump") {
42         $dump = 1;
43         $nextArg = shift;
44     }
45     subscribe("$arg", $dump);
46 }
47 AE::cv->recv;
48
49 # vim: et:ts=4:sts=4
This page took 0.045505 seconds and 4 git commands to generate.