summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-12-12 00:44:24 +0100
committerFlorian Pritz <bluewind@xinu.at>2017-12-12 00:44:24 +0100
commit75827353b4ece85cb4e1e927404692f136b270b8 (patch)
tree02ed358fc2dd17c1d8c69e263e9f66105f41faa2
parent1f005773df11ea43d886476e922b8fefe9f2a6a1 (diff)
downloaddotfiles-75827353b4ece85cb4e1e927404692f136b270b8.tar.gz
dotfiles-75827353b4ece85cb4e1e927404692f136b270b8.tar.xz
i3: Rewrite conky wrapper in perl
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--.i3/config2
-rwxr-xr-x.i3/conky-wrapper.pl65
-rw-r--r--.i3/conkyrc-perl56
3 files changed, 122 insertions, 1 deletions
diff --git a/.i3/config b/.i3/config
index 791e396..c5c4dab 100644
--- a/.i3/config
+++ b/.i3/config
@@ -198,7 +198,7 @@ bar {
font pango:DejaVu Sans Mono 9
position top
#tray_output DP-2
- status_command bash ~/.i3/conky-wrapper.sh
+ status_command perl ~/.i3/conky-wrapper.pl
#status_command i3status
#output eDP1
#output HDMI1
diff --git a/.i3/conky-wrapper.pl b/.i3/conky-wrapper.pl
new file mode 100755
index 0000000..2ab2925
--- /dev/null
+++ b/.i3/conky-wrapper.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+use v5.14;
+use strict;
+use warnings;
+
+use JSON;
+use Clone 'clone';
+use IO::Handle;
+
+# Send the header so that i3bar knows we want to use JSON:
+printf "%s", '{"version":1}';
+
+# Begin the endless array.
+printf "%s", '[';
+
+# We send an empty first array of blocks to make the loop simpler:
+printf "%s",'[],';
+
+open my $conky, "-|:encoding(utf8)", "conky -c $ENV{HOME}/.i3/conkyrc-perl";
+STDOUT->autoflush();
+
+my @data;
+my %in_progress;
+my $json = JSON->new;
+$json->ascii([1]);
+
+my %simple_mappings = (
+ "SHORTTEXT" => "shorttext",
+);
+
+while (<$conky>) {
+ chomp($_);
+
+ next if m/^\s+$/;
+
+ if (m/^END_BLOCK$/) {
+ STDOUT->printf("%s,\n", $json->encode(\@data));
+ undef @data;
+ next;
+ }
+
+ if (m/^COLOR: (#[a-zA-Z0-9]+)$/) {
+ $in_progress{color} = $1;
+ next;
+ }
+
+ for my $key (keys %simple_mappings) {
+ if (m/^$key: (.*)$/) {
+ $in_progress{$simple_mappings{$key}} = $1;
+ next;
+ }
+ }
+
+ if (m/^FULLTEXT: (.*)$/) {
+ my $fulltext = $1;
+ $in_progress{full_text} = $fulltext;
+ push @data, clone \%in_progress;
+ undef %in_progress;
+ next;
+ }
+
+ printf STDERR "Got unexpected data: %s\n", $_;
+}
+
diff --git a/.i3/conkyrc-perl b/.i3/conkyrc-perl
new file mode 100644
index 0000000..e743f09
--- /dev/null
+++ b/.i3/conkyrc-perl
@@ -0,0 +1,56 @@
+out_to_x no
+own_window no
+out_to_console yes
+background no
+max_text_width 0
+update_interval 0.5
+total_run_times 0
+short_units yes
+if_up_strictness link
+use_spacer none
+override_utf8_locale no
+cpu_avg_samples 6
+net_avg_samples 6
+
+mpd_host localhost
+mpd_port 6600
+
+TEXT
+
+${if_match "${mpd_status}" == "Playing"}
+COLOR: \#d466138
+FULLTEXT: ${mpd_artist} - ${mpd_title} (${mpd_vol}%)
+${endif}
+
+COLOR: \#00FF00
+FULLTEXT: intern0 ${upspeed intern0}↑ ${downspeed intern0}↓
+
+${if_up guest0}
+COLOR: \#FF0000
+FULLTEXT: guest0 ${upspeed guest0}↑ ${downspeed guest0}↓
+${endif}
+
+${if_up usb0}
+COLOR: \#FF0000
+FULLTEXT: usb0 ${upspeed usb0}↑ ${downspeed usb0}↓
+${endif}
+
+# { "full_text" : "IO ${diskio_read}↑ ${diskio_write}↓"},
+FULLTEXT: PA ${pa_sink_volume}%
+
+FULLTEXT: / ${fs_free /}
+FULLTEXT: /home ${fs_free /home}
+
+COLOR: \#55ff55
+FULLTEXT: CPU ${cpu cpu}%
+
+COLOR: ${if_match ${memperc}<80}\#55ff55${else}\#ff0000${endif}
+FULLTEXT: RAM ${mem} (${memperc}%)
+
+FULLTEXT: ${loadavg} ${running_threads}/${processes}
+FULLTEXT: Up ${uptime}
+
+SHORTTEXT: ${time %F %H:%M:%S}
+FULLTEXT: ${time %a %F %H:%M:%S
+
+END_BLOCK