I'm keen to make this cooler, even though I've sort of abandoned the idea of a "terminal as a bar" idea..
I'm now trying to add icons, because icons are cool.
bat() {
read bat_status < /sys/class/power_supply/BAT1/status
read bat_capacity < /sys/class/power_supply/BAT1/capacity
bat_capacity=$(( (bat_capacity * 100) / 80 )) # set battery full at %80
if [ $bat_status = "Charging" ]
then bat_state=""
else bat_state=""
fi
bat="$bat_state $bat_capacity%"
}
vol() {
read get_mute get_vol <<EoF
$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{ print $3, $2*100"%" }')
EoF
if [ $get_mute = "[MUTED]" ]
then state=""
else state=" "
fi
vol="${state:-$get_vol}"
}
I don't understand why the volume percentage is no longer shown?:
While I still intend to tweak this script, I will likely use something like sandbar (the above script work fine with icons when using sandbar
)
So, fixing the above barsh
is one thing. Moving onto sandbar
. Here is my working script:
#!/bin/sh
cpu() {
read cpu junk < /proc/loadavg
}
memory() {
memory=$(free -h --si | awk '$1 == "Mem:" { print $3 }')
}
disk() {
disk=$(df -H | awk '$NF == "/" { print $4 }')
}
datetime() {
datetime=" $(date "+%a %d %b, %I:%M %p")"
}
bat() {
read -r bat_status </sys/class/power_supply/BAT1/status
read -r bat_capacity </sys/class/power_supply/BAT1/capacity
bat_capacity=$(( (bat_capacity * 100) / 80 )) # set battery full at %80
if [ $bat_status = "Charging" ]
then state=""
else state=""
fi
#"icons": [
# "", # battery-empty
# "", # battery-quarter
# "", # battery-half
# "", # battery-three-quarters
# "" # battery-full
#]
bat="$state $bat_capacity%"
}
vol() {
ID="@DEFAULT_AUDIO_SINK@"
get_mute="$(wpctl get-volume $ID | awk '{print $3}')"
get_vol="$(wpctl get-volume $ID | awk '{print $2*100"%"}')"
if [ $get_mute = "[MUTED]" ]
then state=""
else state=" "
fi
vol="$state $get_vol"
}
display() {
echo "all status C$cpu | $memory | $disk | $bat | $vol | $datetime" >"$FIFO"
}
printf "%s" "$$" > "$XDG_RUNTIME_DIR/status_pid"
FIFO="$XDG_RUNTIME_DIR/sandbar"
[ -e "$FIFO" ] || mkfifo "$FIFO"
sec=0
while true; do
sleep 1 &
wait && {
[ $((sec % 15)) -eq 0 ] && memory
[ $((sec % 15)) -eq 0 ] && cpu
[ $((sec % 15)) -eq 0 ] && disk
[ $((sec % 5)) -eq 0 ] && bat
[ $((sec % 5)) -eq 0 ] && vol
[ $((sec % 15)) -eq 0 ] && datetime
[ $((sec % 5)) -eq 0 ] && display
sec=$((sec + 1))
}
done
I'm wanting to configure the 5 different battery icons to load at their respective percent amount. (I'd also prefer to use vertical battery icons if anyone can help me find them)
Here is what it looks like at the moment:
Also, how can I convert the cpu
output to a percentage?