2831c15b2d2ae65f063ff3f6b8fb4de2504c2679
2 # -*- coding: utf-8 -*-
4 # This script is a simple wrapper which prefixes each i3status line with custom
5 # information. It is based on:
6 # https://github.com/i3/i3status/blob/master/contrib/wrapper.py
8 # In ~/.i3status.conf, add the following line:
9 # output_format = "i3bar"
10 # in the 'general' section.
11 # Then, in ~/.config/i3/config or ~/.config/sway/config add:
12 # status_command i3status | my-i3status.py
13 # in the 'bar' section. Make sure my-i3status.py is in $PATH.
15 # © 2012 Valentin Haenel <valentin.haenel@gmx.de>
16 # © 2018 Amin Bandali <bandali@gnu.org>
18 # This program is free software. It comes without any warranty, to the extent
19 # permitted by applicable law. You can redistribute it and/or modify it under
20 # the terms of the Do What The Fuck You Want To Public License (WTFPL), Version
21 # 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
29 """ Return true if ~/.nosleep exists. """
30 return os
.path
.isfile(os
.path
.expanduser("~/.nosleep"))
32 def print_line(message
):
33 """ Non-buffered printing to stdout. """
34 sys
.stdout
.write(message
+ '\n')
38 """ Interrupted respecting reader for stdin. """
39 # try reading a line, removing any extra whitespace
41 line
= sys
.stdin
.readline().strip()
42 # i3status sends EOF, or an empty line
47 except KeyboardInterrupt:
50 if __name__
== '__main__':
51 # Skip the first line which contains the version header.
52 print_line(read_line())
54 # The second line contains the start of the infinite array.
55 print_line(read_line())
58 line
, prefix
= read_line(), ''
59 # ignore comma at start of lines
60 if line
.startswith(','):
61 line
, prefix
= line
[1:], ','
65 # insert information into the start of the json, but could be anywhere
66 j
.insert(0, {'full_text' : '•', 'name' : 'nosleep'})
67 # and echo back new encoded json
68 print_line(prefix
+json
.dumps(j
))
70 print_line(prefix
+line
)