summaryrefslogtreecommitdiffhomepage
path: root/src/lib/Xmobar/Environment.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-11-25 03:49:15 +0000
committerjao <jao@gnu.org>2018-11-25 03:49:15 +0000
commit3852d6b5e354b9b03b30f04803a87b2224aeb85c (patch)
tree88213d8fd2e2c5454e3a9ba696ef644c16b8f71b /src/lib/Xmobar/Environment.hs
parent0691071716e6cfa6040044be0ca782771fe6104c (diff)
downloadxmobar-3852d6b5e354b9b03b30f04803a87b2224aeb85c.tar.gz
xmobar-3852d6b5e354b9b03b30f04803a87b2224aeb85c.tar.bz2
Xmobar.System.Environment
Diffstat (limited to 'src/lib/Xmobar/Environment.hs')
-rw-r--r--src/lib/Xmobar/Environment.hs49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/lib/Xmobar/Environment.hs b/src/lib/Xmobar/Environment.hs
deleted file mode 100644
index 8a9223a..0000000
--- a/src/lib/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