summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2012-06-10 19:42:53 +0200
committerMichael Stapelberg <michael@stapelberg.de>2012-06-10 19:42:53 +0200
commit2e3490141d49680e317c5a66de1ccb2d8b8634d1 (patch)
tree4ac415596b66d07aa51f4ee4d4821dcf9f82ccbb /contrib
parent850f6720b5b7323a2b986d8da1baa04077278323 (diff)
add a small perl example wrapper script for i3status’s JSON output
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/wrapper.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/wrapper.pl b/contrib/wrapper.pl
new file mode 100755
index 0000000..7838132
--- /dev/null
+++ b/contrib/wrapper.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+# vim:ts=4:sw=4:expandtab
+# © 2012 Michael Stapelberg, Public Domain
+
+# This script is a simple wrapper which prefixes each i3status line with custom
+# information. To use it, ensure your ~/.i3status.conf contains this line:
+# output_format = "i3bar"
+# in the 'general' section.
+# Then, in your ~/.i3/config, use:
+# status_command i3status | ~/i3status/contrib/wrapper.pl
+# In the 'bar' section.
+
+use strict;
+use warnings;
+# You can install the JSON module with 'cpan JSON' or by using your
+# distribution’s package management system, for example apt-get install
+# libjson-perl on Debian/Ubuntu.
+use JSON;
+
+# Don’t buffer any output.
+$| = 1;
+
+# Skip the first line which contains the version header.
+print scalar <STDIN>;
+
+# The second line contains the start of the infinite array.
+print scalar <STDIN>;
+
+# Read lines forever, ignore a comma at the beginning if it exists.
+while (my ($statusline) = (<STDIN> =~ /^,?(.*)/)) {
+ # Decode the JSON-encoded line.
+ my @blocks = @{decode_json($statusline)};
+
+ # Prefix our own information (you could also suffix or insert in the
+ # middle).
+ @blocks = ({
+ full_text => 'MPD: not running',
+ name => 'mpd'
+ }, @blocks);
+
+ # Output the line as JSON.
+ print encode_json(\@blocks) . ",\n";
+}