diff --git a/bin/xmobar.hs b/bin/xmobar.hs
index 769eefb..398a62e 100644
--- a/bin/xmobar.hs
+++ b/bin/xmobar.hs
@@ -20,8 +20,10 @@ import Data.Maybe
import DBus
import System.Directory
+import System.Exit
import System.FilePath.Posix
import System.IO.Error
+import System.Process (readProcessWithExitCode)
import Xmobar.Plugins.Bluetooth
import Xmobar.Plugins.Device
@@ -114,9 +116,28 @@ getWireless = do
where
hasWireless p = doesPathExist $ sysfsNet > p > "wireless"
+vpnCmd :: CmdSpec
+vpnCmd = CmdSpec
+ { csAlias = vpnAlias
+ , csDepends = Just $ sysDepends vpnBus vpnPath
+ , csRunnable = Run
+ $ VPN ("\xf023", T.fgColor, T.backdropFgColor) 5
+ }
+
+getVPN :: IO (Maybe CmdSpec)
+getVPN = do
+ -- TODO ensure nmcli exists (or guard against an exception if it doesn't)
+ (ec, out, _) <- readProcessWithExitCode "nmcli" args ""
+ return $ case ec of
+ ExitSuccess -> if "vpn" `elem` lines out then Just vpnCmd else Nothing
+ _ -> Nothing
+ where
+ args = ["-c", "no", "-t", "-f", "TYPE", "c", "show"]
+
myCommands :: IO BarRegions
myCommands = do
wirelessSpec <- getWireless
+ vpnSpec <- getVPN
let left =
[ CmdSpec
{ csAlias = "UnsafeStdinReader"
@@ -134,12 +155,7 @@ myCommands = do
$ Device ("enp7s0f1", "\xf0e8", T.fgColor, T.backdropFgColor) 5
}
- , Just $ CmdSpec
- { csAlias = vpnAlias
- , csDepends = Just $ sysDepends vpnBus vpnPath
- , csRunnable = Run
- $ VPN ("\xf023", T.fgColor, T.backdropFgColor) 5
- }
+ , vpnSpec
, Just $ CmdSpec
{ csAlias = btAlias
diff --git a/my-xmonad.cabal b/my-xmonad.cabal
index c5799da..f81a9a2 100644
--- a/my-xmonad.cabal
+++ b/my-xmonad.cabal
@@ -65,6 +65,7 @@ executable xmobar
, my-xmonad
, xmobar
, xmonad >= 0.13
+ , process >= 1.6.5.0
, filepath >= 1.4.2.1
, xmonad-contrib >= 0.13
, directory >= 1.3.3.0