Refactor polybar config

This commit is contained in:
Henrik Lissner 2019-11-26 19:25:51 -05:00
parent d2b9b9ae6c
commit 7381c53e81
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
6 changed files with 9 additions and 170 deletions

View file

@ -63,8 +63,7 @@ font-2 = "Siji:pixelsize=10;2"
; modules-left = volume pad cpu memory pad pkg mail ; modules-left = volume pad cpu memory pad pkg mail
modules-left = volume pad cpu memory modules-left = volume pad cpu memory
modules-center = bspwm modules-center = bspwm
; modules-right = battery wlan app-rslsync app-redshift pad date modules-right = battery wlan syncthing redshift pad date
modules-right = battery wlan app-redshift pad date
;tray-position = center ;tray-position = center
;tray-padding = 2 ;tray-padding = 2
@ -303,34 +302,19 @@ type = custom/text
content = " " content = " "
content-foreground = ${colors.fg-alt} content-foreground = ${colors.fg-alt}
[module/pkg] [module/redshift]
type = custom/ipc type = custom/script
hook-0 = ~/.config/polybar/modules/updates exec = ~/.config/polybar/modules/redshift
initial = 1 exec-if = pgrep -x redshift
click-left = polybar-msg -p %pid% hook pkg 1 interval = 60
format-padding = 1 format-padding = 1
[module/mail] [module/syncthing]
type = custom/ipc
hook-0 = ~/.config/polybar/modules/mail
initial = 1
click-left = polybar-msg -p %pid% hook mail 1
format-padding-right = 1
[module/app-redshift]
type = custom/script type = custom/script
exec = echo 1 exec = echo 1
exec-if = pgrep -x redshift exec-if = systemctl is-active syncthing
format = ""
format-foreground = ${colors.icons}
interval = 2
[module/app-rslsync]
type = custom/script
exec = echo 1
exec-if = pgrep -x rslsync
format = "" format = ""
format-foreground = ${colors.icons} format-foreground = ${colors.icons}
interval = 60 interval = 30
; vim:ft=dosini ; vim:ft=dosini

View file

@ -1,9 +0,0 @@
#!/usr/bin/env bash
icon=""
if pgrep -x rslsync &> /dev/null; then
echo "%{F#e5e8e6}$icon"
else
echo "%{F#65737E}$icon"
fi

View file

@ -1,92 +0,0 @@
#!/usr/bin/env python3
import imaplib
import os
import sys
import socket
from subprocess import Popen
CONFIG_FILE = os.path.expanduser("~/.secrets/email")
CACHE_FILE = "/tmp/polybar-mail"
ICON = ""
try:
import gnupg
from pathlib import Path
except ImportError:
print("%{{F{}}}*".format("#555856", ICON))
sys.exit(1)
#
def internet_is_on():
try:
host = socket.gethostbyname("www.google.com")
socket.create_connection((host, 80), 2)
return True
except:
pass
return False
def unread_count(address, password):
imap = imaplib.IMAP4_SSL('imap.gmail.com', 993)
imap.login(address, password)
imap.select('INBOX')
status, resp = imap.search(None, 'UNSEEN')
imap.close()
imap.logout()
return len(resp[0].split())
def ding():
Popen(["{}/bin/ding".format(os.getenv("DOTFILES", os.expanduser("~/.dotfiles")))])
#
def main():
try:
if not internet_is_on():
raise IOError("Internet is off")
secrets = Path(CONFIG_FILE)
if not secrets.exists():
raise IOError("Can't find secrets")
gpg = gnupg.GPG()
gpgdata = gpg.decrypt(secrets.read_bytes())
if not gpgdata.ok:
raise IOError("Couldn't decrypt secrets: {}".format(gpgdata.status))
accounts = [line.split(':') for line in gpgdata.data.decode('utf-8').strip().split('\n')]
last_total = 0
cache = Path(CACHE_FILE)
if cache.exists():
cache_text = cache.read_text()
last_total = int(cache.read_text())
total = 0
for addr, pwd in accounts:
total += unread_count(addr, pwd)
if total != last_total:
ding()
if total != 0:
print("%{{F{}}}{}{}".format("#f0c674", ICON, total))
else:
print("%{{F{}}}{}".format("#555856", ICON))
cache.write_text(str(total))
except IOError as e:
print("ERROR: {}".format(e), file=sys.stderr)
print("%{{F{}}}{}!".format("#cc6666", ICON))
sys.exit(1)
#
if __name__ == '__main__':
if sys.argv[1:]:
print("%{{F{}}}{}".format("#555856", ICON))
else:
main()

View file

@ -1,22 +0,0 @@
#!/usr/bin/env zsh
icon=""
if [[ $1 == "1" ]]; then
echo "%{F#555856}${icon}%{F-}"
exit
fi
pac=$(checkupdates 2>/dev/null | wc -l)
aur=$(yay -Pn 2>/dev/null)
[[ -f /tmp/polybar-updates ]] && last=$(</tmp/polybar-updates)
check=$((pac + aur))
if [[ "$check" != "0" ]]; then
echo "%{F#b5bd68}${icon}$pac+$aur%{F-}"
if [[ $last != "$pac$aur" ]]; then
notify-send "$((pac+aur)) updates available"
ding updates
echo "$pac$aur" >/tmp/polybar-updates
fi
else
echo "%{F#555856}${icon}%{F-}"
fi

View file

@ -1,22 +0,0 @@
#!/usr/bin/env zsh
icon=""
if [[ $1 == "1" ]]; then
echo "%{F#555856}${icon}%{F-}"
exit
fi
pac=$(checkupdates 2>/dev/null | wc -l)
aur=$(yay -Pn 2>/dev/null)
[[ -f /tmp/polybar-updates ]] && last=$(</tmp/polybar-updates)
check=$((pac + aur))
if [[ "$check" != "0" ]]; then
echo "%{F#b5bd68}${icon}$pac+$aur%{F-}"
if [[ $last != "$pac$aur" ]]; then
notify-send "$((pac+aur)) updates available"
ding updates
echo "$pac$aur" >/tmp/polybar-updates
fi
else
echo "%{F#555856}${icon}%{F-}"
fi