Skip to content

Instantly share code, notes, and snippets.

@johnhamelink
Created October 27, 2020 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhamelink/a4f3f3b6b16c2ce66cb0268d181ce7b4 to your computer and use it in GitHub Desktop.
Save johnhamelink/a4f3f3b6b16c2ce66cb0268d181ce7b4 to your computer and use it in GitHub Desktop.
Mullvad VPN + Polybar = 😍
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
[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
@johnhamelink
Copy link
Author

The result!

27-10-2020 15:18:07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment