ENH dynamically grab wifi interface in xmobar
This commit is contained in:
parent
04343e5bdc
commit
adc2222a21
248
bin/xmobar.hs
248
bin/xmobar.hs
|
@ -13,10 +13,16 @@ module Main (main) where
|
||||||
|
|
||||||
import Control.Monad (filterM)
|
import Control.Monad (filterM)
|
||||||
|
|
||||||
|
import Data.Either
|
||||||
import Data.List
|
import Data.List
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
import DBus
|
import DBus
|
||||||
|
|
||||||
|
import System.Directory
|
||||||
|
import System.FilePath.Posix
|
||||||
|
import System.IO.Error
|
||||||
|
|
||||||
import Xmobar.Plugins.Bluetooth
|
import Xmobar.Plugins.Bluetooth
|
||||||
import Xmobar.Plugins.Device
|
import Xmobar.Plugins.Device
|
||||||
import Xmobar.Plugins.IntelBacklight
|
import Xmobar.Plugins.IntelBacklight
|
||||||
|
@ -83,120 +89,138 @@ filterSpecs = filterM (maybe (return True) exists . csDepends)
|
||||||
where
|
where
|
||||||
exists DBusDepends { ddBus = b, ddPath = p, ddSys = s } = pathExists s b p
|
exists DBusDepends { ddBus = b, ddPath = p, ddSys = s } = pathExists s b p
|
||||||
|
|
||||||
myCommands :: BarRegions
|
sysfsNet :: FilePath
|
||||||
myCommands = BarRegions
|
sysfsNet = "/sys/class/net"
|
||||||
{ brLeft =
|
|
||||||
[ CmdSpec
|
|
||||||
{ csAlias = "UnsafeStdinReader"
|
|
||||||
, csDepends = Nothing
|
|
||||||
, csRunnable = Run UnsafeStdinReader
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
, brCenter = []
|
wirelessCmd :: String -> CmdSpec
|
||||||
|
wirelessCmd interface = CmdSpec
|
||||||
, brRight =
|
{ csAlias = interface ++ "wi"
|
||||||
[ CmdSpec
|
, csDepends = Nothing
|
||||||
{ csAlias = "wlp0s20f3wi"
|
, csRunnable = Run
|
||||||
, csDepends = Nothing
|
$ Wireless interface
|
||||||
, csRunnable = Run
|
[ "-t", "<qualityipat><essid>"
|
||||||
$ Wireless "wlp0s20f3"
|
, "--"
|
||||||
[ "-t", "<qualityipat><essid>"
|
, "--quality-icon-pattern", "<icon=wifi_%%.xpm/>"
|
||||||
, "--"
|
] 5
|
||||||
, "--quality-icon-pattern", "<icon=wifi_%%.xpm/>"
|
|
||||||
] 5
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = "enp7s0f1"
|
|
||||||
, csDepends = Just $ sysDepends devBus devPath
|
|
||||||
, csRunnable = Run
|
|
||||||
$ Device ("enp7s0f1", "<fn=2>\xf0e8</fn>", T.fgColor, T.backdropFgColor) 5
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = vpnAlias
|
|
||||||
, csDepends = Just $ sysDepends vpnBus vpnPath
|
|
||||||
, csRunnable = Run
|
|
||||||
$ VPN ("<fn=2>\xf023</fn>", T.fgColor, T.backdropFgColor) 5
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = btAlias
|
|
||||||
, csDepends = Just $ sysDepends btBus btPath
|
|
||||||
, csRunnable = Run
|
|
||||||
$ Bluetooth ("<fn=2>\xf293</fn>", T.fgColor, T.backdropFgColor) 5
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = "alsa:default:Master"
|
|
||||||
, csDepends = Nothing
|
|
||||||
, csRunnable = Run
|
|
||||||
$ Alsa "default" "Master"
|
|
||||||
[ "-t", "<status><volume>%"
|
|
||||||
, "--"
|
|
||||||
, "-O", "<fn=1>\xf028</fn>"
|
|
||||||
, "-o", "<fn=1>\xf026 </fn>"
|
|
||||||
, "-c", T.fgColor
|
|
||||||
, "-C", T.fgColor
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = "battery"
|
|
||||||
, csDepends = Nothing
|
|
||||||
, csRunnable = Run
|
|
||||||
$ Battery
|
|
||||||
[ "--template", "<acstatus><left>"
|
|
||||||
, "--Low", "10"
|
|
||||||
, "--High", "80"
|
|
||||||
, "--low", "red"
|
|
||||||
, "--normal", T.fgColor
|
|
||||||
, "--high", T.fgColor
|
|
||||||
, "--"
|
|
||||||
, "-P"
|
|
||||||
, "-o" , "<fn=1>\xf0e7</fn>"
|
|
||||||
, "-O" , "<fn=1>\xf1e6</fn>"
|
|
||||||
, "-i" , "<fn=1>\xf1e6</fn>"
|
|
||||||
] 50
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = "intelbacklight"
|
|
||||||
, csDepends = Just $ sesDepends xmonadBus blPath
|
|
||||||
, csRunnable = Run $ IntelBacklight "<fn=1>\xf185</fn>"
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = ssAlias
|
|
||||||
, csDepends = Just $ sesDepends xmonadBus ssPath
|
|
||||||
, csRunnable = Run
|
|
||||||
$ Screensaver ("<fn=1>\xf254</fn>", T.fgColor, T.backdropFgColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = "locks"
|
|
||||||
, csDepends = Nothing
|
|
||||||
, csRunnable = Run
|
|
||||||
$ Locks
|
|
||||||
[ "-N", "<fn=3>\x1f13d</fn>"
|
|
||||||
, "-n", xmobarColor T.backdropFgColor "" "<fn=3>\x1f13d</fn>"
|
|
||||||
, "-C", "<fn=3>\x1f132</fn>"
|
|
||||||
, "-c", xmobarColor T.backdropFgColor "" "<fn=3>\x1f132</fn>"
|
|
||||||
, "-s", ""
|
|
||||||
, "-S", ""
|
|
||||||
, "-d", "<fn=3> </fn>"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
, CmdSpec
|
|
||||||
{ csAlias = "date"
|
|
||||||
, csDepends = Nothing
|
|
||||||
, csRunnable = Run $ Date "%Y-%m-%d %H:%M:%S " "date" 10
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getWireless :: IO (Maybe CmdSpec)
|
||||||
|
getWireless = do
|
||||||
|
r <- tryIOError (listDirectory sysfsNet)
|
||||||
|
ns <- filterM hasWireless $ fromRight [] r
|
||||||
|
return $ case ns of
|
||||||
|
[n] -> Just $ wirelessCmd n
|
||||||
|
_ -> Nothing
|
||||||
|
where
|
||||||
|
hasWireless p = doesPathExist $ sysfsNet </> p </> "wireless"
|
||||||
|
|
||||||
|
myCommands :: IO BarRegions
|
||||||
|
myCommands = do
|
||||||
|
wirelessSpec <- getWireless
|
||||||
|
let left =
|
||||||
|
[ CmdSpec
|
||||||
|
{ csAlias = "UnsafeStdinReader"
|
||||||
|
, csDepends = Nothing
|
||||||
|
, csRunnable = Run UnsafeStdinReader
|
||||||
|
}
|
||||||
|
]
|
||||||
|
let right =
|
||||||
|
[ wirelessSpec
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = "enp7s0f1"
|
||||||
|
, csDepends = Just $ sysDepends devBus devPath
|
||||||
|
, csRunnable = Run
|
||||||
|
$ Device ("enp7s0f1", "<fn=2>\xf0e8</fn>", T.fgColor, T.backdropFgColor) 5
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = vpnAlias
|
||||||
|
, csDepends = Just $ sysDepends vpnBus vpnPath
|
||||||
|
, csRunnable = Run
|
||||||
|
$ VPN ("<fn=2>\xf023</fn>", T.fgColor, T.backdropFgColor) 5
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = btAlias
|
||||||
|
, csDepends = Just $ sysDepends btBus btPath
|
||||||
|
, csRunnable = Run
|
||||||
|
$ Bluetooth ("<fn=2>\xf293</fn>", T.fgColor, T.backdropFgColor) 5
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = "alsa:default:Master"
|
||||||
|
, csDepends = Nothing
|
||||||
|
, csRunnable = Run
|
||||||
|
$ Alsa "default" "Master"
|
||||||
|
[ "-t", "<status><volume>%"
|
||||||
|
, "--"
|
||||||
|
, "-O", "<fn=1>\xf028</fn>"
|
||||||
|
, "-o", "<fn=1>\xf026 </fn>"
|
||||||
|
, "-c", T.fgColor
|
||||||
|
, "-C", T.fgColor
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = "battery"
|
||||||
|
, csDepends = Nothing
|
||||||
|
, csRunnable = Run
|
||||||
|
$ Battery
|
||||||
|
[ "--template", "<acstatus><left>"
|
||||||
|
, "--Low", "10"
|
||||||
|
, "--High", "80"
|
||||||
|
, "--low", "red"
|
||||||
|
, "--normal", T.fgColor
|
||||||
|
, "--high", T.fgColor
|
||||||
|
, "--"
|
||||||
|
, "-P"
|
||||||
|
, "-o" , "<fn=1>\xf0e7</fn>"
|
||||||
|
, "-O" , "<fn=1>\xf1e6</fn>"
|
||||||
|
, "-i" , "<fn=1>\xf1e6</fn>"
|
||||||
|
] 50
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = "intelbacklight"
|
||||||
|
, csDepends = Just $ sesDepends xmonadBus blPath
|
||||||
|
, csRunnable = Run $ IntelBacklight "<fn=1>\xf185</fn>"
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = ssAlias
|
||||||
|
, csDepends = Just $ sesDepends xmonadBus ssPath
|
||||||
|
, csRunnable = Run
|
||||||
|
$ Screensaver ("<fn=1>\xf254</fn>", T.fgColor, T.backdropFgColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = "locks"
|
||||||
|
, csDepends = Nothing
|
||||||
|
, csRunnable = Run
|
||||||
|
$ Locks
|
||||||
|
[ "-N", "<fn=3>\x1f13d</fn>"
|
||||||
|
, "-n", xmobarColor T.backdropFgColor "" "<fn=3>\x1f13d</fn>"
|
||||||
|
, "-C", "<fn=3>\x1f132</fn>"
|
||||||
|
, "-c", xmobarColor T.backdropFgColor "" "<fn=3>\x1f132</fn>"
|
||||||
|
, "-s", ""
|
||||||
|
, "-S", ""
|
||||||
|
, "-d", "<fn=3> </fn>"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
, Just $ CmdSpec
|
||||||
|
{ csAlias = "date"
|
||||||
|
, csDepends = Nothing
|
||||||
|
, csRunnable = Run $ Date "%Y-%m-%d %H:%M:%S " "date" 10
|
||||||
|
}
|
||||||
|
]
|
||||||
|
return $ BarRegions
|
||||||
|
{ brLeft = left
|
||||||
|
, brCenter = []
|
||||||
|
, brRight = catMaybes right
|
||||||
|
}
|
||||||
|
|
||||||
fmtSpecs :: [CmdSpec] -> String
|
fmtSpecs :: [CmdSpec] -> String
|
||||||
fmtSpecs = intercalate sep . fmap go
|
fmtSpecs = intercalate sep . fmap go
|
||||||
where
|
where
|
||||||
|
@ -264,6 +288,6 @@ config br confDir = defaultConfig
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
br <- mapRegionsM filterSpecs myCommands
|
br <- mapRegionsM filterSpecs =<< myCommands
|
||||||
dir <- getXMonadDir
|
dir <- getXMonadDir
|
||||||
xmobar $ config br dir
|
xmobar $ config br dir
|
||||||
|
|
|
@ -65,6 +65,8 @@ executable xmobar
|
||||||
, my-xmonad
|
, my-xmonad
|
||||||
, xmobar
|
, xmobar
|
||||||
, xmonad >= 0.13
|
, xmonad >= 0.13
|
||||||
|
, filepath >= 1.4.2.1
|
||||||
, xmonad-contrib >= 0.13
|
, xmonad-contrib >= 0.13
|
||||||
|
, directory >= 1.3.3.0
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
ghc-options: -Wall -Werror -fno-warn-missing-signatures -threaded
|
ghc-options: -Wall -Werror -fno-warn-missing-signatures -threaded
|
Loading…
Reference in New Issue