From 7381c53e8149c3686a4953b9abb235b33dac7edb Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 26 Nov 2019 19:25:51 -0500 Subject: [PATCH] Refactor polybar config --- themes/glimpse/polybar/config | 34 ++----- themes/glimpse/polybar/modules/app-rslsync | 9 -- themes/glimpse/polybar/modules/mail | 92 ------------------- .../modules/{app-redshift => redshift} | 0 themes/glimpse/polybar/modules/updates | 22 ----- themes/pianocat/polybar/modules/updates | 22 ----- 6 files changed, 9 insertions(+), 170 deletions(-) delete mode 100755 themes/glimpse/polybar/modules/app-rslsync delete mode 100755 themes/glimpse/polybar/modules/mail rename themes/glimpse/polybar/modules/{app-redshift => redshift} (100%) delete mode 100755 themes/glimpse/polybar/modules/updates delete mode 100755 themes/pianocat/polybar/modules/updates diff --git a/themes/glimpse/polybar/config b/themes/glimpse/polybar/config index d5de865b..3025cf46 100644 --- a/themes/glimpse/polybar/config +++ b/themes/glimpse/polybar/config @@ -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 diff --git a/themes/glimpse/polybar/modules/app-rslsync b/themes/glimpse/polybar/modules/app-rslsync deleted file mode 100755 index 043f678c..00000000 --- a/themes/glimpse/polybar/modules/app-rslsync +++ /dev/null @@ -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 diff --git a/themes/glimpse/polybar/modules/mail b/themes/glimpse/polybar/modules/mail deleted file mode 100755 index 7242afb3..00000000 --- a/themes/glimpse/polybar/modules/mail +++ /dev/null @@ -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() diff --git a/themes/glimpse/polybar/modules/app-redshift b/themes/glimpse/polybar/modules/redshift similarity index 100% rename from themes/glimpse/polybar/modules/app-redshift rename to themes/glimpse/polybar/modules/redshift diff --git a/themes/glimpse/polybar/modules/updates b/themes/glimpse/polybar/modules/updates deleted file mode 100755 index f3420fec..00000000 --- a/themes/glimpse/polybar/modules/updates +++ /dev/null @@ -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 - fi -else - echo "%{F#555856}${icon}%{F-}" -fi diff --git a/themes/pianocat/polybar/modules/updates b/themes/pianocat/polybar/modules/updates deleted file mode 100755 index f3420fec..00000000 --- a/themes/pianocat/polybar/modules/updates +++ /dev/null @@ -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 - fi -else - echo "%{F#555856}${icon}%{F-}" -fi