From b1eb899495ed996200a9e99c33bcc8f5a4896af9 Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 21 Nov 2018 20:52:03 +0000 Subject: Wireless: simple auto-detection of interface name --- src/Plugins/Monitors/Wireless.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Plugins/Monitors/Wireless.hs b/src/Plugins/Monitors/Wireless.hs index eeef9a9..9397e50 100644 --- a/src/Plugins/Monitors/Wireless.hs +++ b/src/Plugins/Monitors/Wireless.hs @@ -42,12 +42,14 @@ parseOpts argv = wirelessConfig :: IO MConfig wirelessConfig = - mkMConfig " " ["essid", "quality", "qualitybar", "qualityvbar", "qualityipat"] + mkMConfig " " + ["essid", "quality", "qualitybar", "qualityvbar", "qualityipat"] runWireless :: String -> [String] -> Monitor String runWireless iface args = do opts <- io $ parseOpts args - wi <- io $ getWirelessInfo iface + iface' <- if "" == iface then io findInterface else return iface + wi <- io $ getWirelessInfo iface' na <- getConfigValue naString let essid = wiEssid wi qlty = fromIntegral $ wiQuality wi @@ -60,3 +62,9 @@ runWireless iface args = do qvb <- showVerticalBar qlty (qlty / 100) qipat <- showIconPattern (qualityIconPattern opts) (qlty / 100) parseTemplate [ep, q, qb, qvb, qipat] + +findInterface :: IO String +findInterface = do + c <- readFile "/proc/net/wireless" + let nds = lines c + return $ if length nds > 2 then takeWhile (/= 'c') (nds!!2) else [] -- cgit v1.2.3