module Xmobar.App.Config (defaultConfig,
xmobarConfigDir,
xmobarDataDir,
xmobarConfigFile) where
import System.Environment
import System.Directory
import System.FilePath ((</>))
import System.Posix.Files (fileExist)
import Xmobar.Plugins.Date
import Xmobar.Plugins.StdinReader
import Xmobar.Config.Types
import Xmobar.Run.Runnable
defaultConfig :: Config
defaultConfig =
Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
, additionalFonts = []
, wmClass = "xmobar"
, wmName = "xmobar"
, bgColor = "#000000"
, fgColor = "#BFBFBF"
, alpha = 255
, position = Top
, border = NoBorder
, borderColor = "#BFBFBF"
, borderWidth = 1
, textOffset = -1
, iconOffset = -1
, textOffsets = []
, hideOnStart = False
, lowerOnStart = True
, persistent = False
, allDesktops = True
, overrideRedirect = True
, pickBroadest = False
, iconRoot = "."
, commands = [ Run $ Date "%a %b %_d %Y * %H:%M:%S" "theDate" 10
, Run StdinReader]
, sepChar = "%"
, alignSep = "}{"
, template = "%StdinReader% }{ " ++
"<fc=#00FF00>%uname%</fc> * <fc=#FF0000>%theDate%</fc>"
, verbose = False
}
xmobarConfigDir :: IO String
xmobarConfigDir =
findFirstDirWithEnv "XMOBAR_CONFIG_DIR"
[ getAppUserDataDirectory "xmobar"
, getXdgDirectory XdgConfig "xmobar"
]
xmobarDataDir :: IO String
xmobarDataDir =
findFirstDirWithEnv "XMOBAR_DATA_DIR"
[ getAppUserDataDirectory "xmobar"
, getXdgDirectory XdgData "xmobar"
]
findFirstDirOf :: [IO FilePath] -> IO FilePath
findFirstDirOf [] = findFirstDirOf [getAppUserDataDirectory "xmobar"]
findFirstDirOf possibles = do
found <- go possibles
case found of
Just path -> return path
Nothing -> do
primary <- head possibles
createDirectoryIfMissing True primary
return primary
where
go [] = return Nothing
go (x:xs) = do
exists <- x >>= doesDirectoryExist
if exists then x >>= return . Just else go xs
findFirstDirWithEnv :: String -> [IO FilePath] -> IO FilePath
findFirstDirWithEnv envName paths = do
envPath' <- lookupEnv envName
case envPath' of
Nothing -> findFirstDirOf paths
Just envPath -> findFirstDirOf (return envPath:paths)
xmobarConfigFile :: IO (Maybe FilePath)
xmobarConfigFile =
ffirst [ xdg "xmobar.hs", xdg "xmobarrc", home ".xmobarrc"]
where xdg p = fmap (</> p) xmobarConfigDir
home p = fmap (</> p) getHomeDirectory
ffirst [] = return Nothing
ffirst (f:fs) =
f >>= fileExist >>= \e -> if e then fmap Just f else ffirst fs