Kurt McKee

lessons learned in production

Archive

Fixing a missing Python REPL history

Posted 22 June 2022 in dotfiles, python, and windows

I've used advanced console managers for Windows for a long time, including ConsoleZ and ConEmu. I eventually tried -- and am currently using -- Windows Terminal with Powershell as the actual shell program. It's been great to get off of cmd.exe, but I noticed a problem: Python's REPL was no longer tracking my command history. The history of everything I typed was lost as soon as I exited the REPL!

I finally researched the problem and found that a Windows registry key needed to be updated. There's two ways to do that:

  1. Open cmd.exe, right-click on the title bar, select "Defaults", and in the "Options" tab, change the "Number of Buffers" to a bigger number, like 10.

    A cropped screenshot showing the number of buffers option increased to 10.
  2. Edit the registry and change the HKCU/Console/NumberOfHistoryBuffers value to 10.

Making this change fixed the problem, but I permanently captured this fix by adding a registry file to my dotfiles repository and updated my Windows-specific dotbot configuration to always import that registry file.

My dotfiles directory

dotfiles/
│   dotbot-windows.yaml
│
└── windows/
        increase-number-of-history-buffers.reg

dotbot-windows.yaml

- shell:
    -   description: "Increase the number of history buffers"
        command: "reg import windows/increase-number-of-history-buffers.reg"

increase-number-of-history-buffers.reg

Windows Registry Editor Version 5.00

; Increase the number of history buffers to 10.
;
; On Windows 10, using Powershell in Windows Terminal,
; the default number of history buffers (4) is insufficient,
; and Python's REPL cannot track its command history.
;
; Increasing the number of history buffers fixes this problem.
;

[HKEY_CURRENT_USER\Console]
"NumberOfHistoryBuffers"=dword:0000000a

Problem permanently solved!

☕ Like my work? I accept tips!