Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Windows consoles lose command-line history (up arrow) after a time?

It seems random: after some amount of time / usage of any console I use on Windows Vista, I lose the ability to use the command-line history (or command buffer, if you prefer...), and hitting the up or down arrow no longer does anything at all, meaning there are essentially 0 items available in the history.

I've seen this behavior in Cygwin, CMD, and PowerShell.

Sometimes this behavior applies to processes running inside the console - Python, MySQL client, etc.

Is this an inherent problem in Windows? A setting somewhere? Are there other consoles that don't have this problem?

ps - if you think this is non-programming related, please see other questions regarding programming tools, for instance, nearly anything tagged "eclipse" which deal with how to use the IDE rather than programming for it.

like image 625
wsorenson Avatar asked Aug 06 '09 21:08

wsorenson


People also ask

Does Command Prompt keep history?

Unlike the Linux console, command history is only available for the current session. If you close Command Prompt, it will also clear the history, but you can the doskey command to save the history of the commands you typed to a file.

How do I get Command Prompt history?

Open the Start menu and type cmd in the search bar. Right-click on the Command Prompt app and select Run as Administrator to proceed. Type the command doskey /h > c:\cmd_history. txt and press Enter.

What does the up arrow do at the Command Prompt?

To access previous commands, simply press the up arrow. This will give you the last command you typed in. Pressing it again will produce the command before that, and so on.

Is Command Prompt going away?

Command Prompt in Windows 11 to be replaced by Windows Terminal as the default experience. Windows Terminal was unveiled in 2019, and after a year in preview phase, it was released as an open source tool in 2020. Microsoft has announced that the Command Prompt in Windows 11 will be replaced by Windows Terminal.


1 Answers

Two ways, I think.

1) Far Manager is a good choice for a shell. Even if you don't need it's all power (file/archive management, editor, huge number of plugins, macros), you can use it as a wrapper/executor for cmd, tcc, sh or any other program, shell or command processor.

For example

  • take 3 files from distrib (Far2 or Far3): far.exe, fareng.lng and (optionally) fareng.hlp
  • run "far.exe /w", press Ctrl+B Ctrl+O
  • type any command in command line: dir, set, notepad, putty, an so on...

History will be preserved between sessions, you may access it by Alt+F8 (press Ctrl+Alt+F to switch history into filter mode).

Far 2.0 stores history (and settings) in the registry.

Far 3.0 stores history in SQLite database, and may be portable.

Also, Far can autocomplete commands from history or files/paths from disk. And there is plugin (YAC) which can autocomplete from aliases and so on...

2) I have found recently interesting project: Clink - Bringing Bash's powerful command line editing to Microsoft Windows' cmd.exe

  • Powerful Bash-like line editing from GNU's Readline library. Read more on Readline's keyboard shortcuts.
  • Superior path completion (TAB).
  • Paste from clipboard (Ctrl-V).
  • Support for the completion of executables/commands, and environment variables.
  • Undo/Redo (Ctrl-_ or Ctrl-X, Ctrl-U)
  • Improved command line history.
    • Persists across sessions.
    • Searchable (Ctrl-R and Ctrl-S).
    • History expansion (e.g. !!, !, and !$).
  • Scriptable completion using Lua.

It seems a young but budding project, so I had created an option for use it in my Console Emulator.

like image 99
Maximus Avatar answered Sep 22 '22 00:09

Maximus