2021-09-11 21:45:56 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-12-25 16:35:45 +00:00
|
|
|
|
|
|
|
#
|
2021-09-11 21:45:56 +00:00
|
|
|
# {{@@ header() @@}}
|
2017-12-25 19:07:59 +00:00
|
|
|
#
|
2017-12-25 16:35:45 +00:00
|
|
|
# This script detects if an USB NIC was connected and reloads the bar
|
|
|
|
#
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
# Get PID of the bottom bar
|
|
|
|
pid_bottom_bar=$(ps -x | awk '!/awk/ && /9560-bottom/ {print $1}')
|
|
|
|
# 1st USB port (right)
|
2021-09-11 21:45:56 +00:00
|
|
|
if [[ -z ${USB_NIC1} ]]; then
|
2017-12-25 16:35:45 +00:00
|
|
|
USB_NIC1=$(ip link | awk '!/awk/ && /enp0s20f0u1/ {print $2}' | cut -d":" -f1)
|
2021-09-11 21:45:56 +00:00
|
|
|
if [[ -n ${USB_NIC1} ]]; then
|
|
|
|
polybar-msg -p ${pid_bottom_bar} cmd restart
|
2017-12-25 16:35:45 +00:00
|
|
|
fi
|
2021-09-11 21:45:56 +00:00
|
|
|
elif [[ -n ${USB_NIC1} ]]; then
|
2017-12-25 16:35:45 +00:00
|
|
|
USB_NIC1_CHECK=$(ip link | awk '!/awk/ && /enp0s20f0u1/ {print $2}' | cut -d":" -f1)
|
2021-09-11 21:45:56 +00:00
|
|
|
if [[ -z ${USB_NIC1_CHECK} ]]; then
|
2017-12-25 16:35:45 +00:00
|
|
|
unset USB_NIC1
|
2021-09-11 21:45:56 +00:00
|
|
|
polybar-msg -p ${pid_bottom_bar} cmd restart
|
2017-12-25 16:35:45 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 2nd USB port (left)
|
2021-09-11 21:45:56 +00:00
|
|
|
if [[ -z ${USB_NIC2} ]]; then
|
2017-12-25 16:35:45 +00:00
|
|
|
USB_NIC2=$(ip link | awk '!/awk/ && /enp0s20f0u2/ {print $2}' | cut -d":" -f1)
|
2021-09-11 21:45:56 +00:00
|
|
|
if [[ -n ${USB_NIC2} ]]; then
|
|
|
|
polybar-msg -p ${pid_bottom_bar} cmd restart
|
2017-12-25 16:35:45 +00:00
|
|
|
fi
|
2021-09-11 21:45:56 +00:00
|
|
|
elif [[ -n ${USB_NIC2} ]]; then
|
2017-12-25 16:35:45 +00:00
|
|
|
USB_NIC2_CHECK=$(ip link | awk '!/awk/ && /enp0s20f0u2/ {print $2}' | cut -d":" -f1)
|
2021-09-11 21:45:56 +00:00
|
|
|
if [[ -z ${USB_NIC2_CHECK} ]]; then
|
2017-12-25 16:35:45 +00:00
|
|
|
unset USB_NIC2
|
2021-09-11 21:45:56 +00:00
|
|
|
polybar-msg -p ${pid_bottom_bar} cmd restart
|
2017-12-25 16:35:45 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 5
|
|
|
|
done
|