diff options
author | Ben Boeckel <mathstuf@gmail.com> | 2013-07-05 00:09:46 -0400 |
---|---|---|
committer | Ben Boeckel <mathstuf@gmail.com> | 2013-07-05 00:09:46 -0400 |
commit | 9fc6b376a58e83eecb33a55f88175a71e613aa25 (patch) | |
tree | 6a5c06e09cc2712f2c22d90016560e1a4565a97c /src | |
parent | 7b0d6bffd5c13234feb798604e01fa6a6f91ec6b (diff) | |
download | xmobar-9fc6b376a58e83eecb33a55f88175a71e613aa25.tar.gz xmobar-9fc6b376a58e83eecb33a55f88175a71e613aa25.tar.bz2 |
Implement XDG logic locally
Avoids an extra dependency.
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Main.hs b/src/Main.hs index aad2804..e90a158 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -32,9 +32,10 @@ import Paths_xmobar (version) import Data.Version (showVersion) import Graphics.X11.Xlib import System.Console.GetOpt +import System.Directory (getHomeDirectory) import System.Exit import System.Environment -import System.Environment.XDG.BaseDir +import System.FilePath ((</>)) import System.Posix.Files import Control.Monad (unless) @@ -89,10 +90,22 @@ readConfig f = do ": configuration file contains errors at:\n" ++ show err) return $ parseConfig s +xdgConfigDir :: IO String +xdgConfigDir = do env <- getEnvironment + case lookup "XDG_CONFIG_HOME" env of + Just val -> return val + Nothing -> getHomeDirectory >>= return . (</> ".config") + +xmobarConfigDir :: IO FilePath +xmobarConfigDir = xdgConfigDir >>= return . (</> "xmobar") + +getXdgConfigFile :: IO FilePath +getXdgConfigFile = xmobarConfigDir >>= return . (</> "xmobarrc") + -- | Read default configuration file or load the default config readDefaultConfig :: IO (Config,[String]) readDefaultConfig = do - xdgconf <- getUserDataFile "xmobar" "xmobarrc" + xdgconf <- getXdgConfigFile x <- io $ fileExist xdgconf home <- io $ getEnv "HOME" let path = home ++ "/.xmobarrc" |