diff options
author | jao <jao@gnu.org> | 2018-11-21 23:51:41 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2018-11-21 23:51:41 +0000 |
commit | 50134d5b5c4baabdfb35c0aeb8bf53d29f009c4d (patch) | |
tree | a710ee9a8e9ea9e46951d371af29081e1c72f502 /src/lib/Xmobar/Plugins/Utils.hs | |
parent | 7674145b878fd315999558075edcfc5e09bdd91c (diff) | |
download | xmobar-50134d5b5c4baabdfb35c0aeb8bf53d29f009c4d.tar.gz xmobar-50134d5b5c4baabdfb35c0aeb8bf53d29f009c4d.tar.bz2 |
All sources moved inside src
Diffstat (limited to 'src/lib/Xmobar/Plugins/Utils.hs')
-rw-r--r-- | src/lib/Xmobar/Plugins/Utils.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lib/Xmobar/Plugins/Utils.hs b/src/lib/Xmobar/Plugins/Utils.hs new file mode 100644 index 0000000..6546c15 --- /dev/null +++ b/src/lib/Xmobar/Plugins/Utils.hs @@ -0,0 +1,43 @@ +------------------------------------------------------------------------------ +-- | +-- Module: Plugins.Utils +-- Copyright: (c) 2010 Jose Antonio Ortega Ruiz +-- License: BSD3-style (see LICENSE) +-- +-- Maintainer: Jose A Ortega Ruiz <jao@gnu.org> +-- Stability: unstable +-- Portability: unportable +-- Created: Sat Dec 11, 2010 20:55 +-- +-- +-- Miscellaneous utility functions +-- +------------------------------------------------------------------------------ + + +module Xmobar.Plugins.Utils (expandHome, changeLoop, safeHead) where + +import Control.Monad +import Control.Concurrent.STM + +import System.Environment +import System.FilePath + + +expandHome :: FilePath -> IO FilePath +expandHome ('~':'/':path) = fmap (</> path) (getEnv "HOME") +expandHome p = return p + +changeLoop :: Eq a => STM a -> (a -> IO ()) -> IO () +changeLoop s f = atomically s >>= go + where + go old = do + f old + go =<< atomically (do + new <- s + guard (new /= old) + return new) + +safeHead :: [a] -> Maybe a +safeHead [] = Nothing +safeHead (x:_) = Just x |