From 8453821a99a4a211b2c489f1a90fa1ecea8a690d Mon Sep 17 00:00:00 2001 From: Krzysztof Kosciuszkiewicz Date: Thu, 5 Jul 2007 18:03:20 +0200 Subject: 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 --- Main.hs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'Main.hs') 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) -- cgit v1.2.3