aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/RemovePath.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-02-14 03:11:33 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-02-14 03:11:33 +0300
commit16fca4f16f23364a1441c17ea023bc9744b286c0 (patch)
treef0b2dc1c5504451a46475578f233d01a5e01315c /RemovePath.hs
parentstrip extra whitespace (diff)
downloadwindows-env-16fca4f16f23364a1441c17ea023bc9744b286c0.tar.gz
windows-env-16fca4f16f23364a1441c17ea023bc9744b286c0.zip
allow adding/removing multiple paths at once
Diffstat (limited to '')
-rw-r--r--RemovePath.hs30
1 files changed, 13 insertions, 17 deletions
diff --git a/RemovePath.hs b/RemovePath.hs
index 5fd6d6d..2e8fd01 100644
--- a/RemovePath.hs
+++ b/RemovePath.hs
@@ -20,27 +20,23 @@ main = do
case getOpt Permute optionDescription rawArgs of
(actions, args, []) -> do
options <- foldl (>>=) (return defaultOptions) actions
- case args of
- [path] -> removePath path options
- _ -> invalidNumberOfArguments
+ removePath args options
(_, _, errorMessages) -> exitWithUsageErrors errorMessages
-removePath :: String -> Options -> IO ()
-removePath path options = do
+removePath :: [String] -> Options -> IO ()
+removePath paths options = do
let varName = name options
userVal <- EnvUtils.queryFromRegistry EnvUtils.CurrentUserEnvironment varName
let userValParts = EnvUtils.splitPaths userVal
- if path `elem` userValParts
- then do
- let newUserValParts = filter (/= path) userValParts
- EnvUtils.saveToRegistryWithPrompt EnvUtils.CurrentUserEnvironment varName $ EnvUtils.joinPaths newUserValParts
- else do
- when (global options) $ do
- globalVal <- EnvUtils.queryFromRegistry EnvUtils.AllUsersEnvironment varName
- let globalValParts = EnvUtils.splitPaths globalVal
- when (path `elem` globalValParts) $ do
- let newGlobalValParts = filter (/= path) globalValParts
- EnvUtils.saveToRegistryWithPrompt EnvUtils.AllUsersEnvironment varName $ EnvUtils.joinPaths newGlobalValParts
+ let newUserValParts = filter (`notElem` paths) userValParts
+ when (length userValParts /= length newUserValParts) $ do
+ EnvUtils.saveToRegistryWithPrompt EnvUtils.CurrentUserEnvironment varName $ EnvUtils.joinPaths newUserValParts
+ when (global options) $ do
+ globalVal <- EnvUtils.queryFromRegistry EnvUtils.AllUsersEnvironment varName
+ let globalValParts = EnvUtils.splitPaths globalVal
+ let newGlobalValParts = filter (`notElem` paths) globalValParts
+ when (length globalValParts /= length newGlobalValParts) $ do
+ EnvUtils.saveToRegistryWithPrompt EnvUtils.AllUsersEnvironment varName $ EnvUtils.joinPaths newGlobalValParts
data Options = Options { name :: String
, global :: Bool }
@@ -58,7 +54,7 @@ buildHelpMessage = do
buildHeader :: IO String
buildHeader = do
progName <- getProgName
- return $ "Usage: " ++ progName ++ " [OPTIONS...] PATH\nOptions:"
+ return $ "Usage: " ++ progName ++ " [OPTIONS...] [PATH...]\nOptions:"
exitWithHelpMessage :: a -> IO b
exitWithHelpMessage _ = do