.files/nix/packages/by-name/mullvad-status/mullvad-status.sh

33 lines
735 B
Bash

if ! type mullvad >/dev/null; then
echo -n "Mullvad unavailable"
exit 1
fi
MULLVAD_STATUS="$(mullvad status -j)"
function xmobarColor {
fg="$1"
x="$2"
echo -n "<fc=$fg>$x</fc>"
}
case "$(echo "$MULLVAD_STATUS" | jq -r ".state")" in
connected)
function has-feature {
echo "$MULLVAD_STATUS" | jq --exit-status ".details.feature_indicators|contains([\"$1\"])" >/dev/null
}
if has-feature "LockdownMode"; then
xmobarColor "green" "Mullvad On "
else
xmobarColor "orange" "Mullvad On"
fi
COUNTRY="$(echo "$MULLVAD_STATUS" | jq -r '.details.location.country')"
CITY="$(echo "$MULLVAD_STATUS" | jq -r '.details.location.city')"
echo -n " ($COUNTRY,$CITY)"
;;
disconnected)
xmobarColor "red" "Mullvad Off"
;;
esac