Skip to content

Commit

Permalink
Use XDG directories for user configuration and user data files
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael D. Adams committed Oct 2, 2016
1 parent 59287a7 commit b64f876
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/Idris/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Idris.Info
, getIdrisCC
, getIdrisVersion
, getIdrisVersionNoGit
, getIdrisUserConfigDir
, getIdrisUserDataDir
, getIdrisInitScript
, getIdrisHistoryFile
Expand Down Expand Up @@ -68,9 +69,13 @@ getIdrisVersion = showVersion S.version ++ suffix
getIdrisVersionNoGit = S.version


-- | Get the platform-specific, user-specific Idris dir
-- | Get the platform-specific, user-specific Idris configuration dir
getIdrisUserConfigDir :: IO FilePath
getIdrisUserConfigDir = getXdgDirectory XdgConfig "idris"

-- | Get the platform-specific, user-specific Idris data dir
getIdrisUserDataDir :: IO FilePath
getIdrisUserDataDir = getAppUserDataDirectory "idris"
getIdrisUserDataDir = getXdgDirectory XdgData "idris"

-- | Locate the platform-specific location for the init script
getIdrisInitScript :: IO FilePath
Expand Down
4 changes: 3 additions & 1 deletion src/Idris/Info/Show.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ showIdrisInfo = do

putStrLn "Paths:"
ldir <- getIdrisLibDir
cdir <- getIdrisUserConfigDir
udir <- getIdrisUserDataDir
ddir <- getIdrisDocDir
idir <- getIdrisDataDir
Expand All @@ -116,7 +117,8 @@ showIdrisInfo = do
putStrLn $ unwords ["-", "Library Dir:", ldir]
putStrLn $ unwords ["-", "C RTS Dir:", crdir]
putStrLn $ unwords ["-", "JS RTS Dir:", jrdir]
putStrLn $ unwords ["-", "User Dir:", udir]
putStrLn $ unwords ["-", "User Data Config:", cdir]
putStrLn $ unwords ["-", "User Data Dir:", udir]
putStrLn $ unwords ["-", "Documentation Dir:", ddir]

putStrLn "Flags:"
Expand Down
11 changes: 6 additions & 5 deletions src/Idris/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ idrisMain opts =
Just expr -> execScript expr

-- Create Idris data dir + repl history and config dir
idrisCatch (do dir <- runIO $ getIdrisUserDataDir
exists <- runIO $ doesDirectoryExist dir
unless exists $ logLvl 1 ("Creating " ++ dir)
runIO $ createDirectoryIfMissing True (dir </> "repl"))
(\e -> return ())
sequence_ $
[idrisCatch (do dir <- runIO $ getDir
exists <- runIO $ doesDirectoryExist dir
unless exists $ logLvl 1 ("Creating " ++ dir)
runIO $ createDirectoryIfMissing True (dir </> "repl"))
(\e -> return ()) | getDir <- [getIdrisUserConfigDir, getIdrisUserDataDir]]

historyFile <- runIO $ getIdrisHistoryFile

Expand Down

0 comments on commit b64f876

Please sign in to comment.