aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-06-09 15:07:15 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-06-10 03:28:49 +0300
commitfe69c19646acf2ebdf52db7edc73cf02337db4de (patch)
treec5710fe3ad521e4f11191cf820db3a38b9723799 /app
parentadd comments to `foreign` imports (diff)
downloadwindows-env-fe69c19646acf2ebdf52db7edc73cf02337db4de.tar.gz
windows-env-fe69c19646acf2ebdf52db7edc73cf02337db4de.zip
paths: don't expand registry values
Diffstat (limited to 'app')
-rw-r--r--app/ListPaths.hs28
1 files changed, 22 insertions, 6 deletions
diff --git a/app/ListPaths.hs b/app/ListPaths.hs
index 666423f..5834f11 100644
--- a/app/ListPaths.hs
+++ b/app/ListPaths.hs
@@ -9,7 +9,7 @@ module Main (main) where
import Control.Monad (filterM)
import Control.Monad.Trans.Class (lift)
-import Control.Monad.Trans.Except (runExceptT)
+import Control.Monad.Trans.Except (ExceptT, runExceptT)
import Data.Maybe (fromMaybe)
import System.Directory (doesDirectoryExist)
import System.Environment (lookupEnv)
@@ -63,22 +63,38 @@ main = execParser parser >>= listPaths
parser = info (helper <*> optionParser) $
fullDesc <> progDesc "List directories in your PATH"
+data ExpandedPath = ExpandedPath
+ { pathOriginal :: WindowsEnv.VarValue
+ , pathExpanded :: WindowsEnv.VarValue
+ } deriving (Eq, Show)
+
+splitAndExpand :: WindowsEnv.VarValue -> ExceptT IOError IO [ExpandedPath]
+splitAndExpand pathValue = do
+ expandedOnce <- expandOnce
+ zipWith ExpandedPath originalPaths <$>
+ if length expandedOnce == length originalPaths
+ then return expandedOnce
+ else expandEach
+ where
+ originalPaths = WindowsEnv.pathSplit pathValue
+ expandOnce = WindowsEnv.pathSplit <$> WindowsEnv.expand pathValue
+ expandEach = mapM WindowsEnv.expand originalPaths
+
listPaths :: Options -> IO ()
listPaths options = runExceptT doListPaths >>= either ioError return
where
varName = optName options
whichPaths = optWhichPaths options
- source = optSource options
- query = queryFrom source
+ query = queryFrom $ optSource options
queryFrom Environment = lift $ fromMaybe "" <$> lookupEnv varName
queryFrom (Registry profile) = WindowsEnv.query profile varName
- filterPaths = filterM $ shouldListPath whichPaths
+ filterPaths = filterM (shouldListPath whichPaths . pathExpanded)
doListPaths = do
- paths <- WindowsEnv.pathSplit <$> query
+ paths <- query >>= splitAndExpand
lift $ do
pathsToPrint <- filterPaths paths
- mapM_ putStrLn pathsToPrint
+ mapM_ (putStrLn . pathOriginal) pathsToPrint