aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--apps/AddPath.hs18
-rw-r--r--apps/ListPaths.hs16
-rw-r--r--apps/PromptMessage.hs14
-rw-r--r--apps/RemovePath.hs18
-rw-r--r--apps/SetEnv.hs12
-rw-r--r--apps/UnsetEnv.hs10
-rw-r--r--src/WindowsEnv.hs16
-rw-r--r--windows-env.cabal2
8 files changed, 61 insertions, 45 deletions
diff --git a/apps/AddPath.hs b/apps/AddPath.hs
index 0439873..73d86d0 100644
--- a/apps/AddPath.hs
+++ b/apps/AddPath.hs
@@ -14,16 +14,16 @@ import System.IO.Error (ioError, isDoesNotExistError)
import Options.Applicative
-import qualified WindowsEnv.Environment as Env
+import qualified WindowsEnv
import Prompt
import PromptMessage
data Options = Options
- { optName :: Env.VarName
+ { optName :: WindowsEnv.VarName
, optYes :: Bool
, optGlobal :: Bool
- , optPaths :: [Env.VarValue]
+ , optPaths :: [WindowsEnv.VarValue]
} deriving (Eq, Show)
optionParser :: Parser Options
@@ -61,8 +61,8 @@ addPath options = runExceptT doAddPath >>= either ioError return
forAllUsers = optGlobal options
profile
- | forAllUsers = Env.AllUsers
- | otherwise = Env.CurrentUser
+ | forAllUsers = WindowsEnv.AllUsers
+ | otherwise = WindowsEnv.CurrentUser
skipPrompt = optYes options
@@ -71,13 +71,13 @@ addPath options = runExceptT doAddPath >>= either ioError return
| otherwise = throwE e
doAddPath = do
- oldValue <- Env.query profile varName `catchE` emptyIfMissing
- let oldPaths = Env.pathSplit oldValue
+ oldValue <- WindowsEnv.query profile varName `catchE` emptyIfMissing
+ let oldPaths = WindowsEnv.pathSplit oldValue
let newPaths = oldPaths `union` pathsToAdd
when (length oldPaths /= length newPaths) $ do
- let newValue = Env.pathJoin newPaths
+ let newValue = WindowsEnv.pathJoin newPaths
let promptAnd = if skipPrompt
then withoutPrompt
else withPrompt $ oldNewMessage profile varName oldValue newValue
- let engrave = Env.engrave profile varName newValue
+ let engrave = WindowsEnv.engrave profile varName newValue
void $ promptAnd engrave
diff --git a/apps/ListPaths.hs b/apps/ListPaths.hs
index 543599e..666423f 100644
--- a/apps/ListPaths.hs
+++ b/apps/ListPaths.hs
@@ -17,21 +17,21 @@ import System.IO.Error (ioError)
import Options.Applicative
-import qualified WindowsEnv.Environment as Env
+import qualified WindowsEnv
data WhichPaths = All | ExistingOnly | MissingOnly
deriving (Eq, Show)
-shouldListPath :: WhichPaths -> Env.VarValue -> IO Bool
+shouldListPath :: WhichPaths -> WindowsEnv.VarValue -> IO Bool
shouldListPath All = return . const True
shouldListPath ExistingOnly = doesDirectoryExist
shouldListPath MissingOnly = fmap not . doesDirectoryExist
-data Source = Environment | Registry Env.Profile
+data Source = Environment | Registry WindowsEnv.Profile
deriving (Eq, Show)
data Options = Options
- { optName :: Env.VarName
+ { optName :: WindowsEnv.VarName
, optWhichPaths :: WhichPaths
, optSource :: Source
} deriving (Eq, Show)
@@ -52,9 +52,9 @@ optionParser = Options
<|> flag' MissingOnly (long "missing" <> short 'm'
<> help "List missing paths only")
optSourceDesc = pure Environment
- <|> flag' (Registry Env.CurrentUser) (long "user" <> short 'u'
+ <|> flag' (Registry WindowsEnv.CurrentUser) (long "user" <> short 'u'
<> help "List current user's paths only")
- <|> flag' (Registry Env.AllUsers) (long "global" <> short 'g'
+ <|> flag' (Registry WindowsEnv.AllUsers) (long "global" <> short 'g'
<> help "List global (all users') paths only")
main :: IO ()
@@ -73,12 +73,12 @@ listPaths options = runExceptT doListPaths >>= either ioError return
query = queryFrom source
queryFrom Environment = lift $ fromMaybe "" <$> lookupEnv varName
- queryFrom (Registry profile) = Env.query profile varName
+ queryFrom (Registry profile) = WindowsEnv.query profile varName
filterPaths = filterM $ shouldListPath whichPaths
doListPaths = do
- paths <- Env.pathSplit <$> query
+ paths <- WindowsEnv.pathSplit <$> query
lift $ do
pathsToPrint <- filterPaths paths
mapM_ putStrLn pathsToPrint
diff --git a/apps/PromptMessage.hs b/apps/PromptMessage.hs
index f5afd71..8dd3ef5 100644
--- a/apps/PromptMessage.hs
+++ b/apps/PromptMessage.hs
@@ -13,27 +13,27 @@ module PromptMessage
import Text.Printf (printf)
-import qualified WindowsEnv.Environment as Env
+import qualified WindowsEnv
-oldNewMessage :: Env.Profile -> Env.VarName -> Env.VarValue -> Env.VarValue -> String
+oldNewMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> WindowsEnv.VarValue -> WindowsEnv.VarValue -> String
oldNewMessage profile name oldValue newValue =
descrMsg ++ oldValueMsg ++ newValueMsg
where
- profileKey = Env.profileKeyPath profile
+ profileKey = WindowsEnv.profileKeyPath profile
descrMsg = printf "Saving variable '%s' to '%s'...\n" name (show profileKey)
oldValueMsg = printf "\tOld value: %s\n" oldValue
newValueMsg = printf "\tNew value: %s\n" newValue
-newMessage :: Env.Profile -> Env.VarName -> Env.VarValue -> String
+newMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> WindowsEnv.VarValue -> String
newMessage profile name newValue =
descrMsg ++ newValueMsg
where
- profileKey = Env.profileKeyPath profile
+ profileKey = WindowsEnv.profileKeyPath profile
descrMsg = printf "Saving variable '%s' to '%s'...\n" name (show profileKey)
newValueMsg = printf "\tNew value: %s\n" newValue
-wipeMessage :: Env.Profile -> Env.VarName -> String
+wipeMessage :: WindowsEnv.Profile -> WindowsEnv.VarName -> String
wipeMessage profile name =
printf "Deleting variable '%s' from '%s'...\n" name (show profileKey)
where
- profileKey = Env.profileKeyPath profile
+ profileKey = WindowsEnv.profileKeyPath profile
diff --git a/apps/RemovePath.hs b/apps/RemovePath.hs
index 446b837..7d0c104 100644
--- a/apps/RemovePath.hs
+++ b/apps/RemovePath.hs
@@ -14,16 +14,16 @@ import System.IO.Error (ioError, isDoesNotExistError)
import Options.Applicative
-import qualified WindowsEnv.Environment as Env
+import qualified WindowsEnv
import Prompt
import PromptMessage
data Options = Options
- { optName :: Env.VarName
+ { optName :: WindowsEnv.VarName
, optYes :: Bool
, optGlobal :: Bool
- , optPaths :: [Env.VarValue]
+ , optPaths :: [WindowsEnv.VarValue]
} deriving (Eq, Show)
optionParser :: Parser Options
@@ -68,18 +68,18 @@ removePath options = runExceptT doRemovePath >>= either ioError return
| otherwise = throwE e
doRemovePath = do
- removePathFrom Env.CurrentUser
+ removePathFrom WindowsEnv.CurrentUser
when forAllUsers $
- removePathFrom Env.AllUsers
+ removePathFrom WindowsEnv.AllUsers
removePathFrom profile = do
- oldValue <- Env.query profile varName `catchE` emptyIfMissing
- let oldPaths = Env.pathSplit oldValue
+ oldValue <- WindowsEnv.query profile varName `catchE` emptyIfMissing
+ let oldPaths = WindowsEnv.pathSplit oldValue
let newPaths = oldPaths \\ pathsToRemove
when (length oldPaths /= length newPaths) $ do
- let newValue = Env.pathJoin newPaths
+ let newValue = WindowsEnv.pathJoin newPaths
let promptAnd = if skipPrompt
then withoutPrompt
else withPrompt $ oldNewMessage profile varName oldValue newValue
- let engrave = Env.engrave profile varName newValue
+ let engrave = WindowsEnv.engrave profile varName newValue
void $ promptAnd engrave
diff --git a/apps/SetEnv.hs b/apps/SetEnv.hs
index 6cf5d29..87d7812 100644
--- a/apps/SetEnv.hs
+++ b/apps/SetEnv.hs
@@ -13,7 +13,7 @@ import System.IO.Error (ioError)
import Options.Applicative
-import qualified WindowsEnv.Environment as Env
+import qualified WindowsEnv
import Prompt
import PromptMessage
@@ -21,8 +21,8 @@ import PromptMessage
data Options = Options
{ optYes :: Bool
, optGlobal :: Bool
- , optName :: Env.VarName
- , optValue :: Env.VarValue
+ , optName :: WindowsEnv.VarName
+ , optValue :: WindowsEnv.VarValue
} deriving (Eq, Show)
optionParser :: Parser Options
@@ -59,14 +59,14 @@ setEnv options = runExceptT doSetEnv >>= either ioError return
forAllUsers = optGlobal options
profile
- | forAllUsers = Env.AllUsers
- | otherwise = Env.CurrentUser
+ | forAllUsers = WindowsEnv.AllUsers
+ | otherwise = WindowsEnv.CurrentUser
skipPrompt = optYes options
promptAnd
| skipPrompt = withoutPrompt
| otherwise = withPrompt $ newMessage profile varName varValue
- engrave = Env.engraveForce profile varName varValue
+ engrave = WindowsEnv.engraveForce profile varName varValue
doSetEnv = void $ promptAnd engrave
diff --git a/apps/UnsetEnv.hs b/apps/UnsetEnv.hs
index 65f0c91..f60503b 100644
--- a/apps/UnsetEnv.hs
+++ b/apps/UnsetEnv.hs
@@ -13,7 +13,7 @@ import System.IO.Error (ioError)
import Options.Applicative
-import qualified WindowsEnv.Environment as Env
+import qualified WindowsEnv
import Prompt
import PromptMessage
@@ -21,7 +21,7 @@ import PromptMessage
data Options = Options
{ optYes :: Bool
, optGlobal :: Bool
- , optName :: Env.VarName
+ , optName :: WindowsEnv.VarName
} deriving (Eq, Show)
optionParser :: Parser Options
@@ -53,14 +53,14 @@ unsetEnv options = runExceptT doUnsetEnv >>= either ioError return
forAllUsers = optGlobal options
profile
- | forAllUsers = Env.AllUsers
- | otherwise = Env.CurrentUser
+ | forAllUsers = WindowsEnv.AllUsers
+ | otherwise = WindowsEnv.CurrentUser
skipPrompt = optYes options
promptAnd
| skipPrompt = withoutPrompt
| otherwise = withPrompt $ wipeMessage profile varName
- wipe = Env.wipe profile varName
+ wipe = WindowsEnv.wipe profile varName
doUnsetEnv = void $ promptAnd wipe
diff --git a/src/WindowsEnv.hs b/src/WindowsEnv.hs
new file mode 100644
index 0000000..e306507
--- /dev/null
+++ b/src/WindowsEnv.hs
@@ -0,0 +1,16 @@
+-- |
+-- Description : The convinience module to re-export public definitions
+-- Copyright : (c) 2015 Egor Tensin <Egor.Tensin@gmail.com>
+-- License : MIT
+-- Maintainer : Egor.Tensin@gmail.com
+-- Stability : experimental
+-- Portability : Windows-only
+--
+-- An empty module to re-export everything required by the packaged
+-- applications.
+
+module WindowsEnv (
+ module WindowsEnv.Environment
+ ) where
+
+import WindowsEnv.Environment
diff --git a/windows-env.cabal b/windows-env.cabal
index d452305..0d982c2 100644
--- a/windows-env.cabal
+++ b/windows-env.cabal
@@ -15,7 +15,7 @@ cabal-version: >=1.10
library
hs-source-dirs: src
- exposed-modules: WindowsEnv.Environment
+ exposed-modules: WindowsEnv, WindowsEnv.Environment
other-modules: WindowsEnv.Registry, WindowsEnv.Utils
ghc-options: -Wall -Werror
build-depends: base