18

By default, GHCi saves 100 lines of command history in ~/.ghc/ghci_history. Can I increase this number?

I'm using GHC 7.6.3 on GNU/Linux.

ntc2
  • 11,203
  • 7
  • 53
  • 70

2 Answers2

17

On my system (GNU/Linux, GHC 7.6.3), GHCi is built against the haskeline library. According to this document, it can be customised by editing the ~/.haskeline file:

maxhistorysize: Just 1000

Mikhail Glushenkov
  • 14,928
  • 3
  • 52
  • 65
  • Thanks! This worked for me. Strangely, I couldn't test it automatically, e.g. `{ seq 1 200 | xargs -n1 ; echo ':quit' } | ghci` doesn't save any history at all, and truncates the existing history file to 100 lines, regardless of the `maxhistorysize` setting. But, opening up ghci and mashing the keyboard for a while verified that the history file has grown above 100 lines :D – ntc2 Nov 22 '13 at 00:57
  • 3
    IIUC, haskeline [switches itself off automatically](http://hackage.haskell.org/package/haskeline-0.7.1.1/src/System/Console/Haskeline/InputT.hs) when `stdin` is a pipe. – Mikhail Glushenkov Nov 22 '13 at 01:10
  • Interesting. The docs for the `preferTerm` variable in the file indicate that one might be able to configure GHCi to save history even when reading from a pipe. Of course, I don't have any use for that besides my stupid test :P – ntc2 Nov 22 '13 at 01:17
  • This also works on Windows. Just put the line above in `C:\Users\YourName\.hakeline`. – Hjulle May 27 '17 at 09:02
  • 1000 seems very conservative, especially with hard drives being so cheap... Thanks! – jpaugh Nov 10 '17 at 03:34
4

As discussed this is the solution for Mac OSX, the other answer is for Linux. I found what your looking for here basically copy pasting the relevant information and formatting it below here.

The default is a history of 100 commands but you can change that by adding this line to your ~/.ghc/ghci.conf:

System.Console.Editline.Readline.stifleHistory 1000

which would increase your history to 1000 commands.

pyCthon
  • 11,746
  • 20
  • 73
  • 135
  • This does not work on my system, I think because my GHCi is using `readline` and your trick is for `editline`. The module `System.Console.Editline.Readline` is not installed, and trying to install it with `cabal install editline` gives a compile error, because editline is not installed. Installing the editline lib with `sudo aptitude install libeditline-dev` does not help. – ntc2 Nov 21 '13 at 23:13
  • There is a [Haskell Readline lib](http://hackage.haskell.org/package/readline-1.0.3.0/docs/System-Console-Readline.html), but I can't find a "amount of saved history" command there. – ntc2 Nov 21 '13 at 23:20
  • @ntc2 interesting! now we know the mac solution and the linux solution! – pyCthon Nov 22 '13 at 02:54