Created
July 12, 2011 19:27
-
-
Save xfire/1078773 to your computer and use it in GitHub Desktop.
xmobar util to read temperature on lenovo notebooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- xmobar util to read temperature on lenovo notebooks | |
- | |
- usage: | |
- , Run Com "/home/fire/.xmonad/ibm_temp" ["40", "#B6B4B8", "red"] "temp" 10 | |
-} | |
import System( getArgs ) | |
import Data.Maybe | |
import Control.Monad | |
import Control.Applicative | |
stripPrefix s = let (_:r) = snd $ break (== '\t') s in r | |
stripPostfix s = fst $ break (== ' ') s | |
colorize max normal high s = "<fc=" ++ (color $ read s) ++ ">" ++ s ++ "</fc>" | |
where color x | x < max = normal | |
| otherwise = high | |
initArgs :: [String] -> [String] -> [String] | |
initArgs ds as = catMaybes $ zipWith mplus (m as) (m ds) | |
where m xs = (Just <$> xs) ++ repeat Nothing | |
-- > ibm_temp high_temperature normal_color high_color | |
-- defaults: 40 white red | |
main = do | |
args <- getArgs | |
f <- readFile "/proc/acpi/ibm/thermal" | |
let params = initArgs ["40", "white", "red"] args | |
let max = read (params !! 0) :: Int | |
let normal = params !! 1 | |
let high = params !! 2 | |
putStrLn ((colorize max normal high) . stripPostfix . stripPrefix $ f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment