diff options
author | jao <jao@gnu.org> | 2018-11-21 23:51:41 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2018-11-21 23:51:41 +0000 |
commit | 50134d5b5c4baabdfb35c0aeb8bf53d29f009c4d (patch) | |
tree | a710ee9a8e9ea9e46951d371af29081e1c72f502 /src/Xmobar/Environment.hs | |
parent | 7674145b878fd315999558075edcfc5e09bdd91c (diff) | |
download | xmobar-50134d5b5c4baabdfb35c0aeb8bf53d29f009c4d.tar.gz xmobar-50134d5b5c4baabdfb35c0aeb8bf53d29f009c4d.tar.bz2 |
All sources moved inside src
Diffstat (limited to 'src/Xmobar/Environment.hs')
-rw-r--r-- | src/Xmobar/Environment.hs | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/src/Xmobar/Environment.hs b/src/Xmobar/Environment.hs deleted file mode 100644 index 8a9223a..0000000 --- a/src/Xmobar/Environment.hs +++ /dev/null @@ -1,49 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : XMobar.Environment --- Copyright : (c) William Song --- License : BSD-style (see LICENSE) --- --- Maintainer : Will Song <incertia@incertia.net> --- Stability : stable --- Portability : portable --- --- A function to expand environment variables in strings --- ------------------------------------------------------------------------------ -module Xmobar.Environment(expandEnv) where - -import Control.Applicative ((<$>)) -import Data.Maybe (fromMaybe) -import System.Environment (lookupEnv) - -expandEnv :: String -> IO String -expandEnv "" = return "" -expandEnv (c:s) = case c of - '$' -> do - envVar <- fromMaybe "" <$> lookupEnv e - remainder <- expandEnv s' - return $ envVar ++ remainder - where (e, s') = getVar s - getVar "" = ("", "") - getVar ('{':s'') = (takeUntil "}" s'', drop 1 . dropUntil "}" $ s'') - getVar s'' = (takeUntil filterstr s'', dropUntil filterstr s'') - filterstr = ",./? \t;:\"'~`!@#$%^&*()<>-+=\\|" - takeUntil f = takeWhile (not . flip elem f) - dropUntil f = dropWhile (not . flip elem f) - - '\\' -> case s == "" of - True -> return "\\" - False -> do - remainder <- expandEnv $ drop 1 s - return $ escString s ++ remainder - where escString s' = let (cc:_) = s' in - case cc of - 't' -> "\t" - 'n' -> "\n" - '$' -> "$" - _ -> [cc] - - _ -> do - remainder <- expandEnv s - return $ c : remainder |