aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i3/.i3status.conf5
-rwxr-xr-xi3/bin/i3status.py51
2 files changed, 48 insertions, 8 deletions
diff --git a/i3/.i3status.conf b/i3/.i3status.conf
index 1163e40..0b7c09f 100644
--- a/i3/.i3status.conf
+++ b/i3/.i3status.conf
@@ -4,7 +4,6 @@ general {
output_format = "i3bar"
}
-order += "cmd nowplaying"
order += "volume master"
order += "wireless wlp2s0"
order += "battery 0"
@@ -20,10 +19,6 @@ volume master {
mixer_idx = 0
}
-cmd nowplaying {
- cmd = "cmus-remote -Q | grep '^tag \\(artist\\|album\\|title\\) ' | sort | cut -d' ' -f 3- | tr '\\n' '\t' | awk 'BEGIN { FS = \"\\t\" } ; { print \"♪: \" $3 \" (\" $1 \", \" $2 \")\" }'; echo -n ' '"
-}
-
wireless wlp2s0 {
format_up = "%essid: %quality, %bitrate (%ip)"
format_down = "wlan0 down"
diff --git a/i3/bin/i3status.py b/i3/bin/i3status.py
index ce562b1..1a2d166 100755
--- a/i3/bin/i3status.py
+++ b/i3/bin/i3status.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import json
from select import select
-from subprocess import Popen, PIPE
+from subprocess import check_output, Popen, PIPE
import sys
def remove_empty_outputs(obj):
@@ -33,6 +33,46 @@ def parse_kbdlayout(s):
color = '#cccccc'
return [{'full_text': s, 'color': color}]
+def print_album_and_artist(info, parentheses):
+ if 'album' in info:
+ if 'artist' in info:
+ if parentheses:
+ return info['album'] + ' (' + info['artist'] + ')'
+ else:
+ return info['album'] + ', ' + info['artist']
+ else:
+ return info['album']
+ elif 'artist' in info:
+ return info['artist']
+ else:
+ return None
+
+def get_cmus_song():
+ result = check_output(['cmus-remote', '-Q'])
+ info = {}
+ for line in result.split('\n'):
+ if line[:10] == 'tag title ':
+ info['title'] = line[10:]
+ elif line[:10] == 'tag album ':
+ info['album'] = line[10:]
+ elif line[:11] == 'tag artist ':
+ info['artist'] = line[11:]
+
+ album_and_artist = print_album_and_artist(info, 'title' not in info)
+ text = None
+ if album_and_artist is None:
+ if 'title' in info:
+ text = info['title']
+ elif 'title' in info:
+ text = info['title'] + ' (' + album_and_artist + ')'
+ else:
+ text = album_and_artist
+
+ if text is None:
+ return []
+ else:
+ return [{'full_text': text}]
+
def merge_status_items(*args):
return [item for sublist in args for item in sublist]
@@ -47,7 +87,7 @@ if __name__ == '__main__':
sys.stdout.write(i3stat.stdout.readline())
sys.stdout.write(i3stat.stdout.readline())
- stat, kbd, clg = [], [], []
+ stat, kbd, cmus = [], [], []
try:
stdouts = [p.stdout for p in [i3stat, kbdlayout]]
while True:
@@ -58,8 +98,13 @@ if __name__ == '__main__':
kbd = parse_kbdlayout(line)
elif f == i3stat.stdout:
stat = parse_i3stat(line)
+
+ try:
+ cmus = get_cmus_song()
+ except:
+ cmus = []
- print_i3stat(merge_status_items(kbd, clg, stat))
+ print_i3stat(merge_status_items(kbd, cmus, stat))
except Exception, e:
print(e)