perf(sketchybar,polybar): mullvad plugin - use listen instead of poll

This commit is contained in:
winston 2022-07-31 21:31:57 +02:00
parent 3fad9a4d76
commit f9c4303746
Signed by: winston
GPG key ID: 3786770EDBC2B481
3 changed files with 18 additions and 15 deletions

View file

@ -108,7 +108,6 @@ sketchybar \
--add item mullvad right \ --add item mullvad right \
--set mullvad \ --set mullvad \
script="$PLUGIN_DIR/mullvad.sh" \ script="$PLUGIN_DIR/mullvad.sh" \
update_freq=10 \
\ \
--add item battery right \ --add item battery right \
--set battery \ --set battery \

View file

@ -3,19 +3,18 @@
# path where mullvad is kept # path where mullvad is kept
PATH=/usr/local/bin:$PATH PATH=/usr/local/bin:$PATH
if command -v mullvad &> /dev/null; then if ! [ -x "$(command -v mullvad)" ]; then
MULLVAD_STATUS=$(mullvad status) sketchybar --set "$NAME" icon=" " label=""
fi
if echo "$MULLVAD_STATUS" | grep -q 'Connected'; then while read -r LINE; do
OUTPUT=$(mullvad status | cut -d " " -f 3 | cut -d "-" -f 1 | tr '/a-z/' '/A-Z/') 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=" " ICON=" "
else else
ICON=" " ICON=" "
fi fi
else sketchybar --set "$NAME" icon="$ICON" label="${OUTPUT^^}"
ICON=" " done < <(mullvad status listen)
OUTPUT=""
fi
sketchybar --set "$NAME" icon="$ICON" label="$OUTPUT"

View file

@ -1,14 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# if mullvad is not installed
if ! [ -x "$(command -v mullvad)" ]; then
echo " "
exit 1
fi
while read -r LINE; do while read -r LINE; do
if echo "$LINE" | grep -q 'Connected'; then if echo "$LINE" | grep -q 'Connected'; then
# get the relay (3rd word) | drop the wireguard/openvpn suffix | make it uppercase # regex grep the relay, e.g. se7 for sweden-7
# just replace this with whatever style you like OUTPUT=$(echo "$LINE" | grep -oE "\w{2}\d+")
OUTPUT=$(echo "$LINE" | cut -d " " -f 3 | cut -d "-" -f 1 | tr '/a-z/' '/A-Z/')
ICON=" " ICON=" "
else else
ICON=" " ICON=" "
fi fi
echo "$ICON" "$OUTPUT" echo "$ICON" "${OUTPUT^^}"
done < <(mullvad status listen) done < <(mullvad status listen)