import System.Process (callProcess, readProcess)
import Control.Monad (when)

getWord :: Int -> String -> String
getWord n = init . (!!n) . words

main :: IO ()
main = do
  info <- readProcess "acpi" ["-b"] []
  let currentStatus  = getWord 2 info
  let percentageLeft = read $ init $ getWord 3 info
  when (currentStatus == "Discharging" && percentageLeft < 30)
    (callProcess "notify-send" ["Battery Low", "CONNECT YOUR CHARGER !!!"])
