Search code examples
haskellhaskell-stackghci

Can I persuade stack / ghci to *only* load the local .ghci file?


I have a .ghci in my local project directory, and another one in my $HOME. When I do a stack ghci, then $HOME/.ghci is loaded first, followed by $PWD/.ghci. Is it possible to have ONLY the local .ghci be loaded, and the global one ignored?

I could do a stack exec -- ghci -ignore-dot-ghci, but then, none is loaded.

What I also tried is:

stack exec -- ghci -ignore-dot-ghci -W .ghci

The idea being to first tell ghci not to load anything and then explicitly requesting the local .ghci file, but this gives the error message Warning: ignoring unrecognised input `.ghci'


Solution

  • GHCi has a -ghci-script flag which can be used alongside -ignore-dot-ghci. It can be used with stack ghci through --ghci-options:

    stack ghci --ghci-options "-ignore-dot-ghci -ghci-script .ghci"
    

    For the sake of completeness, here is the corresponding cabal repl invocation:

    cabal repl --repl-options "-ignore-dot-ghci" --repl-options "-ghci-script .ghci"