Module Eth +Mask IP
Transforms the [Module/Eth] into a module which can be used to show and hide your local machine's IP (if you're connected by ethernet)
This commit is contained in:
parent
bde6ceecbc
commit
461177d71c
37
Modules/Module Eth +Mask IP/mask_ip.sh
Normal file
37
Modules/Module Eth +Mask IP/mask_ip.sh
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#!/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<NF;i++) if($i=="dev") print $(i+1)}' \
|
||||||
|
| head -n1)
|
||||||
|
[[ -z "$IF" ]] && IF="eth0"
|
||||||
|
|
||||||
|
# Initialize state if missing
|
||||||
|
if [[ ! -f $F ]]; then
|
||||||
|
echo 1 > "$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
|
||||||
Loading…
x
Reference in New Issue
Block a user