aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2024-01-22 07:28:23 +0100
committerEddy Pedroni <epedroni@pm.me>2024-01-22 07:28:23 +0100
commit94b84430683a47a379da0554d38447167caf8bd0 (patch)
tree37973c346150865472ee2c65cff804b4a56753c2
parent3011bc0b8fde77baf02e6d2aa22f11bce0a4a94b (diff)
Status bar support for multiple dynamic ETH interfacescustom
-rwxr-xr-xdwm-statusbar25
1 files changed, 10 insertions, 15 deletions
diff --git a/dwm-statusbar b/dwm-statusbar
index 6ebd11c..383cd75 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,24 +214,20 @@ print_cpu_used() {
# Configure the adapter to display above
print_eth() {
- eth_status=$(ip addr show dev ${eth_adapter} | awk 'NR==1 {print $9}')
+ icon_colour=${colour_neutral}
+ eth_colour=${colour_normal}
+ ips=($(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
-
- echo -ne "${icon_colour}\uE0E4${eth_colour}${eth_ip}"
+ for eth_ip in $ips; do
+ echo -ne "${space}${icon_colour}\uE0E4${eth_colour}${eth_ip}"
+ 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
+ if [[ "$wlan_status" == "UP" ]]; then
wlan_ip=$(ip addr show dev ${wlan_adapter} | awk 'NR==3 {print $2}' | sed -r 's/\/.*//')
let wlan_strength="10 * $(cat /proc/net/wireless | awk 'NR==3 {print substr($3, 1, 2)}') / 7"
@@ -265,7 +260,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