Add waybar

This commit is contained in:
templis 2020-02-18 20:57:02 +01:00
parent ff109544ab
commit da7e23541c
7 changed files with 393 additions and 0 deletions

149
.config/waybar/config Normal file
View File

@ -0,0 +1,149 @@
[{
"layer": "top",
"position": "top",
"height": 30,
"modules-left": ["sway/mode", "temperature"],
"modules-center": ["clock", "custom/weather"],
"modules-right": ["network", "cpu"],
"clock": {
"format": "{:%a %d %b %H:%M}",
"tooltip": false
},
"sway/mode": {
"format": " {}"
},
"network": {
"format": "{icon}",
"format-alt": "{ipaddr}/{cidr} {icon}",
"format-alt-click": "click-right",
"format-icons": {
"wifi": ["", "" ,""],
"ethernet": [""],
"disconnected": [""]
},
"on-click": "termite -e nmtui",
"tooltip": false
},
"temperature": {
"thermal-zone": 2,
"hwmon-path": "/sys/class/hwmon/hwmon0/temp1_input",
"critical-threshold": 80,
"format-critical": "{temperatureC}°C ",
"format": "{temperatureC}°C "
},
"cpu": {
"interval": 10,
"format": "{}% ",
"max-length": 10,
"states": {
"warning": 70,
"critical": 80
}
},
"custom/weather": {
"format": "{}",
"format-alt": "{alt}: {}",
"format-alt-click": "click-right",
"interval": 1800,
"return-type": "json",
"exec": "~/.config/waybar/modules/weather.sh",
"exec-if": "ping wttr.in -c1"
}
},
{
"layer": "bottom",
"position": "bottom",
"height": 30,
"modules-left": ["sway/workspaces", "sway/mode"],
"modules-center": ["sway/window"],
"modules-right": ["custom/spotify", "custom/storage", "backlight", "pulseaudio", "idle_inhibitor", "battery", "tray"],
"sway/mode": {
"format": " {}"
},
"sway/workspaces": {
"format": "{name}",
"disable-scroll": true
},
"sway/window": {
"max-length": 80,
"tooltip": false
},
"battery": {
"format": "{capacity}% {icon}",
"format-alt": "{time} {icon}",
"format-icons": ["", "", "", "", ""],
"format-charging": "{capacity}% ",
"interval": 30,
"states": {
"warning": 25,
"critical": 10
},
"tooltip": false
},
"pulseaudio": {
"format": "{icon}",
"format-alt": "{volume} {icon}",
"format-alt-click": "click-right",
"format-muted": "",
"format-icons": {
"phone": [" ", " ", " ", " "],
"default": ["", "", "", ""]
},
"scroll-step": 10,
"on-click": "pavucontrol",
"tooltip": false
},
"custom/spotify": {
"interval": 1,
"return-type": "json",
"exec": "~/.config/waybar/modules/spotify.sh",
"exec-if": "pgrep spotify",
"escape": true
},
"custom/storage": {
"format": "{} ",
"format-alt": "{percentage}% ",
"format-alt-click": "click-right",
"return-type": "json",
"interval": 60,
"exec": "~/.config/waybar/modules/storage.sh"
},
"backlight": {
"format": "{icon}",
"format-alt": "{percent}% {icon}",
"format-alt-click": "click-right",
"format-icons": ["", ""],
"on-scroll-down": "light -A 1",
"on-scroll-up": "light -U 1"
},
"custom/weather": {
"format": "{}",
"format-alt": "{alt}: {}",
"format-alt-click": "click-right",
"interval": 1800,
"return-type": "json",
"exec": "~/.config/waybar/modules/weather.sh",
"exec-if": "ping wttr.in -c1"
},
"idle_inhibitor": {
"format": "{icon}",
"format-icons": {
"activated": "",
"deactivated": ""
},
"tooltip": false
},
"custom/test": {
"format": "{}",
"exec": "/tmp/test blub",
"param": "blah",
"interval": 5
},
"tray": {
"icon-size": 18
}
}]

