aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xdwm-statusbar40
1 files changed, 22 insertions, 18 deletions
diff --git a/dwm-statusbar b/dwm-statusbar
index 6ebd11c..06803e3 100755
--- a/dwm-statusbar
+++ b/dwm-statusbar
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/usr/bin/zsh
#
# Status bar for dwm. Adapted from:
# https://github.com/w0ng/bin/blob/master/dwm-statusbar
@@ -19,7 +19,6 @@ space=" "
refresh="5"
# Name of the network adapters, like enp3s0
-eth_adapter=""
wlan_adapter="wlp1s0"
print_date() {
@@ -40,7 +39,7 @@ print_volume() {
volume=$(amixer get Master -M | tail -n1 | sed -r 's/.*\[(.*)%\].*/\1/')
mute="$(amixer get Master | tail -n1 | sed -r 's/.*\[(on|off)\].*/\1/')"
- if [ "$mute" == "off" ]; then
+ if [[ "$mute" == "off" ]]; then
vol_colour=$colour_warning
icon_colour=$colour_warning
icon="\uE022"
@@ -215,25 +214,32 @@ print_cpu_used() {
# Configure the adapter to display above
print_eth() {
- eth_status=$(ip addr show dev ${eth_adapter} | awk 'NR==1 {print $9}')
+ devices=($(ip -oneline addr show up | ip -oneline addr show up | awk 'match($0, /.+(enp.*?) inet ([0-9.]+)\/.*/, cap) {print cap[1]}'))
- if [ "$eth_status" == "UP" ]; then
- eth_ip=$(ip addr show dev ${eth_adapter} | awk 'NR==3 {print $2}' | sed -r 's/\/.*//')
- icon_colour=${colour_neutral}
- eth_colour=${colour_normal}
- else
- icon_colour=${colour_faded}
- fi
+ for dev in $devices; do
+ ip=$(ip -oneline addr show dev $dev | awk 'match($0, /.+enp.*inet ([0-9.]+)\/.*/, cap) {print cap[1]}')
+ speed=$(ethtool $dev &> /dev/null | awk 'match($0, / *Speed: ([0-9A-z/]+).*/, cap) {print cap[1]}')
- echo -ne "${icon_colour}\uE0E4${eth_colour}${eth_ip}"
+ if [[ $speed == "10Mb/s" ]]; then
+ icon_colour=${colour_critical}
+ eth_colour=${colour_critical}
+ elif [[ $speed == "100Mb/s" ]]; then
+ icon_colour=${colour_warning}
+ eth_colour=${colour_warning}
+ else
+ icon_colour=${colour_neutral}
+ eth_colour=${colour_normal}
+ fi
+ echo -ne "${space}${icon_colour}\uE0E4${eth_colour}${ip} ${speed}"
+ done
}
# Configure the adapter to display above, strength might need to be tweaked
print_wlan() {
wlan_status=$(ip addr show dev ${wlan_adapter} | awk 'NR==1 {print $9}')
- if [ "$wlan_status" == "UP" ]; then
- wlan_ip=$(ip addr show dev ${wlan_adapter} | awk 'NR==3 {print $2}' | sed -r 's/\/.*//')
+ if [[ "$wlan_status" == "UP" ]]; then
+ wlan_ip=$(ip -oneline addr show dev wlp1s0 | awk 'match($0, /.+wlp.*inet ([0-9.]+)\/.*/, cap) {print cap[1]}')
let wlan_strength="10 * $(cat /proc/net/wireless | awk 'NR==3 {print substr($3, 1, 2)}') / 7"
if [ $wlan_strength -lt 25 ]; then
@@ -246,14 +252,12 @@ print_wlan() {
icon_colour=${colour_neutral}
wlan_colour=${colour_normal}
fi
-
- wlan_strength="${wlan_strength}%"
else
icon_colour=${colour_faded}
fi
- echo -ne "${icon_colour}\uE401${wlan_colour}${wlan_ip} ${wlan_strength}"
+ echo -ne "${icon_colour}\uE401${wlan_colour}${wlan_ip} ${wlan_strength}%"
}
while true; do
@@ -265,7 +269,7 @@ while true; do
# Pipe to status bar
# This is where you can adjust what gets shown by adding the desired function calls
- xsetroot -name "$(print_wlan)${space}$(print_root_free)${space}$(print_home_free)${space}$(print_cpu_used)${space}$(print_cpu_temp)${space}$(print_mem_free)${space}$(print_battery)${space}$(print_backlight)${space}$(print_volume)${space}$(print_time)$(print_date)"
+ xsetroot -name "$(print_eth)${space}$(print_wlan)${space}$(print_root_free)${space}$(print_home_free)${space}$(print_cpu_used)${space}$(print_cpu_temp)${space}$(print_mem_free)${space}$(print_battery)${space}$(print_backlight)${space}$(print_volume)${space}$(print_time)$(print_date)"
# reset old rate
cpu_idle_old=$cpu_idle_now