From 694384e0e7165b358cd0a7b421df83e6ec29f272 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Mon, 24 Aug 2020 11:27:01 -0300 Subject: Added emojis to polybar, compressed information a bit --- .config/polybar/config | 76 ++++++++++---------- .config/polybar/keyboard_lang.sh | 10 +++ .config/polybar/mullvad_status.sh | 13 ++++ .config/polybar/spotify_status.py | 141 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 35 deletions(-) create mode 100755 .config/polybar/keyboard_lang.sh create mode 100755 .config/polybar/mullvad_status.sh create mode 100644 .config/polybar/spotify_status.py (limited to '.config/polybar') diff --git a/.config/polybar/config b/.config/polybar/config index 08e05b5d..f378a98c 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -8,17 +8,18 @@ accent = #fba922 [bar/top] +monitor = ${env:MONITOR:} enable-ipc = true width = 100% -height = 40 +height = 17 ;background = #222 -background = #000 +background = #33000000 foreground = #fff -overline-size = 10 +overline-size = 1 overline-color = ${self.background} -underline-size = 10 +underline-size = 1 underline-color = ${self.background} padding-left = 1 @@ -26,20 +27,15 @@ padding-right = 1 module-margin-left = 1 module-margin-right = 1 -font-0 = NotoSans-Regular:size=20;0 -font-1 = MaterialIcons:size=20;2 -font-2 = Termsynu:size=20;0 -font-3 = Siji:pixelsize=20;1 -font-4 = FontAwesome:size=20;0 -modules-left = i3 +font-0 = NotoSans-Regular:size=10;0 +font-1 = MaterialIcons:size=10;2 +font-2 = Termsynu:size=10;0 +font-3 = Siji:pixelsize=10;1 +font-4 = FontAwesome:size=10;0 +font-5 = Noto Color Emoji:scale=12;0 +modules-left = i3 spotify modules-center = xwindow -modules-right = pulseaudio xkeyboard xbacklight cpu memory wireless-network battery clock -; tray-position = right - -[module/xbacklight] -type = internal/xbacklight -format-prefix = "BL: " -label = %percentage:2%% +modules-right = pulseaudio xkeyboard cpu memory wireless-network mullvad-status battery clock [module/i3] type = internal/i3 @@ -56,7 +52,6 @@ label-focused-font = 4 label-focused-padding = 3 label-unfocused = %name% -label-unfocused-underline = #000 label-unfocused-font = 4 label-unfocused-padding = 3 @@ -75,14 +70,15 @@ label-visible-padding = 4 [module/cpu] type = internal/cpu interval = 2 -format-prefix = " " +format-prefix = "πŸŽ› " format-underline = #f90000 label = %percentage:2%% [module/memory] type = internal/memory interval = 2 -format-prefix = " ο‚€ " +; format-prefix = " ο‚€ " +format-prefix = " πŸ“Š " format-underline = #4bffdc label = %percentage_used%% @@ -91,27 +87,27 @@ type = internal/network interface = wlp2s0 interval = 2.0 ping-interval = 10 - -label-connected =  %essid% -label-disconnected = ξ‡š not connected +label-connected = πŸ“Ά %essid% +label-disconnected = 🚫 not connected label-disconnected-foreground = #66 [module/clock] type = internal/date interval = 5 format-padding = 5 -format-foreground = #fff -date = %%{F#bb} %d-%m-%Y%%{F-} %%{F#ee}ο€— %H:%M%%{F-} +date = πŸ“… %d-%m-%Y% πŸ•œ %H:%M% [module/battery] type = internal/battery -full-at = 100 -format-charging = %{T3}  %{T-} -format-discharging = %{T3} %{T-} -format-full = %{T3} %{T-} +full-at = 99 +battery = BAT0 +adapter = AC +format-charging = %{T4} πŸ”Œ %{T-} +format-discharging = %{T4}πŸ”‹ %{T-} +format-full = %{T4}πŸ”Œ %{T-} label-charging-font = 3 label-discharging-font = 3 -label-full = '100%' +label-full = 100% [module/xwindow] type = internal/xwindow @@ -119,12 +115,22 @@ label-maxlen = 75 label-foreground = #FFF [module/xkeyboard] -type = internal/xkeyboard -format-prefix = "layout: " -label-layout = %layout% +type = custom/script +exec = /home/roger/.config/polybar/keyboard_lang.sh +interval = 1 [module/pulseaudio] type = internal/pulseaudio -label-volume = ο‚’ %percentage%% -label-muted = ο‡· +label-volume = πŸ”Š %percentage%% +label-muted = πŸ”ˆ label-muted-foreground = #666 + +[module/spotify] +type = custom/script +interval = 1 +exec = python /home/roger/.config/polybar/spotify_status.py -t 80 --playpause-font=5 -p '⏯,⏸️' -f ' {play_pause} {song} - {artist} - {album}' + +[module/mullvad-status] +type = custom/script +exec = /home/roger/.config/polybar/mullvad_status.sh +interval = 1 diff --git a/.config/polybar/keyboard_lang.sh b/.config/polybar/keyboard_lang.sh new file mode 100755 index 00000000..00288f1b --- /dev/null +++ b/.config/polybar/keyboard_lang.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -euo pipefail + +LANG=$(setxkbmap -query | grep layout | awk -F ' ' '{print $2}') + +if [ "$LANG" = 'us' ]; then + echo "%{T5}󾓦%{T-}" +else + echo "%{T5}σΎ“«%{T-}" +fi diff --git a/.config/polybar/mullvad_status.sh b/.config/polybar/mullvad_status.sh new file mode 100755 index 00000000..fbca326c --- /dev/null +++ b/.config/polybar/mullvad_status.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +MULLVAD_STATUS=$(mullvad status) + +if echo $MULLVAD_STATUS | grep -q 'Connected'; then + echo "%{u#75d85a}VPN %{T5}βœ…%{T-}" + elif echo $MULLVAD_STATUS | grep -q 'Connecting'; then + echo "VPN ..." + else + echo "%{u#f90000}VPN %{T5}🚫%{T-}" +fi diff --git a/.config/polybar/spotify_status.py b/.config/polybar/spotify_status.py new file mode 100644 index 00000000..ff948f95 --- /dev/null +++ b/.config/polybar/spotify_status.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python + +import sys +import dbus +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument( + '-t', + '--trunclen', + type=int, + metavar='trunclen' +) +parser.add_argument( + '-f', + '--format', + type=str, + metavar='custom format', + dest='custom_format' +) +parser.add_argument( + '-p', + '--playpause', + type=str, + metavar='play-pause indicator', + dest='play_pause' +) +parser.add_argument( + '--font', + type=str, + metavar='the index of the font to use for the main label', + dest='font' +) +parser.add_argument( + '--playpause-font', + type=str, + metavar='the index of the font to use to display the playpause indicator', + dest='play_pause_font' +) +parser.add_argument( + '-q', + '--quiet', + action='store_true', + help="if set, don't show any output when the current song is paused", + dest='quiet', +) + +args = parser.parse_args() + + +def fix_string(string): + # corrects encoding for the python version used + if sys.version_info.major == 3: + return string + else: + return string.encode('utf-8') + + +def truncate(name, trunclen): + if len(name) > trunclen: + name = name[:trunclen] + name += '...' + if ('(' in name) and (')' not in name): + name += ')' + return name + + + +# Default parameters +output = fix_string(u'{play_pause} {artist}: {song}') +trunclen = 35 +play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused + +label_with_font = '%{{T{font}}}{label}%{{T-}}' +font = args.font +play_pause_font = args.play_pause_font + +quiet = args.quiet + +# parameters can be overwritten by args +if args.trunclen is not None: + trunclen = args.trunclen +if args.custom_format is not None: + output = args.custom_format +if args.play_pause is not None: + play_pause = args.play_pause + +try: + session_bus = dbus.SessionBus() + spotify_bus = session_bus.get_object( + 'org.mpris.MediaPlayer2.spotify', + '/org/mpris/MediaPlayer2' + ) + + spotify_properties = dbus.Interface( + spotify_bus, + 'org.freedesktop.DBus.Properties' + ) + + metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata') + status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus') + + # Handle play/pause label + + play_pause = play_pause.split(',') + + if status == 'Playing': + play_pause = play_pause[0] + elif status == 'Paused': + play_pause = play_pause[1] + else: + play_pause = str() + + if play_pause_font: + play_pause = label_with_font.format(font=play_pause_font, label=play_pause) + + # Handle main label + + artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else '' + song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else '' + album = fix_string(metadata['xesam:album']) if metadata['xesam:album'] else '' + + if (quiet and status == 'Paused') or (not artist and not song and not album): + print('') + else: + if font: + artist = label_with_font.format(font=font, label=artist) + song = label_with_font.format(font=font, label=song) + album = label_with_font.format(font=font, label=album) + + # Add 4 to trunclen to account for status symbol, spaces, and other padding characters + print(truncate(output.format(artist=artist, + song=song, + play_pause=play_pause, + album=album), trunclen + 4)) + +except Exception as e: + if isinstance(e, dbus.exceptions.DBusException): + print('') + else: + print(e) -- cgit v1.2.3