diff --git a/dot_config/sketchybar/executable_sketchybarrc b/dot_config/sketchybar/executable_sketchybarrc index 6eb872e..a3b3b42 100644 --- a/dot_config/sketchybar/executable_sketchybarrc +++ b/dot_config/sketchybar/executable_sketchybarrc @@ -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 \ diff --git a/dot_config/sketchybar/plugins/executable_mullvad.sh b/dot_config/sketchybar/plugins/executable_mullvad.sh index 2ebd81e..beaeae0 100644 --- a/dot_config/sketchybar/plugins/executable_mullvad.sh +++ b/dot_config/sketchybar/plugins/executable_mullvad.sh @@ -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) diff --git a/dot_local/bin/executable_mullvad-status b/dot_local/bin/executable_mullvad-status index 95e9ad2..3c6d254 100644 --- a/dot_local/bin/executable_mullvad-status +++ b/dot_local/bin/executable_mullvad-status @@ -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)