dwm/dwm_status
Marcin Wozniak a4da1b7a2b Added files
2019-05-20 14:40:18 +02:00

110 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
function get_bytes {
interface=$(ip route get 8.8.8.8 2>/dev/null| awk '{print $5}')
line=$(grep $interface /proc/net/dev | cut -d ':' -f 2 | awk '{print "received_bytes="$1, "transmitted_bytes="$9}')
eval $line
now=$(date +%s%N)
}
# Function which calculates the speed using actual and old byte number.
# Speed is shown in KByte per second when greater or equal than 1 KByte per second.
# This function should be called each second.
function get_velocity {
value=$1
old_value=$2
now=$3
}
print_volume() {
[ "$(pulsemixer --get-mute)" = "1" ] && printf "MUTE" && exit
vol=$(pulsemixer --get-volume | awk '{print $1}')
printf "%s%%\\n" "$vol"
}
print_wifi()
{
ESSID="`iw dev wlan0 link | grep SSID| sed -r 's/SSID://' | sed -e 's/^[ \t]*//'`"
echo -e "$ESSID"
}
print_mem(){
memfree=$(($(grep -m1 'MemAvailable:' /proc/meminfo | awk '{print $2}') / 1024))
echo -e "$memfree"
}
print_temp(){
echo -e "$(sensors | awk '/Core 0/ {print $3}') +$(nvidia-smi -q -d temperature | grep -i "GPU Current" |sed -r 's/GPU Current Temp ://'| sed -r 's/ C//' |sed -e 's/^[ \t]*//').0°C"
}
print_bat(){
hash acpi || return 0
onl="$(grep "on-line" <(acpi -V))"
charge="$(awk '{ sum += $1 } END { print sum }' /sys/class/power_supply/BAT*/capacity)"
if test -z "$onl"
then
# suspend when we close the lid
#systemctl --user stop inhibit-lid-sleep-on-battery.service
echo -e "B:${charge}%"
else
# On mains! no need to suspend
#systemctl --user start inhibit-lid-sleep-on-battery.service
echo -e "B:${charge}%"
fi
}
print_date(){
echo -e "$(date +"%m-%e %H:%M")"
}
print_mail(){
RESULT=$(echo "$(du -a ~/.mailbox/*/inbox/new/* 2>/dev/null | sed -n '$=')$(cat /tmp/imapsyncicon_$USER 2>/dev/null)")
if [ -z $RESULT ]; then
echo "0"
else
echo "$(du -a ~/.mailbox/*/inbox/new/* 2>/dev/null | sed -n '$=')$(cat /tmp/imapsyncicon_$USER 2>/dev/null)"
fi
}
echo AUTOSTART
feh --bg-fill $HOME/.wall.jpg &
xset s off -dpms&
xset b off&
xset s off&
xset -dpms&
redshift -l 52.2327:18.3036 -t 6500:3200&
nm-applet --sm-disable&
/usr/local/bin/st -e "tmux-my"&
"/mnt/mega/Systems/Gentoo/apps/KeePass.AppImage"&
megasync&
opera-developer&
dunst -config&
/usr/bin/ibus-daemon -d&
sh /home/yorune/.xsessionrc&
keepassxc&
transmission-daemon&
teamviewer&
while true
do
# Get new transmitted, received byte number values and current time
get_bytes
# Calculates speeds
vel_recv=$(get_velocity $received_bytes $old_received_bytes $now)
vel_trans=$(get_velocity $transmitted_bytes $old_transmitted_bytes $now)
xsetroot -name "M:$(print_mail) $(print_temp) $(sh /home/yorune/dwm/weather.sh) $(print_wifi) $(print_bat) V:$(print_volume) $(print_date)"
# Update old values to perform new calculations
old_received_bytes=$received_bytes
old_transmitted_bytes=$transmitted_bytes
old_time=$now
sleep 1
done