screen: expanded battery script printing capabilities

master
Meliurwen 2 years ago
parent eaf856b0bc
commit a0131aaff1
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 202
      screen/.config/screen/bin/battery.sh
  2. 2
      screen/.screenrc

@ -1,67 +1,191 @@
#!/bin/sh #!/bin/sh
# Usage: ./battery.sh [--color [screen]]
if [ "$1" = "--color" ]; then # Docs: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power
case $2 in
"screen") set -e
colgreen="\005{g}"
colyellow="\005{y}" while [ $# -gt 0 ] ; do
colred="\005{r}" case "$1" in
colred_blink="\005{+B r}" "--newline")
colend="\005{-}" newline=1
;;
"--unit")
unitsymbol="%"
;;
"--icon")
case $2 in
"ascii"|""|"--"*)
case "$2" in
"--"*|"")
: # skip if it's a parameter or is empty
;;
*)
shift
;;
esac
iconize=1
iconbat0="[----]"
iconbat1="[#---]"
iconbat2="[##--]"
iconbat3="[###-]"
iconbat4="[####]"
;;
"nerd")
shift
iconize=1
iconbat0=
iconbat1=
iconbat2=
iconbat3=
iconbat4=
;;
*)
printf "Icon coding not supported. Aborting...\n"
exit 1
;;
esac
;;
"--color")
case $2 in
"screen")
shift
colorize=1
colgreen="\005{g}"
colyellow="\005{y}"
colred="\005{r}"
colred_blink="\005{+B r}"
colend="\005{-}"
;;
"lemonbar")
shift
colorize=1
# xterm ANSI color palette
colgreen="%{F#00CD00}"
colyellow="%{F#CDCD00}"
colred="%{F#CD0000}"
colred_blink="%{F#000000}%{B#CD0000}" # no blinking available :(
colend="%{F-}"
colbgend="%{B-}"
;;
"ansi"|""|"--"*)
case "$2" in
"--"*|"")
: # skip if it's a parameter or is empty
;;
*)
shift
;;
esac
colorize=1
colgreen="\033[0;32m"
colyellow="\033[0;33m"
colred="\033[0;31m"
colred_blink="\033[5;31m"
colend="\033[0m"
;;
*)
printf "Color coding not supported. Aborting...\n"
exit 1
;;
esac
;; ;;
"") "--symbols")
colgreen="\033[0;32m" case $2 in
colyellow="\033[0;33m" "ascii"|""|"--"*)
colred="\033[0;31m" case "$2" in
colred_blink="\033[5;31m" "--"*|"")
colend="\033[0m" : # skip if it's a parameter or is empty
;;
*)
shift
;;
esac
symdischarging="-"
symcharging="+"
symnotcharging="~"
symunknown="?"
symundetermined="/"
;;
"ascii-alt")
shift
symdischarging="▼"
symcharging="▲"
symnotcharging="~"
symunknown="?"
symundetermined="/"
;;
*)
printf "Charset not available. Aborting...\n"
exit 1
;;
esac
;; ;;
*) *)
printf "Color coding not supported. Aborting...\n" printf "Parameter not recognized. Aborting...\n"
exit 1 exit 1
;; ;;
esac esac
fi shift
done
pwr_lvl="" pwr_lvl=""
status="" status=""
multi_bat=0 multi_bat=0
for folder in /sys/class/power_supply/BAT?/; do
supply_paths=/sys/class/power_supply/*/
for folder in $supply_paths; do
[ -r "$folder/type" ] && [ "$(cat "$folder/type")" = "Battery" ] || continue
[ -r "$folder/capacity" ] || continue
[ -r "$folder/status" ] || continue
pwr_lvl="$(cat "$folder/capacity")" pwr_lvl="$(cat "$folder/capacity")"
pwr_stat="$(cat "$folder/status")" pwr_stat="$(cat "$folder/status")"
if [ "$pwr_stat" = "Discharging" ]; then case "$pwr_stat" in
status="%▼" "Discharging")
elif [ "$pwr_stat" = "Charging" ]; then status="$symdischarging"
status="%▲" ;;
elif [ "$pwr_stat" = "Not charging" ]; then "Charging")
status="%~" status="$symcharging"
elif [ "$pwr_stat" = "Unknown" ]; then ;;
status="%?" "Not charging"|"Full")
else status="$symnotcharging"
status="%/" ;;
fi "Unknown")
if [ "$1" = "--color" ]; then status="$symunknown"
# if: ;;
# - <= 5 blinking red text *)
# - <= 10 red text status="$symundetermined"
# - <= 20 yellow text ;;
# - > 20 green esac
if [ "$pwr_lvl" -le 8 ]; then if [ "$colorize" = 1 ] || [ "$iconize" = 1 ]; then
if [ "$pwr_lvl" -le 5 ]; then
color="${colred_blink}" color="${colred_blink}"
elif [ "$pwr_lvl" -le 20 ]; then icon="${iconbat0}"
elif [ "$pwr_lvl" -le 15 ]; then
color="${colred}" color="${colred}"
elif [ "$pwr_lvl" -le 40 ]; then icon="${iconbat0}"
elif [ "$pwr_lvl" -le 35 ]; then
color="${colyellow}" color="${colyellow}"
icon="${iconbat1}"
elif [ "$pwr_lvl" -le 65 ]; then
color="${colgreen}"
icon="${iconbat2}"
elif [ "$pwr_lvl" -le 97 ]; then
color="${colgreen}"
icon="${iconbat3}"
else else
color="${colgreen}" color="${colgreen}"
icon="${iconbat4}"
fi fi
fi fi
[ "$colend" = "%{F-}" ] && [ "$unitsymbol" = "%" ] && colend="%%{F-}"
if [ $multi_bat = 1 ]; then if [ $multi_bat = 1 ]; then
sep="|" sep="|"
else else
sep="" sep=""
multi_bat=1 multi_bat=1
fi fi
printf "%b%s%s%b%s" "${color}" "${pwr_lvl}" "${status}" "${colend}" "${sep}" printf "%b%s%s%s%s%b%s" "${color}" "${icon}" "${status}" "${pwr_lvl}" "${unitsymbol}" "${colend}${colbgend}" "${sep}"
done done
[ "$newline" = 1 ] && printf "\n" || :

@ -15,7 +15,7 @@ termcapinfo xterm*|rxvt*|kterm*|Eterm* ti@:te@
defscrollback 10000 defscrollback 10000
# backtick id lifespan autorefresh cmd args... # backtick id lifespan autorefresh cmd args...
backtick 1 10 10 $HOME/.config/screen/bin/battery.sh --color screen backtick 1 10 10 $HOME/.config/screen/bin/battery.sh --unit --symbols ascii --icon ascii --color screen
backtick 2 10 10 $HOME/.config/screen/bin/netinfo.sh --icon ascii --color screen backtick 2 10 10 $HOME/.config/screen/bin/netinfo.sh --icon ascii --color screen
# Statusbar # Statusbar

Loading…
Cancel
Save