summaryrefslogtreecommitdiffhomepage
path: root/Main.hs
diff options
context:
space:
mode:
authorKrzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com>2007-07-05 18:03:20 +0200
committerKrzysztof Kosciuszkiewicz <k.kosciuszkiewicz@gmail.com>2007-07-05 18:03:20 +0200
commit8453821a99a4a211b2c489f1a90fa1ecea8a690d (patch)
tree5cefd95f9873198b530c7c22d5290bd93bf87547 /Main.hs
parentd41cd30ddef7ffd26ea0c799d734b703a6fb21db (diff)
downloadxmobar-8453821a99a4a211b2c489f1a90fa1ecea8a690d.tar.gz
xmobar-8453821a99a4a211b2c489f1a90fa1ecea8a690d.tar.bz2
Read default configuration from ~/.xmobarrc
I am not sure if handling of other exceptions is acceptable, the assumption is that failure to read ~/.xmobarrc because of other errors than parsing should not blow up the whole program. Otherwise explicit test for file existence would be required etc. darcs-hash:20070705160320-ba08c-fb91db4583071f14d94eb5f2a25c92c7f1bfb7e3.gz
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/Main.hs b/Main.hs
index ca2b92f..6f4a0ee 100644
--- a/Main.hs
+++ b/Main.hs
@@ -22,6 +22,7 @@ import XMobar
import Parsers
import Config
import System.Environment
+import System.IO.Error
-- $main
@@ -29,11 +30,9 @@ import System.Environment
main :: IO ()
main =
do args <- getArgs
- config <-
- if length args /= 1
- then do putStrLn ("No configuration file specified. Using default settings.")
- return defaultConfig
- else readConfig (args!!0)
+ config <- case args of
+ [cfgfile] -> readConfig cfgfile
+ _ -> readDefaultConfig
cl <- parseTemplate config (template config)
var <- execCommands config cl
(d,w) <- createWin config
@@ -48,4 +47,11 @@ readConfig f =
[] -> error ("Corrupt config file: " ++ f)
_ -> error ("Some problem occured. Aborting...")
+-- | Read default configuration or quit with an error
+readDefaultConfig :: IO Config
+readDefaultConfig =
+ do home <- getEnv "HOME"
+ let path = home ++ "/.xmobarrc"
+ catch (readConfig path)
+ (\e -> if isUserError e then ioError e else return defaultConfig)