Skip to content

Instantly share code, notes, and snippets.

@funrep
Created September 27, 2014 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funrep/179999d4917621ec26e3 to your computer and use it in GitHub Desktop.
Save funrep/179999d4917621ec26e3 to your computer and use it in GitHub Desktop.
My dwm statusbar
# statusbar
while true; do
xsetroot -name "$( statusbar )"
sleep 1m # Update time every minute
done &
# settings
xset -b
xrdb -merge ~/.XResources
xsetroot -solid "#002b36"
xsetroot -cursor_name left_ptr &
# startup programs
exec dwm
import Data.List
import System.Process
import System.Exit
run x y z = do
(err, s, _) <- readProcessWithExitCode x y z
case err of
ExitSuccess -> return s
_ -> return ""
main = do
battery <- run "/usr/bin/acpi" ["-b"] ""
temp <- run "/usr/bin/acpi" ["-t"] ""
date <- run "/bin/date" ["+\"%F %R\""] ""
-- volume <- run "/usr/bin/amixer" [] ""
network <- run "/usr/bin/wicd-cli" ["-y", "-d"] ""
let s = unwords [networkParse network, tempParse temp, batteryParse battery,
dateParse date]
putStrLn s
batteryParse :: String -> String
batteryParse s = let
s' = words s
in case find (== "Discharging,") s' of
Just s'' -> take 3 . head . tail $ dropWhile (/= s'') s'
Nothing -> "100%"
tempParse :: String -> String
tempParse s = let
s' = words s
in case find (== "ok,") s' of
Just s'' -> let
cpu1 = take 2 . head . tail $ dropWhile (/= s'') s'
cpu2 = take 2 . head . tail . dropWhile (/= s'') . tail $ dropWhile (/= s'') s'
in cpu1 ++ "°" ++ " " ++ cpu2 ++ "°"
Nothing -> "XX° YY°"
networkParse :: String -> String
networkParse s = let
s' = words s
in case find (== "Rates:") s' of
Just s'' -> let
s''' = take 2 . tail $ dropWhile (/= s'') s'
in unwords s'''
Nothing -> "5 Tb/s"
dateParse :: String -> String
dateParse = init . init . tail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment