diff options
author | Amin Bandali <bandali@gnu.org> | 2019-04-12 23:39:24 -0400 |
---|---|---|
committer | Amin Bandali <bandali@gnu.org> | 2019-04-13 00:40:17 -0400 |
commit | a92a01fe479e3b069e23297cb3b541eb273deb58 (patch) | |
tree | 092762963a81ac538b16deda8e2e1c7ea3fc1e2b /.local/bin/my-i3status | |
parent | ec80f07afe6f0985de1aff4d321292c93b3cb4ef (diff) | |
download | configs-a92a01fe479e3b069e23297cb3b541eb273deb58.tar.gz configs-a92a01fe479e3b069e23297cb3b541eb273deb58.tar.xz configs-a92a01fe479e3b069e23297cb3b541eb273deb58.zip |
scripts: pull current scripts out of rc.org & clean up
battery-percentage-time: pull out of rc.org scripts
my-i3status: pull out of rc.org
rofi-light: pull out of rc.org
rofi-remmina: pull out of rc.org
s: pull out of rc.org
sway-ws-util: pull out of rc.org
toggle-presentation-mode: pull out of rc.org
toggle-tablet: pull out of rc.org
volume-info: pull out of rc.org
zathura-sync: pull out of rc.org
remove Scripts
Diffstat (limited to '.local/bin/my-i3status')
-rwxr-xr-x | .local/bin/my-i3status | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/.local/bin/my-i3status b/.local/bin/my-i3status new file mode 100755 index 0000000..2831c15 --- /dev/null +++ b/.local/bin/my-i3status @@ -0,0 +1,70 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- + +# This script is a simple wrapper which prefixes each i3status line with custom +# information. It is based on: +# https://github.com/i3/i3status/blob/master/contrib/wrapper.py +# +# In ~/.i3status.conf, add the following line: +# output_format = "i3bar" +# in the 'general' section. +# Then, in ~/.config/i3/config or ~/.config/sway/config add: +# status_command i3status | my-i3status.py +# in the 'bar' section. Make sure my-i3status.py is in $PATH. +# +# © 2012 Valentin Haenel <valentin.haenel@gmx.de> +# © 2018 Amin Bandali <bandali@gnu.org> +# +# This program is free software. It comes without any warranty, to the extent +# permitted by applicable law. You can redistribute it and/or modify it under +# the terms of the Do What The Fuck You Want To Public License (WTFPL), Version +# 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more +# details. + +import sys +import json +import os + +def get_nosleep(): + """ Return true if ~/.nosleep exists. """ + return os.path.isfile(os.path.expanduser("~/.nosleep")) + +def print_line(message): + """ Non-buffered printing to stdout. """ + sys.stdout.write(message + '\n') + sys.stdout.flush() + +def read_line(): + """ Interrupted respecting reader for stdin. """ + # try reading a line, removing any extra whitespace + try: + line = sys.stdin.readline().strip() + # i3status sends EOF, or an empty line + if not line: + sys.exit(3) + return line + # exit on ctrl-c + except KeyboardInterrupt: + sys.exit() + +if __name__ == '__main__': + # Skip the first line which contains the version header. + print_line(read_line()) + + # The second line contains the start of the infinite array. + print_line(read_line()) + + while True: + line, prefix = read_line(), '' + # ignore comma at start of lines + if line.startswith(','): + line, prefix = line[1:], ',' + + if get_nosleep(): + j = json.loads(line) + # insert information into the start of the json, but could be anywhere + j.insert(0, {'full_text' : '•', 'name' : 'nosleep'}) + # and echo back new encoded json + print_line(prefix+json.dumps(j)) + else: + print_line(prefix+line) |