Author: Honza Pokorny <me@honza.ca>
Better vpn detection
bin/is-vpn-connected | 8 ++++++++ i3/i3status.py | 17 +++++++++++++----
diff --git a/bin/is-vpn-connected b/bin/is-vpn-connected new file mode 100755 index 0000000000000000000000000000000000000000..d7a148a57b33db687a8697a02e858c748d849b5e --- /dev/null +++ b/bin/is-vpn-connected @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# Status code: +# +# 0 => Connected +# 1 => Not connected + +nmcli connection show --active | grep vpn \ No newline at end of file diff --git a/i3/i3status.py b/i3/i3status.py index 8d66fdcf45217f7c3046b0e475c05a4c800f1b1a..a2ba4258f1a9ec7648daa31ab8d52bb950764779 100755 --- a/i3/i3status.py +++ b/i3/i3status.py @@ -2,8 +2,14 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import json +import os import subprocess import sys + +RED = '#dc322f' +GREEN = '#2aa198' + +NULL = open(os.devnull, 'w') def get_memory(): @@ -29,14 +35,17 @@ def get_vpn(): try: - host = subprocess.check_output(["host", "mail.corp.redhat.com"]) - vpn_connected = 'has address' in host - except: + subprocess.check_call( + ["/home/honza/dotfiles/bin/is-vpn-connected"], + stdout=NULL + ) + vpn_connected = True + except Exception: vpn_connected = False return { 'full_text': "VPN", 'name': 'vpn', - 'color': '#00FF00' if vpn_connected else '#FF0000', + 'color': GREEN if vpn_connected else RED }