summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2010-12-11 14:11:09 -0500
committerBen Boeckel <MathStuf@gmail.com>2010-12-11 14:11:09 -0500
commitf61136d9649555c155bd5b3f570bf1269b98bc9a (patch)
treef16e94b260824f1485b49937d18b99b4854e772f
parent533d459b70774b3bbdab5dde1fcb442a579b36cc (diff)
downloadxmobar-f61136d9649555c155bd5b3f570bf1269b98bc9a.tar.gz
xmobar-f61136d9649555c155bd5b3f570bf1269b98bc9a.tar.bz2
Expand '~' in paths for mail directories
-rw-r--r--Plugins/Mail.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/Plugins/Mail.hs b/Plugins/Mail.hs
index 851fc5e..165467a 100644
--- a/Plugins/Mail.hs
+++ b/Plugins/Mail.hs
@@ -21,6 +21,7 @@ import Control.Monad
import Control.Concurrent.STM
import System.Directory
+import System.Environment
import System.FilePath
import System.INotify
@@ -37,9 +38,10 @@ instance Exec Mail where
vs <- mapM (const $ newTVarIO S.empty) ms
let ts = map fst ms
- ds = map ((</> "new") . snd) ms
+ rs = map ((</> "new") . snd) ms
ev = [Move, MoveIn, MoveOut, Create, Delete]
+ ds <- mapM expandHome rs
i <- initINotify
zipWithM_ (\d v -> addWatch i ev d (handle v)) ds vs
@@ -56,6 +58,10 @@ instance Exec Mail where
modifyTVar :: TVar a -> (a -> a) -> STM ()
modifyTVar v f = readTVar v >>= writeTVar v . f
+expandHome :: FilePath -> IO FilePath
+expandHome ('~':'/':path) = getEnv "HOME" >>= return . flip (</>) path
+expandHome p = return p
+
handle :: TVar (Set String) -> Event -> IO ()
handle v e = atomically $ modifyTVar v $ case e of
Created {} -> create