Created
October 27, 2020 15:17
-
-
Save johnhamelink/a4f3f3b6b16c2ce66cb0268d181ce7b4 to your computer and use it in GitHub Desktop.
Mullvad VPN + Polybar = π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PID_FILE=~/.cache/mullvad-status-pid | |
SUCCESS_HOOK=1 | |
SHUTDOWN_HOOK=1 | |
finish() { | |
echo "Shutting down..." | |
rm $PID_FILE | |
rm $CACHE_FILE | |
polybar-msg hook mullvad ${SHUTDOWN_HOOK} | |
exit 0 | |
} | |
startup_check() { | |
if [ -f "$PID_FILE" ] && kill -0 "$(cat $PID_FILE)" 2>/dev/null; then | |
echo "Either another process is running, or the process did not close cleanly last time." | |
echo "Try deleting ${PID_FILE} if this is an error." | |
exit 1 | |
fi | |
echo $$ > $PID_FILE | |
} | |
main() { | |
mullvad status listen | while IFS= read -r line; do | |
echo "${line}" | |
if [[ $line =~ Disconnected ]]; then | |
echo "Disconnected" > $CACHE_FILE | |
fi | |
if [[ $line =~ Connecting ]]; then | |
echo "Connecting" > $CACHE_FILE | |
fi | |
if [[ $line =~ Connected ]]; then | |
ip=$(echo "${line}" | awk '{ print $6 }' | sed 's/:.*//') | |
echo "${ip}" > $CACHE_FILE | |
fi | |
polybar-msg hook mullvad ${SUCCESS_HOOK} | |
done | |
} | |
startup_check | |
trap finish SIGINT SIGQUIT SIGTSTP | |
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[module/mullvad] | |
format-prefix = "ξ― " | |
format-prefix-foreground = ${colors.foreground-alt} | |
format = <output> | |
type = custom/ipc | |
hook-0 = cat ~/.cache/mullvad-status | |
click-left = mullvad connect | |
double-click-left = mullvad reconnect | |
click-right = mullvad disconnect | |
initial = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result!