Skip to content

A peer-to-peer stack for code collaboration

Fixed bug when using $HOME by default for config/cache paths (#97)

Luke Palmere8ae4e8fa396
diff --git a/package.yaml b/package.yaml
index 3999818..3049bb1 100644
--- a/package.yaml
+++ b/package.yaml
@@ -14,6 +14,7 @@ dependencies:
- aeson
- containers
- deriving-compat
+- directory
- haskeline
- megaparsec
- mtl
diff --git a/src/Radicle/Internal/CLI.hs b/src/Radicle/Internal/CLI.hs
index 4e5580b..388f69b 100644
--- a/src/Radicle/Internal/CLI.hs
+++ b/src/Radicle/Internal/CLI.hs
@@ -1,20 +1,16 @@
-module Radicle.Internal.CLI where
+module Radicle.Internal.CLI
+ ( getConfig
+ , getHistory
+ )
+where
import Protolude
-import System.Environment (lookupEnv)
+import System.Directory (XdgDirectory(..), getXdgDirectory)
-- | Uses XDG_CONFIG_HOME if available.
getConfig :: IO FilePath
-getConfig = do
- mCfgHome <- lookupEnv "XDG_CONFIG_HOME"
- pure $ case mCfgHome of
- Nothing -> "$HOME/.config/rad/config.rad"
- Just cfgHome -> cfgHome <> "/rad/config.rad"
+getConfig = getXdgDirectory XdgConfig "rad/config.rad"
-- | Uses XDG_CACHE_HOME if available.
getHistory :: IO FilePath
-getHistory = do
- mCfgHome <- lookupEnv "XDG_CACHE_HOME"
- pure $ case mCfgHome of
- Nothing -> "$HOME/.cache/rad/history"
- Just cfgHome -> cfgHome <> "/rad/history"
+getHistory = getXdgDirectory XdgData "rad/config.rad"