perf(sketchybar,polybar): mullvad plugin - use listen instead of poll
This commit is contained in:
parent
3fad9a4d76
commit
f9c4303746
3 changed files with 18 additions and 15 deletions
|
@ -108,7 +108,6 @@ sketchybar \
|
|||
--add item mullvad right \
|
||||
--set mullvad \
|
||||
script="$PLUGIN_DIR/mullvad.sh" \
|
||||
update_freq=10 \
|
||||
\
|
||||
--add item battery right \
|
||||
--set battery \
|
||||
|
|
|
@ -3,19 +3,18 @@
|
|||
# path where mullvad is kept
|
||||
PATH=/usr/local/bin:$PATH
|
||||
|
||||
if command -v mullvad &> /dev/null; then
|
||||
MULLVAD_STATUS=$(mullvad status)
|
||||
if ! [ -x "$(command -v mullvad)" ]; then
|
||||
sketchybar --set "$NAME" icon=" " label=""
|
||||
fi
|
||||
|
||||
if echo "$MULLVAD_STATUS" | grep -q 'Connected'; then
|
||||
OUTPUT=$(mullvad status | cut -d " " -f 3 | cut -d "-" -f 1 | tr '/a-z/' '/A-Z/')
|
||||
while read -r LINE; do
|
||||
if echo "$LINE" | grep -q 'Connected'; then
|
||||
# regex grep the relay, e.g. se7 for sweden-7
|
||||
OUTPUT=$(echo "$LINE" | grep -oE "\w{2}\d+")
|
||||
ICON=" "
|
||||
else
|
||||
ICON=" "
|
||||
fi
|
||||
|
||||
else
|
||||
ICON=" "
|
||||
OUTPUT=""
|
||||
fi
|
||||
|
||||
sketchybar --set "$NAME" icon="$ICON" label="$OUTPUT"
|
||||
sketchybar --set "$NAME" icon="$ICON" label="${OUTPUT^^}"
|
||||
done < <(mullvad status listen)
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# if mullvad is not installed
|
||||
if ! [ -x "$(command -v mullvad)" ]; then
|
||||
echo " "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while read -r LINE; do
|
||||
if echo "$LINE" | grep -q 'Connected'; then
|
||||
# get the relay (3rd word) | drop the wireguard/openvpn suffix | make it uppercase
|
||||
# just replace this with whatever style you like
|
||||
OUTPUT=$(echo "$LINE" | cut -d " " -f 3 | cut -d "-" -f 1 | tr '/a-z/' '/A-Z/')
|
||||
# regex grep the relay, e.g. se7 for sweden-7
|
||||
OUTPUT=$(echo "$LINE" | grep -oE "\w{2}\d+")
|
||||
ICON=" "
|
||||
else
|
||||
ICON=" "
|
||||
fi
|
||||
|
||||
echo "$ICON" "$OUTPUT"
|
||||
echo "$ICON" "${OUTPUT^^}"
|
||||
done < <(mullvad status listen)
|
||||
|
|
Loading…
Reference in a new issue