42
.config/waybar/modules/mail.py Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/python
import os
import imaplib
import mailsecrets
def getmails(username, password, server):
imap = imaplib.IMAP4_SSL(server, 993)
imap.login(username, password)
imap.select('INBOX')
ustatus, uresponse = imap.uid('search', None, 'UNSEEN')
if ustatus == 'OK':
unread_msg_nums = uresponse[0].split()
else:
unread_msg_nums = []
fstatus, fresponse = imap.uid('search', None, 'FLAGGED')
if fstatus == 'OK':
flagged_msg_nums = fresponse[0].split()
else:
flagged_msg_nums = []
return [len(unread_msg_nums), len(flagged_msg_nums)]
ping = os.system("ping " + mailsecrets.server + " -c1 > /dev/null 2>&1")
if ping == 0:
mails = getmails(mailsecrets.username, mailsecrets.password, mailsecrets.server)
text = ''
alt = ''
if mails[0] > 0:
text = alt = str(mails[0])
if mails[1] > 0:
alt = str(mails[1]) + "" + alt
else:
exit(1)
print('{"text":"' + text + '", "alt": "' + alt + '"}')
else:
exit(1)

View File

@ -0,0 +1,18 @@
#!/bin/sh
class=$(playerctl metadata --player=spotify --format '{{lc(status)}}')
icon=""
if [[ $class == "playing" ]]; then
info=$(playerctl metadata --player=spotify --format '{{artist}} - {{title}}')
if [[ ${#info} > 40 ]]; then
info=$(echo $info | cut -c1-40)"..."
fi
text=$info" "$icon
elif [[ $class == "paused" ]]; then
text=$icon
elif [[ $class == "stopped" ]]; then
text=""
fi
echo -e "{\"text\":\""$text"\", \"class\":\""$class"\"}"

View File

@ -0,0 +1,24 @@
#!/bin/sh
mount="/"
warning=20
critical=10
df -h -P -l "$mount" | awk -v warning=$warning -v critical=$critical '
/\/.*/ {
text=$4
tooltip="Filesystem: "$1"\rSize: "$2"\rUsed: "$3"\rAvail: "$4"\rUse%: "$5"\rMounted on: "$6
use=$5
exit 0
}
END {
class=""
gsub(/%$/,"",use)
if ((100 - use) < critical) {
class="critical"
} else if ((100 - use) < warning) {
class="warning"
}
print "{\"text\":\""text"\", \"percentage\":"use",\"tooltip\":\""tooltip"\", \"class\":\""class"\"}"
}
'

View File

@ -0,0 +1,79 @@
#!/bin/bash
cachedir=~/.cache/rbn
cachefile=${0##*/}-$1
if [ ! -d $cachedir ]; then
mkdir -p $cachedir
fi
if [ ! -f $cachedir/$cachefile ]; then
touch $cachedir/$cachefile
fi
# Save current IFS
SAVEIFS=$IFS
# Change IFS to new line.
IFS=$'\n'
cacheage=$(($(date +%s) - $(stat -c '%Y' "$cachedir/$cachefile")))
if [ $cacheage -gt 1740 ] || [ ! -s $cachedir/$cachefile ]; then
data=($(curl -s https://de.wttr.in/tuebingen\?0qnT 2>&1))
echo ${data[0]} | cut -f1 -d, > $cachedir/$cachefile
echo ${data[1]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile
echo ${data[2]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile
fi
weather=($(cat $cachedir/$cachefile))
# Restore IFSClear
IFS=$SAVEIFS
temperature=$(echo ${weather[2]} | sed -E 's/([[:digit:]])+\.\./\1 bis /g')
#echo ${weather[1]##*,}
# https://fontawesome.com/icons?s=solid&c=weather
case $(echo ${weather[1]##*,} | tr '[:upper:]' '[:lower:]') in
"clear" | "sunny" | "sonnig" | "wolkenlos" | "klar")
condition=""
;;
"partly cloudy" | "leicht bewölkt")
condition=""
;;
"cloudy" | "bewölkt")
condition=""
;;
"overcast" | "bedeckt")
condition=""
;;
"mist" | "fog" | "freezing fog" | "nebel" | "gefrierender nebel")
condition=""
;;
"patchy rain possible" | "patchy light drizzle" | "light drizzle" | "patchy light rain" | "light rain" | "light rain shower" | "rain" | "stellenweise regen möglich" | "stellenweise nieselregen" | "leichter nieselregen" | "stellenweise leichter regen" | "leichter regenfall" | "leichter regen" | "regen")
condition=""
;;
"moderate rain at times" | "moderate rain" | "heavy rain at times" | "heavy rain" | "moderate or heavy rain shower" | "torrential rain shower" | "rain shower" | "stellenweise gemäßigter regen" | "gemäßigter regen" | "stellenweise starker regen" | "starker regen" | "gemäßigter oder starker regen" | "wolkenbruch")
condition=""
;;
"patchy snow possible" | "patchy sleet possible" | "patchy freezing drizzle possible" | "freezing drizzle" | "heavy freezing drizzle" | "light freezing rain" | "moderate or heavy freezing rain" | "light sleet" | "ice pellets" | "light sleet showers" | "moderate or heavy sleet showers" | "stellenweise schnee möglich" | "stellenweise schneeregen möglich" | "stellenweise gefrierende nässe möglich" | "gefrierender nieselregen" | "starker gefrierender nieselregen" | "leichter gefrierender regen" | "gemäßigter oder starker gefrierender regen" | "leichter schneeregen" | "eiskörner" | "leichter schneeregen" | "gemäßigter oder starker schneeregen")
condition=""
;;
"blowing snow" | "moderate or heavy sleet" | "patchy light snow" | "light snow" | "light snow showers" | "schneesturm" | "gemäßigter oder starker schneeregen" | "stellenweise leichter schneefall" | "leichter schneefall")
condition=""
;;
"blizzard" | "patchy moderate snow" | "moderate snow" | "patchy heavy snow" | "heavy snow" | "moderate or heavy snow with thunder" | "moderate or heavy snow showers" | "stellenweise gemäßigter schneefall" | "gemäßigter schneefall" | "stellenweise starker schneefall" | "starker schneefall" | "gemäßigter oder starker schnefall mit gewitter" | "gemäßigter oder starker schneefall")
condition=""
;;
"thundery outbreaks possible" | "patchy light rain with thunder" | "moderate or heavy rain with thunder" | "patchy light snow with thunder" | "gewitter möglich" | "stellenweise leichter regen mit gewitter" | "gemäßigter oder starker regen mit gewitter" | "stellenweise leichter schnefall mit gewitter")
condition=""
;;
*)
condition=""
echo -e "{\"text\":\""$condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}"
;;
esac
#echo $temp $condition
echo -e "{\"text\":\""$temperature $condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}"

