diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-03-04 10:21:34 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-03-04 10:21:34 -0700 |
commit | 752aa419fde8838f79115ee109bcdbd7d6e9230e (patch) | |
tree | 015bc3b010b0a7ecb69a809c72163ff69cf75f0c /scripts | |
parent | 7de922d5c31d45102f1a132ed5c24f9550b81da1 (diff) | |
download | dotfiles-752aa419fde8838f79115ee109bcdbd7d6e9230e.tar.gz |
move i3status-wrapper
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/desktop/i3status-wrapper | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper new file mode 100755 index 00000000..7e518666 --- /dev/null +++ b/scripts/desktop/i3status-wrapper @@ -0,0 +1,48 @@ +#!/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; + +use Sys::Hostname; + +# 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>; + +my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<); +my $hostname = hostname; + +# 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 => $username . "@" . $hostname, + name => 'hostinfo' + }, @blocks); + + # Output the line as JSON. + print encode_json(\@blocks) . ",\n"; +} |