mirror of
https://github.com/FAUSheppy/config
synced 2025-12-09 16:18:33 +01:00
betterstatus bar
This commit is contained in:
@@ -121,7 +121,7 @@ hc keybind $Mod-Control-Up resize up +$resizestep
|
|||||||
hc keybind $Mod-Control-Right resize right +$resizestep
|
hc keybind $Mod-Control-Right resize right +$resizestep
|
||||||
|
|
||||||
# tags
|
# tags
|
||||||
hc rename default "1" || true
|
#hc rename default "1" || true
|
||||||
hc add "2"
|
hc add "2"
|
||||||
hc add "3"
|
hc add "3"
|
||||||
hc add "4"
|
hc add "4"
|
||||||
@@ -240,7 +240,9 @@ herbstclient set tree_style '╾│ ├└╼─┐'
|
|||||||
# hc detect_monitors
|
# hc detect_monitors
|
||||||
|
|
||||||
# find the panel
|
# find the panel
|
||||||
panel=~/.config/herbstluftwm/panel.sh
|
hlpath="${HOME}/.config/herbstluftwm"
|
||||||
|
pkill -f herbstluftwm/panel.sh
|
||||||
|
panel=$hlpath/panel.sh
|
||||||
[ -x "$panel" ] || panel=/etc/xdg/herbstluftwm/panel.sh
|
[ -x "$panel" ] || panel=/etc/xdg/herbstluftwm/panel.sh
|
||||||
for monitor in $(herbstclient list_monitors | cut -d: -f1) ; do
|
for monitor in $(herbstclient list_monitors | cut -d: -f1) ; do
|
||||||
# start it on each monitor
|
# start it on each monitor
|
||||||
|
|||||||
@@ -94,33 +94,16 @@ def ip():
|
|||||||
|
|
||||||
def battery():
|
def battery():
|
||||||
if hl_utils.is_laptop():
|
if hl_utils.is_laptop():
|
||||||
try:
|
try:
|
||||||
bat = hl_utils.shexec("acpi -b")
|
with open(hl_utils.hlpath("battery.log")) as f:
|
||||||
if bat == '':
|
tmp = f.read()
|
||||||
return color_panel("BATTERY FAILURE",RED)
|
tmp = ' '+tmp+' | '
|
||||||
bat = re.compile(r'Battery [0-9]+: ').sub('',bat)
|
return tmp;
|
||||||
plain = int(bat.split('%')[0][-3:].rstrip('%').lstrip(','))
|
except Exception as e:
|
||||||
|
return color_panel(str(e),RED)
|
||||||
#cur_time = [bat.split('%, ')[1].split(' ')[0].split(':')]
|
|
||||||
|
|
||||||
if plain > 10:
|
|
||||||
plain += BAT_COLOR_OFFSET
|
|
||||||
|
|
||||||
if bat.startswith("Charging"):
|
|
||||||
return color_panel("Charging",GREEN,seper=False) + color_panel(bat.lstrip("Charging ,").strip('\n'),get_color(plain,0,100))
|
|
||||||
elif bat.startswith("Full") or bat.startswith('Unknown'):
|
|
||||||
return color_panel("On Supply and fully charged",GREEN)
|
|
||||||
elif plain <= 1:
|
|
||||||
return color_panel(">>>>>>>>>>>>>>>> --------------- WARNING BATTER FAILURE IMMINENT --------------- <<<<<<<<<<<<<",RED)
|
|
||||||
elif bat.startswith("Discharging"):
|
|
||||||
return color_panel("Discharging",RED,seper=False) + color_panel(bat.lstrip("Discharging ,").strip('\n'),get_color(plain,0,100))
|
|
||||||
else:
|
|
||||||
return color_panel(bat.strip('\n'),get_color(plain,0,100))
|
|
||||||
except ValueError as e:
|
|
||||||
return color_panel(str(e),RED)
|
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(ip(),vpn(),guthaben(),battery(),sep='')
|
print(ip(),vpn(),guthaben(),battery(),sep='',end='')
|
||||||
|
|||||||
@@ -4,89 +4,100 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from hl_panel_content import color_panel, get_color
|
|
||||||
from hl_utils import error, is_cip, shexec, color_remove, hlpath, is_laptop
|
|
||||||
import re
|
import re
|
||||||
|
import hl_utils
|
||||||
|
from hl_constants import *
|
||||||
|
|
||||||
RED = 0xff0000
|
battery_average=[]
|
||||||
GREEN = 0x32CD32
|
|
||||||
YELLOW = 0xffff00
|
|
||||||
BAT_COLOR_OFFSET = 10
|
|
||||||
|
|
||||||
|
|
||||||
#Druckerguthaben
|
|
||||||
def pr_acct_status():
|
|
||||||
if is_cip():
|
|
||||||
path = hlpath("pracct.log")
|
|
||||||
out = color_remove(shexec("pr_acct").split("\n")[0]).split(' ')[-1]
|
|
||||||
with open(path,'w+') as f:
|
|
||||||
f.write(out)
|
|
||||||
def vpn_status():
|
|
||||||
if not is_cip():
|
|
||||||
vpn_path = hlpath("vpn_status.log")
|
|
||||||
out_vpn = subprocess.check_output(["ps","-ef"]).decode().split('\n')
|
|
||||||
#filter(lambda x: not 'openvpn' in x,out_vpn)
|
|
||||||
ret = 0
|
|
||||||
#worst case thats about 1k lines
|
|
||||||
for l in out_vpn:
|
|
||||||
if 'openvpn' in l and not 'sudo' in l and not 'grep' in l and not 'cip.sh' in l:
|
|
||||||
ret += 1;
|
|
||||||
#print(ret)
|
|
||||||
if ret == 0:
|
|
||||||
out_vpn = color_panel("VPN: Link Down",RED)
|
|
||||||
elif ret == 1:
|
|
||||||
out_vpn = color_panel("VPN: In Use",GREEN)
|
|
||||||
elif ret > 1:
|
|
||||||
out_vpn = color_panel("multiple VPNs connected",YELLOW)
|
|
||||||
else:
|
|
||||||
out_vpn = color_panel("VPN: ret was "+str(ret)+" ??",RED)
|
|
||||||
#print(out_vpn)
|
|
||||||
with open(vpn_path,'w+') as g:
|
|
||||||
g.write(out_vpn)
|
|
||||||
|
|
||||||
def battery():
|
def battery():
|
||||||
try:
|
try:
|
||||||
bat = shexec("acpi -b")
|
## query battery ##
|
||||||
|
bat = hl_utils.shexec("acpi -b")
|
||||||
if bat == '':
|
if bat == '':
|
||||||
return color_panel("BATTERY FAILURE",RED)
|
return hl_utils.color_panel("Cannot query battery status",RED)
|
||||||
bat = re.compile(r'Battery [0-9]+: ').sub('',bat)
|
bat = re.compile(r'Battery [0-9]+: ').sub('',bat)
|
||||||
plain = int(bat.split('%')[0][-3:].rstrip('%').lstrip(','))
|
plain = int(bat.split('%')[0][-3:].rstrip('%').lstrip(','))
|
||||||
|
|
||||||
|
## imediatelly return if full and on supply ##
|
||||||
|
if bat.startswith("Full") or bat.startswith('Unknown'):
|
||||||
|
return hl_utils.color_panel("On Supply and fully charged",GREEN)
|
||||||
|
|
||||||
#cur_time = [bat.split('%, ')[1].split(' ')[0].split(':')]
|
## calculate average time remaining ##
|
||||||
|
cur_time = bat.split('%, ')[1].split(' ')[0].split(':')
|
||||||
|
cur = int(cur_time[0]) + int(cur_time[1]) * 60 + int(cur_time[2]) * 60 * 60
|
||||||
|
global battery_average
|
||||||
|
battery_average+=[int(cur)]
|
||||||
|
if len(battery_average) == 0:
|
||||||
|
bat_avg = "unkown"
|
||||||
|
else:
|
||||||
|
bat_avg=int(sum(battery_average) / float(len(battery_average)))
|
||||||
|
|
||||||
|
## color fine tuning ##
|
||||||
if plain > 10:
|
if plain > 10:
|
||||||
plain += BAT_COLOR_OFFSET
|
plain += BAT_COLOR_OFFSET
|
||||||
|
|
||||||
|
## build string ##
|
||||||
|
tmp=hl_utils.color_panel(bat.lstrip("Charging ,").lstrip("Discharging ,").split(",")[0],hl_utils.get_color(plain,0,100),False)
|
||||||
|
bat_avg=hl_utils.color_panel(str(bat_avg),RED,False)
|
||||||
|
|
||||||
|
## conditional coloring ##
|
||||||
if bat.startswith("Charging"):
|
if bat.startswith("Charging"):
|
||||||
return color_panel("Charging",GREEN,seper=False) + color_panel(bat.lstrip("Charging ,").strip('\n'),get_color(plain,0,100))
|
return hl_utils.color_panel("Charging, ",GREEN,False) + str(tmp) + str(bat_avg)
|
||||||
elif bat.startswith("Full") or bat.startswith('Unknown'):
|
elif plain <= BATTERY_CRITICAL:
|
||||||
return color_panel("On Supply and fully charged",GREEN)
|
return hl_utils.color_panel(">>>>>>>>>>>>>>>> ------------ WARNING BATTER FAILURE IMMINENT ------------ <<<<<<<<<<<<<",RED)
|
||||||
elif plain <= 1:
|
|
||||||
return color_panel(">>>>>>>>>>>>>>>> --------------- WARNING BATTER FAILURE IMMINENT --------------- <<<<<<<<<<<<<",RED)
|
|
||||||
elif bat.startswith("Discharging"):
|
elif bat.startswith("Discharging"):
|
||||||
return color_panel("Discharging",RED,seper=False) + color_panel(bat.lstrip("Discharging ,").strip('\n'),get_color(plain,0,100))
|
return hl_utils.color_panel("Discharging, ",RED,False) + str(tmp) + str(bat_avg)
|
||||||
else:
|
else:
|
||||||
return color_panel(bat.strip('\n'),get_color(plain,0,100))
|
return hl_utils.color_panel(bat.strip('\n'),hl_utils.get_color(plain,0,100))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return color_panel(str(e),RED)
|
return hl_utils.color_panel(str(e),RED)
|
||||||
|
|
||||||
|
|
||||||
|
def pr_acct_status():
|
||||||
|
if hl_utils.is_cip():
|
||||||
|
out = hl_utils.color_remove(hl_utils.shexec(PRINT_LOG).split("\n")[0]).split(' ')[-1]
|
||||||
|
with open(hl_utils.hlpath(PRINT_LOG),'w+') as f:
|
||||||
|
f.write(out)
|
||||||
|
|
||||||
|
def vpn_status():
|
||||||
|
if not hl_utils.is_cip():
|
||||||
|
out_vpn = hl_utils.shexec("ps -ef")
|
||||||
|
#out_vpn = subprocess.check_output(["ps","-ef"]).decode().split('\n')
|
||||||
|
|
||||||
|
ret = 0
|
||||||
|
for l in out_vpn:
|
||||||
|
if 'openvpn' in l and not 'sudo' in l and not 'grep' in l and not 'cip.sh' in l:
|
||||||
|
ret += 1;
|
||||||
|
|
||||||
|
if ret == 0:
|
||||||
|
out_vpn = hl_utils.color_panel("VPN: Link Down",RED)
|
||||||
|
elif ret == 1:
|
||||||
|
out_vpn = hl_utils.color_panel("VPN: In Use",GREEN)
|
||||||
|
elif ret > 1:
|
||||||
|
out_vpn = hl_utils.color_panel("multiple VPNs connected",YELLOW)
|
||||||
|
else:
|
||||||
|
out_vpn = hl_utils.color_panel("VPN: ret was "+str(ret)+" ??",RED)
|
||||||
|
|
||||||
|
with open(hl_utils.hlpath(VPN_LOG),'w+') as g:
|
||||||
|
g.write(out_vpn)
|
||||||
|
|
||||||
def battery_status():
|
def battery_status():
|
||||||
if is_laptop:
|
if hl_utils.is_laptop():
|
||||||
with open(hlpath("battery.log"),'w') as g:
|
with open(hl_utils.hlpath(BATTERY_LOG),'w') as g:
|
||||||
g.write(battery())
|
g.write(battery())
|
||||||
|
|
||||||
def ip_status():
|
def ip_status():
|
||||||
with open(hlpath("ip.log"),'w') as g:
|
with open(hl_utils.hlpath(IP_LOG),'w') as g:
|
||||||
p="Public IP: "
|
p="Public IP: "
|
||||||
try:
|
try:
|
||||||
tmp=color_panel(p+shexec("wget --timeout=3 -O- --quiet https://atlantishq.de/ipcheck"),GREEN)
|
tmp=hl_utils.color_panel(p+hl_utils.shexec("wget --timeout=3 -O- --quiet https://atlantishq.de/ipcheck"),GREEN)
|
||||||
except:
|
except:
|
||||||
tmp=color_panel("Offline",RED)
|
tmp=hl_utils.color_panel("Offline",RED)
|
||||||
g.write(tmp)
|
g.write(tmp)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#print('"'+sys.argv[-1]+'"')
|
|
||||||
while(True):
|
while(True):
|
||||||
vpn_status()
|
vpn_status()
|
||||||
pr_acct_status()
|
pr_acct_status()
|
||||||
@@ -94,6 +105,4 @@ if __name__ == '__main__':
|
|||||||
ip_status()
|
ip_status()
|
||||||
if sys.argv[-1]=='--refresh':
|
if sys.argv[-1]=='--refresh':
|
||||||
break
|
break
|
||||||
time.sleep(30)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import string
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
import shlex
|
||||||
import re
|
import re
|
||||||
|
from hl_constants import *
|
||||||
|
|
||||||
def hlpath(addition=""):
|
def hlpath(addition=""):
|
||||||
return os.path.join(os.path.expanduser("~"),".config/herbstluftwm/"+addition)
|
return os.path.join(os.path.expanduser("~"),".config/herbstluftwm/"+addition)
|
||||||
@@ -27,3 +30,50 @@ def error(s):
|
|||||||
with open(hlpath("herbstlog"),'a') as f:
|
with open(hlpath("herbstlog"),'a') as f:
|
||||||
time = str(datetime.datetime.now().time())[:-7] #cut seconds at the end
|
time = str(datetime.datetime.now().time())[:-7] #cut seconds at the end
|
||||||
f.write(time + " ERROR: " + os.path.basename(__file__) + ' ' +s +'\n')
|
f.write(time + " ERROR: " + os.path.basename(__file__) + ' ' +s +'\n')
|
||||||
|
|
||||||
|
def color_panel(s,hex_code,seper=True):
|
||||||
|
if type(hex_code)==int:
|
||||||
|
hex_code = hex(hex_code)
|
||||||
|
hex_code = hex_code.lstrip('0x')
|
||||||
|
if seper:
|
||||||
|
sep=color_panel(SEP,DEFAULT_FG,False)
|
||||||
|
else:
|
||||||
|
sep = ""
|
||||||
|
return "^fg(#" + hex_code + ") " + s + "^bg()"+sep
|
||||||
|
|
||||||
|
def get_color(nr,start,end):
|
||||||
|
if end == start or nr >= end:
|
||||||
|
return hex(GREEN)
|
||||||
|
elif nr <= 0:
|
||||||
|
return hex(RED)
|
||||||
|
else:
|
||||||
|
r,g,b = 0,0,0
|
||||||
|
interval = 256 + 256
|
||||||
|
custom_interval = abs(start-end)
|
||||||
|
div = float(interval)/float(custom_interval)
|
||||||
|
if div >= interval:
|
||||||
|
error("Interval for coloring too small, using default")
|
||||||
|
return WHITE
|
||||||
|
nr = nr*div
|
||||||
|
if custom_interval > interval:
|
||||||
|
custom_interval = interval
|
||||||
|
if nr >= 256:
|
||||||
|
g = 0xFF
|
||||||
|
r = int(abs(nr - (256+256))) #counts down reverse to nr
|
||||||
|
##
|
||||||
|
if r == 0x100:
|
||||||
|
r = 0xFF
|
||||||
|
b = 0
|
||||||
|
elif nr >= 0:
|
||||||
|
g = int(nr)
|
||||||
|
r = 0xFF
|
||||||
|
b = 0
|
||||||
|
else:
|
||||||
|
error("Negative interval value???")
|
||||||
|
return(WHITE)
|
||||||
|
r = r << 16
|
||||||
|
g = g << 8
|
||||||
|
tmp_col = r + g + b
|
||||||
|
if tmp_col > 0xFFFF00:
|
||||||
|
error("color value too high")
|
||||||
|
return hex(tmp_col)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
|
hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
|
||||||
monitor=${1:-0}
|
monitor=${1:-0}
|
||||||
@@ -68,6 +68,12 @@ hc pad $monitor $panel_height
|
|||||||
date +$'date\t^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d'
|
date +$'date\t^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d'
|
||||||
sleep 1 || break
|
sleep 1 || break
|
||||||
done > >(uniq_linebuffered) &
|
done > >(uniq_linebuffered) &
|
||||||
|
|
||||||
|
while true ; do
|
||||||
|
printf 'pystat\t%s\n' "$($HOME/.config/herbstluftwm/hl_panel_content.py)"
|
||||||
|
sleep 1 || break
|
||||||
|
done > >(uniq_linebuffered) &
|
||||||
|
|
||||||
childpid=$!
|
childpid=$!
|
||||||
hc --idle
|
hc --idle
|
||||||
kill $childpid
|
kill $childpid
|
||||||
@@ -75,6 +81,7 @@ hc pad $monitor $panel_height
|
|||||||
IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
|
IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
|
||||||
visible=true
|
visible=true
|
||||||
date=""
|
date=""
|
||||||
|
pystat=
|
||||||
windowtitle=""
|
windowtitle=""
|
||||||
while true ; do
|
while true ; do
|
||||||
|
|
||||||
@@ -118,13 +125,13 @@ hc pad $monitor $panel_height
|
|||||||
echo -n "^bg()^fg() ${windowtitle//^/^^}"
|
echo -n "^bg()^fg() ${windowtitle//^/^^}"
|
||||||
|
|
||||||
####################### Interface to python layer #########################
|
####################### Interface to python layer #########################
|
||||||
right="$($HOME/.config/herbstluftwm/hl_panel_content.py) $date"
|
#right="$($HOME/.config/herbstluftwm/hl_panel_content.py) $date"
|
||||||
|
|
||||||
|
right="${pystat}${date}"
|
||||||
right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g')
|
right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g')
|
||||||
# get width of right aligned text.. and add some space..
|
# get width of right aligned text.. and add some space..
|
||||||
width=$($textwidth "$font" "$right_text_only ")
|
width=$($textwidth "$font" "$right_text_only ")
|
||||||
len=$(expr $(echo -n "$right" | wc -c) / 3)
|
len=$(expr $(echo -n "$right" | wc -c) / 3)
|
||||||
35
|
|
||||||
echo -n "^pa($(($panel_width - $width - $len + 10)))$right"
|
echo -n "^pa($(($panel_width - $width - $len + 10)))$right"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
@@ -140,13 +147,15 @@ hc pad $monitor $panel_height
|
|||||||
IFS=$'\t' read -ra cmd || break
|
IFS=$'\t' read -ra cmd || break
|
||||||
# find out event origin
|
# find out event origin
|
||||||
case "${cmd[0]}" in
|
case "${cmd[0]}" in
|
||||||
|
|
||||||
tag*)
|
tag*)
|
||||||
#echo "resetting tags" >&2
|
#echo "resetting tags" >&2
|
||||||
IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
|
IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
|
||||||
;;
|
;;
|
||||||
|
pystat)
|
||||||
|
pystat="${cmd[@]:1}"
|
||||||
|
;;
|
||||||
date)
|
date)
|
||||||
#echo "resetting date" >&2
|
echo "resetting date" >&2
|
||||||
date="${cmd[@]:1}"
|
date="${cmd[@]:1}"
|
||||||
;;
|
;;
|
||||||
quit_panel)
|
quit_panel)
|
||||||
|
|||||||
Reference in New Issue
Block a user