71
.config/waybar/style.css Normal file
View File

@ -0,0 +1,71 @@
* {
border: none;
border-radius: 0;
font-family: Sans;
font-size: 15px;
box-shadow: none;
text-shadow: none;
transition-duration: 0s;
}
window {
color: rgba(217, 216, 216, 1);
background: rgba(35, 31, 32, 0.80);
}
window#waybar.solo {
color: rgba(217, 216, 216, 1);
background: rgba(35, 31, 32, 0.80);
}
#workspaces {
margin: 0 5px;
}
#workspaces button {
padding: 0 5px;
color: rgba(217, 216, 216, 0.4);
}
#workspaces button.visible {
color: rgba(217, 216, 216, 1);
}
#workspaces button.focused {
border-top: 3px solid rgba(217, 216, 216, 1);
border-bottom: 3px solid rgba(217, 216, 216, 0);
}
#workspaces button.urgent {
color: rgba(238, 46, 36, 1);
}
#mode, #battery, #cpu, #memory, #network, #pulseaudio, #idle_inhibitor, #backlight, #custom-storage, #custom-spotify, #custom-weather, #custom-mail {
margin: 0px 6px 0px 10px;
min-width: 25px;
}
#clock {
margin: 0px 16px 0px 10px;
min-width: 140px;
}
#battery.warning {
color: rgba(255, 210, 4, 1);
}
#battery.critical {
color: rgba(238, 46, 36, 1);
}
#battery.charging {
color: rgba(217, 216, 216, 1);
}
#custom-storage.warning {
color: rgba(255, 210, 4, 1);
}
#custom-storage.critical {
color: rgba(238, 46, 36, 1);
}

10
.config/waybar/waybar.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env sh
# Terminate already running bar instances
killall -q waybar
# Wait until the processes have been shut down
while pgrep -x waybar >/dev/null; do sleep 1; done
# Launch main
waybar