aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-06-12 03:35:31 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-06-12 03:41:16 +0300
commit37489c93248e5197f9b84b58c07680c9cb273189 (patch)
tree4d40a1d3f818f7105573a682e8319be0aec1d1bf /app
parentdelpath: don't do anything if variable is missing (diff)
downloadwindows-env-37489c93248e5197f9b84b58c07680c9cb273189.tar.gz
windows-env-37489c93248e5197f9b84b58c07680c9cb273189.zip
addpath: fix a sleep-deprived bug
Yeah, so last night I added a Show instance to WindowsEnv.Value (ex-WindowsEnv.VarValue), which would simply call valueString (ex-varValueString). Then I replaced every valueString/varValueString with show. Then I decided that this Show instance was a mistake, and derived an instance instead. It obviously messed up all the show VarValue/Value calls. The lesson to learn is you should remove an instance first, fix all the call sites, and only then derive it. The disgusting part is that a few of the last commits are actually broken, which I hate.
Diffstat (limited to 'app')
-rw-r--r--app/AddPath.hs16
1 files changed, 9 insertions, 7 deletions
diff --git a/app/AddPath.hs b/app/AddPath.hs
index d141270..1152df6 100644
--- a/app/AddPath.hs
+++ b/app/AddPath.hs
@@ -63,14 +63,13 @@ addPath options = runExceptT doAddPath >>= either ioError return
where
varName = optName options
pathsToAdd = nub $ optPaths options
-
forAllUsers = optGlobal options
+ skipPrompt = optYes options
+
profile
| forAllUsers = WindowsEnv.AllUsers
| otherwise = WindowsEnv.CurrentUser
- skipPrompt = optYes options
-
prepend = optPrepend options
mergePaths old new
| prepend = new ++ old
@@ -88,10 +87,13 @@ addPath options = runExceptT doAddPath >>= either ioError return
doAddPath = do
oldValue <- WindowsEnv.query profile varName `catchE` emptyIfMissing
- let oldPaths = WindowsEnv.pathSplit $ show oldValue
- let newPaths = pathsToAdd \\ oldPaths
- unless (null newPaths) $ do
- let newValue = WindowsEnv.Value (WindowsEnv.valueExpandable oldValue) $ WindowsEnv.pathJoin (mergePaths oldPaths newPaths)
+ let expandable = WindowsEnv.valueExpandable oldValue
+ let joined = WindowsEnv.valueString oldValue
+ let split = WindowsEnv.pathSplit joined
+ let missing = pathsToAdd \\ split
+ unless (null missing) $ do
+ let merged = mergePaths split missing
+ let newValue = WindowsEnv.Value expandable (WindowsEnv.pathJoin merged)
promptAndEngrave oldValue newValue
promptAndEngrave oldValue newValue = do