Refactor polybar config
This commit is contained in:
parent
d2b9b9ae6c
commit
7381c53e81
|
@ -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
|
||||
modules-center = bspwm
|
||||
; modules-right = battery wlan app-rslsync app-redshift pad date
|
||||
modules-right = battery wlan app-redshift pad date
|
||||
modules-right = battery wlan syncthing redshift pad date
|
||||
|
||||
;tray-position = center
|
||||
;tray-padding = 2
|
||||
|
@ -303,34 +302,19 @@ type = custom/text
|
|||
content = " "
|
||||
content-foreground = ${colors.fg-alt}
|
||||
|
||||
[module/pkg]
|
||||
type = custom/ipc
|
||||
hook-0 = ~/.config/polybar/modules/updates
|
||||
initial = 1
|
||||
click-left = polybar-msg -p %pid% hook pkg 1
|
||||
[module/redshift]
|
||||
type = custom/script
|
||||
exec = ~/.config/polybar/modules/redshift
|
||||
exec-if = pgrep -x redshift
|
||||
interval = 60
|
||||
format-padding = 1
|
||||
|
||||
[module/mail]
|
||||
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]
|
||||
[module/syncthing]
|
||||
type = custom/script
|
||||
exec = echo 1
|
||||
exec-if = pgrep -x redshift
|
||||
format = ""
|
||||
format-foreground = ${colors.icons}
|
||||
interval = 2
|
||||
|
||||
[module/app-rslsync]
|
||||
type = custom/script
|
||||
exec = echo 1
|
||||
exec-if = pgrep -x rslsync
|
||||
exec-if = systemctl is-active syncthing
|
||||
format = ""
|
||||
format-foreground = ${colors.icons}
|
||||
interval = 60
|
||||
interval = 30
|
||||
|
||||
; vim:ft=dosini
|
||||
|
|
|
@ -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
|
|
@ -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()
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue