Compare commits

..

2 Commits

Author SHA1 Message Date
Ricard Illa 165195cd96
default commands 2021-08-05 09:44:53 +02:00
Ricard Illa b58336c621
ignore exit code for pamixer 2021-08-05 09:42:23 +02:00
2 changed files with 11 additions and 3 deletions

View File

@ -9,15 +9,18 @@ import Monitors.Net (queryNet)
import Monitors.Volume (queryVolume)
usage :: IO String
usage = printf "%s bat | vol | net | date" <$> getProgName
usage = printf "%s bat (acpi_command) | vol (pamixer_command) | net (nmcli_command) | date" <$> getProgName
main :: IO ()
main = do
args <- getArgs
output <- case args of
[ "bat", cmd ] -> queryBattery cmd
[ "bat" ] -> queryBattery "acpi"
[ "vol", cmd ] -> queryVolume cmd
[ "vol" ] -> queryVolume "pamixer"
[ "net", cmd ] -> queryNet cmd
[ "net" ] -> queryNet "nmcli"
[ "date" ] -> queryDate True
[ "date-min" ] -> queryDate False
_ -> usage

View File

@ -76,15 +76,20 @@ parseMixerInfo = fmap fmtMixer . matchRegex regex
fmtData :: MixerData -> String
fmtData = (separator ++ ) . getStatus
readProcessIgnoreCode :: FilePath -> [String] -> String -> IO String
readProcessIgnoreCode cmd args stdin = do
(_,out,_) <- readProcessWithExitCode cmd args stdin
return out
getMute :: String -> IO Bool
getMute cmd = parseMute <$> readProcess cmd ["--get-mute"] ""
getMute cmd = parseMute <$> readProcessIgnoreCode cmd ["--get-mute"] ""
where
parseMute "true" = True
parseMute "false" = False
parseMute _ = False
getVol :: String -> IO Int
getVol cmd = parseVol <$> readProcess cmd ["--get-volume"] ""
getVol cmd = parseVol <$> readProcessIgnoreCode cmd ["--get-volume"] ""
where
parseVol x = case readMaybe x of (Just vol) -> vol
Nothing -> 0