#!/usr/bin/env bash # Recommended to store this file in the $HOME/.config/polybar/polybar-scripts/ folder # you can use... mkdir $HOME/.config/polybar && mkdir $HOME/.config/polybar/polybar-scripts/ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Temp File to save a state, Polybar makes a variable loop impossible # unless we pull the value from outside of our script in another file. F=/tmp/polybar_mask_ip_toggle # Our print values! IP="$(hostname -I | awk '{print $1}')" MASK="████████████" # detect real interface name INTERFACENAME=$(ip route get 1.1.1.1 2>/dev/null \ | awk '/dev/ { for(i=1;i "$F" fi # If called to toggle, flip 1↔ 2, write and exit if [[ $1 == "toggle" ]]; then state=$(<"$F") # compute next: 1→ 2, 2→ 1 next=$(( state % 2 + 1 )) echo $next > "$F" exit 0 fi # Otherwise, just read the state and print state=$(<"$F") if (( state == 1 )); then echo "%{F#F0C674}$INTERFACENAME%{F-} $MASK" else echo "%{F#F0C674}$INTERFACENAME%{F-} $IP" fi