take command path as argument
parent
e7d15f9718
commit
37e8aa3554
|
@ -9,15 +9,15 @@ import Monitors.Net (queryNet)
|
||||||
import Monitors.Volume (queryVolume)
|
import Monitors.Volume (queryVolume)
|
||||||
|
|
||||||
usage :: IO String
|
usage :: IO String
|
||||||
usage = printf "%s battery | volume | net" <$> getProgName
|
usage = printf "%s bat | vol | net | date" <$> getProgName
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
output <- case args of
|
output <- case args of
|
||||||
[ "bat" ] -> queryBattery
|
[ "bat", cmd ] -> queryBattery cmd
|
||||||
[ "vol" ] -> queryVolume
|
[ "vol", cmd ] -> queryVolume cmd
|
||||||
[ "net" ] -> queryNet
|
[ "net", cmd ] -> queryNet cmd
|
||||||
[ "date" ] -> queryDate True
|
[ "date" ] -> queryDate True
|
||||||
[ "date-min" ] -> queryDate False
|
[ "date-min" ] -> queryDate False
|
||||||
_ -> usage
|
_ -> usage
|
||||||
|
|
|
@ -127,8 +127,8 @@ parseAcpiStdout = mapMaybe parseBatteryInfo . lines
|
||||||
fmtData :: [BatteryData] -> String
|
fmtData :: [BatteryData] -> String
|
||||||
fmtData = (separator ++ ) . intercalate separator . map getStatus
|
fmtData = (separator ++ ) . intercalate separator . map getStatus
|
||||||
|
|
||||||
runAcpi :: IO String
|
runAcpi :: String -> IO String
|
||||||
runAcpi = readProcess "acpi" ["-b"] ""
|
runAcpi cmd = readProcess cmd ["-b"] ""
|
||||||
|
|
||||||
queryBattery :: IO String
|
queryBattery :: String -> IO String
|
||||||
queryBattery = fmtData . parseAcpiStdout <$> runAcpi
|
queryBattery cmd = fmtData . parseAcpiStdout <$> runAcpi cmd
|
||||||
|
|
|
@ -29,23 +29,23 @@ icons = M.map buildIcon $ M.fromList
|
||||||
offline :: String
|
offline :: String
|
||||||
offline = colorize (colors M.! "inactive") (icons M.! "wifi-off")
|
offline = colorize (colors M.! "inactive") (icons M.! "wifi-off")
|
||||||
|
|
||||||
getConnectivity :: IO String
|
getConnectivity :: String -> IO String
|
||||||
getConnectivity = head . lines <$> readProcess "nmcli" args ""
|
getConnectivity cmd = head . lines <$> readProcess cmd args ""
|
||||||
where args = ["networking", "connectivity", "check"]
|
where args = ["networking", "connectivity", "check"]
|
||||||
|
|
||||||
getDevStatus :: IO [DeviceData]
|
getDevStatus :: String -> IO [DeviceData]
|
||||||
getDevStatus = readProcess "nmcli" args "" >>= mapM buildDeviceData . lines
|
getDevStatus cmd = readProcess cmd args "" >>= mapM (buildDeviceData cmd) . lines
|
||||||
where
|
where
|
||||||
args = ["--terse", "--fields", "device,type,state", "device", "status"]
|
args = ["--terse", "--fields", "device,type,state", "device", "status"]
|
||||||
|
|
||||||
buildDeviceData :: String -> IO DeviceData
|
buildDeviceData :: String -> String -> IO DeviceData
|
||||||
buildDeviceData x =
|
buildDeviceData cmd x =
|
||||||
let
|
let
|
||||||
[d,t,state] = splitOn ":" x
|
[d,t,state] = splitOn ":" x
|
||||||
deviceType = readDeviceType t
|
deviceType = readDeviceType t
|
||||||
connected = state == "connected"
|
connected = state == "connected"
|
||||||
in do
|
in do
|
||||||
signal <- getWifiSignal deviceType d
|
signal <- getWifiSignal cmd deviceType d
|
||||||
return DeviceData
|
return DeviceData
|
||||||
{ deviceName = d
|
{ deviceName = d
|
||||||
, deviceType = deviceType
|
, deviceType = deviceType
|
||||||
|
@ -58,8 +58,8 @@ readDeviceType "wifi" = Wifi
|
||||||
readDeviceType "ethernet" = Ethernet
|
readDeviceType "ethernet" = Ethernet
|
||||||
readDeviceType _ = OtherDevice
|
readDeviceType _ = OtherDevice
|
||||||
|
|
||||||
getWifiSignal :: DeviceType -> String -> IO (Maybe Int)
|
getWifiSignal :: String -> DeviceType -> String -> IO (Maybe Int)
|
||||||
getWifiSignal Wifi dev = parseStdout <$> readProcess "nmcli" args ""
|
getWifiSignal cmd Wifi dev = parseStdout <$> readProcess cmd args ""
|
||||||
where
|
where
|
||||||
args =
|
args =
|
||||||
[ "--terse"
|
[ "--terse"
|
||||||
|
@ -71,10 +71,10 @@ getWifiSignal Wifi dev = parseStdout <$> readProcess "nmcli" args ""
|
||||||
isActive = (=="*") . head . splt
|
isActive = (=="*") . head . splt
|
||||||
readVal = read . (!! 1) . splt
|
readVal = read . (!! 1) . splt
|
||||||
parseStdout = fmap readVal . find isActive . lines
|
parseStdout = fmap readVal . find isActive . lines
|
||||||
getWifiSignal _ _ = return Nothing
|
getWifiSignal _ _ _ = return Nothing
|
||||||
|
|
||||||
getActiveDevs :: IO [DeviceData]
|
getActiveDevs :: String -> IO [DeviceData]
|
||||||
getActiveDevs = filter activeDev <$> getDevStatus
|
getActiveDevs cmd = filter activeDev <$> getDevStatus cmd
|
||||||
where
|
where
|
||||||
activeDev :: DeviceData -> Bool
|
activeDev :: DeviceData -> Bool
|
||||||
activeDev DeviceData { deviceType = Wifi, connected = True } = True
|
activeDev DeviceData { deviceType = Wifi, connected = True } = True
|
||||||
|
@ -114,11 +114,11 @@ getStatus :: [DeviceData] -> String
|
||||||
getStatus = intercalate separator . map makeDevIcon
|
getStatus = intercalate separator . map makeDevIcon
|
||||||
|
|
||||||
|
|
||||||
queryNet :: IO String
|
queryNet :: String -> IO String
|
||||||
queryNet = do
|
queryNet cmd = do
|
||||||
connectivity <- getConnectivity
|
connectivity <- getConnectivity cmd
|
||||||
--icon <- if connectivity `elem` ["none", "limited"]
|
--icon <- if connectivity `elem` ["none", "limited"]
|
||||||
icon <- if connectivity == "none"
|
icon <- if connectivity == "none"
|
||||||
then return offline
|
then return offline
|
||||||
else getStatus <$> getActiveDevs
|
else getStatus <$> getActiveDevs cmd
|
||||||
return $ separator ++ icon
|
return $ separator ++ icon
|
||||||
|
|
|
@ -76,24 +76,24 @@ parseMixerInfo = fmap fmtMixer . matchRegex regex
|
||||||
fmtData :: MixerData -> String
|
fmtData :: MixerData -> String
|
||||||
fmtData = (separator ++ ) . getStatus
|
fmtData = (separator ++ ) . getStatus
|
||||||
|
|
||||||
getMute :: IO Bool
|
getMute :: String -> IO Bool
|
||||||
getMute = parseMute <$> readProcess "/nix/store/ambq4n07zlax0lwz0v1yph85cph1sssk-pamixer-1.4/bin/pamixer" ["--get-mute"] ""
|
getMute cmd = parseMute <$> readProcess cmd ["--get-mute"] ""
|
||||||
where
|
where
|
||||||
parseMute "true" = True
|
parseMute "true" = True
|
||||||
parseMute "false" = False
|
parseMute "false" = False
|
||||||
parseMute _ = False
|
parseMute _ = False
|
||||||
|
|
||||||
getVol :: IO Int
|
getVol :: String -> IO Int
|
||||||
getVol = parseVol <$> readProcess "pamixer" ["--get-volume"] ""
|
getVol cmd = parseVol <$> readProcess cmd ["--get-volume"] ""
|
||||||
where
|
where
|
||||||
parseVol x = case readMaybe x of (Just vol) -> vol
|
parseVol x = case readMaybe x of (Just vol) -> vol
|
||||||
Nothing -> 0
|
Nothing -> 0
|
||||||
|
|
||||||
getInfo :: IO MixerData
|
getInfo :: String -> IO MixerData
|
||||||
getInfo = do
|
getInfo cmd = do
|
||||||
mute <- getMute
|
mute <- getMute cmd
|
||||||
vol <- getVol
|
vol <- getVol cmd
|
||||||
return $ MixerData { mute = mute, vol = vol }
|
return $ MixerData { mute = mute, vol = vol }
|
||||||
|
|
||||||
queryVolume :: IO String
|
queryVolume :: String -> IO String
|
||||||
queryVolume = fmtData <$> getInfo
|
queryVolume cmd = fmtData <$> getInfo cmd
|
||||||
|
|
Loading…
Reference in New Issue