Skip to content

Instantly share code, notes, and snippets.

@8dcc
Last active September 23, 2022 23:00
Show Gist options
  • Save 8dcc/c99ae9ba6c42c9b9e7b15468ad1e26f4 to your computer and use it in GitHub Desktop.
Save 8dcc/c99ae9ba6c42c9b9e7b15468ad1e26f4 to your computer and use it in GitHub Desktop.
Simpler version of my dwmbar without icons and with less stuff (for smaller resolutions)
#!/bin/bash
# https://github.com/r4v10l1/arch-dotfiles
#####################
multibattery=false #
hourchange=true #
hourdiff=-2 # Ignored if !hourchange
#####################
dte() {
if [[ $hourchange == true ]]; then
hour=$(date +"%H")
# Subtract one from the hour unless it is 00
if [[ $hour == 00 ]]; then
hour=23
else
hour=$(($hour + $hourdiff))
fi
# Add a 0 after the subtraction
if [[ $hour < 10 && $hour > 0 ]]; then
hour="0$hour" # Kinda not working ngl
fi
dte="$(date +"%d-%b $hour:%M")"
else
dte="$(date +"%d-%b %R")"
fi
echo "$dte"
}
hdd() {
hdd="$(df -h /home | grep dev | awk '{print$5}')"
echo "$hdd"
}
mem() {
mem="$(free -h | awk '/Mem:/ {printf $3 "-" $2}')"
echo "$mem"
}
cpu() {
read cpu a b c previdle rest < /proc/stat
prevtotal=$((a+b+c+previdle))
sleep 0.5
read cpu a b c idle rest < /proc/stat
total=$((a+b+c+idle))
cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
echo "$cpu%"
}
pkgs() {
pkgs="$(apt list --installed | wc -l)"
echo "$pkgs"
}
vpn() {
vpn="$(ip a | grep tun0 | grep inet | wc -l)"
echo "VPN: $vpn"
}
vol() {
vol="$(amixer -D pulse get Master | awk -F'[][]' 'END{print $2}')"
muted="$(amixer -D pulse get Master | awk -F'[][]' 'END{print $4}')"
if [[ $muted == off ]]; then
echo "Muted"
else
echo "$vol"
fi
}
batt() {
if [[ $multibattery == false ]]; then
batt1=$(acpi | awk '{print $4}' | sed s/,//)
echo "$batt1"
else
# First battery
if [[ $(acpi | head -n 1 | awk '{print $3}') == "Charging," ]]; then
# If battery is being charged we display a different icon
batt1=" $(acpi | head -n 1 | awk '{print $4}')"
elif [[ $(acpi | head -n 1 | awk '{print $3}') == "Not" ]]; then
# If battery is not being charged we use the 5th field
batt1=" $(acpi | head -n 1 | awk '{print $5}')"
else
batt1=" $(acpi | head -n 1 | awk '{print $4}')"
fi
# Second battery
if [[ $(acpi | tail -n 1 | awk '{print $3}') == "Charging," ]]; then
batt2=" $(acpi | tail -n 1 | awk '{print $4}')"
elif [[ $(acpi | tail -n 1 | awk '{print $3}') == "Not" ]];then
batt2=" $(acpi | tail -n 1 | awk '{print $5}')"
else
batt2=" $(acpi | tail -n 1 | awk '{print $4}')"
fi
# Check for weird commas
if [[ $batt1 == *","* ]]; then
batt1=${batt1::-1}
fi
if [[ $batt2 == *","* ]]; then
batt2=${batt2::-1}
fi
echo "$batt1 - $batt2"
fi
}
status() {
echo " C:$(cpu) | M:$(mem) | B:$(batt) | $(dte) "
}
while true; do
xsetroot -name "$(status)"
sleep 5
done &
@8dcc
Copy link
Author

8dcc commented Sep 23, 2022

Original: Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment