summaryrefslogtreecommitdiffhomepage
path: root/src/Environment.hs
diff options
context:
space:
mode:
authorPavan Rikhi <pavan.rikhi@gmail.com>2018-03-17 22:48:24 -0400
committerjao <jao@gnu.org>2018-11-21 21:41:35 +0000
commit4d1402a1a7d87767267d48a77998e4fb13395b31 (patch)
tree17fd6160dc1fa9c8a0676a94bcf8d19b551c655c /src/Environment.hs
parent9e2a5c7daddf683d4be7c318aefed3da3ea7a89a (diff)
downloadxmobar-4d1402a1a7d87767267d48a77998e4fb13395b31.tar.gz
xmobar-4d1402a1a7d87767267d48a77998e4fb13395b31.tar.bz2
Split Modules into Library & Executable Structure
Move the Main module to a new `app` directory. All other modules have been nested under the `Xmobar` name. Lots of module headers & imports were updated.
Diffstat (limited to 'src/Environment.hs')
-rw-r--r--src/Environment.hs49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/Environment.hs b/src/Environment.hs
deleted file mode 100644
index 1b7e48c..0000000
--- a/src/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 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