-- Loads the appropriate .ghci file
-- (.ghci-9.0, .ghci-8.10, .ghci-8.8, .ghci-8.6, .ghci-8.2, .ghci-8.0)
--
:{
:def agda_load_ghci_by_version \varcmd ->
  let
    ghcVersion = Data.Version.versionBranch System.Info.compilerVersion
  in
    if (length ghcVersion /= 2)
    then return "putStrLn \"Strange GHC version…\""
    else if ghcVersion >= [9,0]
    then return ":script .ghci-9.0"
    else if ghcVersion >= [8,10]
    then return ":script .ghci-8.10"
    else if ghcVersion >= [8,8]
    then return ":script .ghci-8.8"
    else if ghcVersion >= [8,6]
    then return ":script .ghci-8.6"
    else if ghcVersion >= [8,2]
    then return ":script .ghci-8.2"
    else if ghcVersion >= [8,0]
    then return ":script .ghci-8.0"
    else return "putStrLn \"Unsupported GHC version\""
:}
:agda_load_ghci_by_version
:undef agda_load_ghci_by_version

-- Loads a ".ghci.local" file if it exists.
-- That file is gitignored, so you may edit it freely.
--
-- Put any local .ghci customizations there and they will not be overwritten
-- by checkouts, nor cause git to appear dirty. Some nice ideas for you which
-- may become defaults at some point in the future:
-- :set +c
-- :set -fdefer-out-of-scope-variables
-- :set -fdefer-type-errors
-- :set -fdefer-typed-holes
-- :set -ferror-spans
-- :set -fhelpful-errors
:{
:def agda_load_local_ghci \_ -> do
  let localGhci = ".ghci.local"
  exists <- System.Directory.doesFileExist localGhci
  return $ if exists
    then ":script " ++ localGhci
    else ""
:}
:agda_load_local_ghci
:undef agda_load_local_ghci
