2 # -*- coding: utf-8 -*-
4 # This script is a simple wrapper which prefixes each i3status line with custom
5 # information. It is a python reimplementation of:
6 # http://code.stapelberg.de/git/i3status/tree/contrib/wrapper.pl
8 # To use it, ensure your ~/.i3status.conf contains this line:
9 # output_format = "i3bar"
10 # in the 'general' section.
11 # Then, in your ~/.i3/config, use:
12 # status_command i3status | ~/i3status/contrib/wrapper.py
13 # In the 'bar' section.
15 # In its current version it will display the cpu frequency governor, but you
16 # are free to change it to display whatever you like, see the comment in the
19 # © 2012 Valentin Haenel <valentin.haenel@gmx.de>
21 # This program is free software. It comes without any warranty, to the extent
22 # permitted by applicable law. You can redistribute it and/or modify it under
23 # the terms of the Do What The Fuck You Want To Public License (WTFPL), Version
24 # 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
31 """ Get the current governor for cpu0, assuming all CPUs use the same. """
32 with open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor') as fp:
33 return fp.readlines()[0].strip()
35 def print_line(message):
36 """ Non-buffered printing to stdout. """
37 sys.stdout.write(message + '\n')
41 """ Interrupted respecting reader for stdin. """
42 # try reading a line, removing any extra whitespace
44 line = sys.stdin.readline().strip()
45 # i3status sends EOF, or an empty line
50 except KeyboardInterrupt:
53 if __name__ == '__main__':
54 # Skip the first line which contains the version header.
55 print_line(read_line())
57 # The second line contains the start of the infinite array.
58 print_line(read_line())
61 line, prefix = read_line(), ''
62 # ignore comma at start of lines
63 if line.startswith(','):
64 line, prefix = line[1:], ','
67 # insert information into the start of the json, but could be anywhere
68 # CHANGE THIS LINE TO INSERT SOMETHING ELSE
69 j.insert(0, {'full_text' : '%s' % get_governor(), 'name' : 'gov'})
70 # and echo back new encoded json
71 print_line(prefix+json.dumps(j))