diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-11 21:41:08 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-12-11 21:41:08 +0100 |
commit | 4b26940ed310b9d7119eaf83c18526eb5ec38cd5 (patch) | |
tree | 2f9be0ff20806b9330d2125cbeae9afac5101cd3 /Plugins/Utils.hs | |
parent | 643b9235844d730aa9f0340da2a290a3c42bbccc (diff) | |
download | xmobar-4b26940ed310b9d7119eaf83c18526eb5ec38cd5.tar.gz xmobar-4b26940ed310b9d7119eaf83c18526eb5ec38cd5.tar.bz2 |
MBox: support for ~ paths and skipping non-existing mboxes
Diffstat (limited to 'Plugins/Utils.hs')
-rw-r--r-- | Plugins/Utils.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Plugins/Utils.hs b/Plugins/Utils.hs new file mode 100644 index 0000000..1dbcd40 --- /dev/null +++ b/Plugins/Utils.hs @@ -0,0 +1,39 @@ +------------------------------------------------------------------------------ +-- | +-- 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 Plugins.Utils (expandHome, changeLoop) 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) |