Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Remember Command History #6500

Closed
srana2000 opened this issue Jun 14, 2020 · 16 comments
Closed

Feature Request: Remember Command History #6500

srana2000 opened this issue Jun 14, 2020 · 16 comments
Labels
Needs-Tag-Fix Doesn't match tag requirements Resolution-Won't-Fix We're just really obstinate about this. There's probably a good reason.

Comments

@srana2000
Copy link

srana2000 commented Jun 14, 2020

Just like in Linux how can Terminal (for CMD.exe) remember the command line history across multiple instances. It is very frustrating to type commands again.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jun 14, 2020
@DHowett
Copy link
Member

DHowett commented Jun 14, 2020

This is the shell's job. PoweerShell and Bash (and zsh, fish, ...) already do this! The terminal can't do anything about shells that cannot save their history. Sorry!

@DHowett DHowett closed this as completed Jun 14, 2020
@DHowett DHowett added Resolution-External For issues that are outside this codebase and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jun 14, 2020
@mcgov
Copy link

mcgov commented Aug 6, 2020

This feature request should be re-enabled. This is a legitimate feature request. You can't think of a way to write a program which just remembers history and passes the commands to a cmd shell?

@zadjii-msft
Copy link
Member

@mcgov cmd.exe is very much in maintenance-only mode. If you'd like a shell that can remember command history across reboots, I recommend looking into powershell, zsh, yori, click, cmder, or pretty much any other shell.

@mcgov
Copy link

mcgov commented Aug 6, 2020

This is going to sound crazy but I'd like to have this feature in windows terminal

@zadjii-msft
Copy link
Member

I think there might be a bit of a misunderstanding here - there are two different kinds of applications we're talking about here:

  • shell applications, like cmd.exe, powershell, zsh, etc. These are text-only applications that emit streams of characters. They don't care at all about how they're eventually rendered to the user. These are also sometimes referred to as "commandline client" applications.
  • terminal applications, like the Windows Terminal, gnome-terminal, xterm, iterm2, hyper. These are graphical applications that can be used to render the output of commandline clients.

On Windows, if you just run cmd.exe directly, the OS will create an instance of conhost.exe as the terminal for cmd.exe. The same thing happens for powershell.exe, the system will creates a new conhost window for any client that's not already connected to a terminal of some sort. This has lead to an enormous amount of confusion for people thinking that a conhost window is actually a "cmd window". cmd can't have a window, it's just a commandline application. Its window is always some other terminal.

Any terminal can run any commandline client application. So you can use the Windows Terminal to run whatever shell you want. I use mine for both cmd and powershell, and also WSL:
image

It's not the Terminal's responsibility to remember the commands executed by a commandline client. That's the responsibility of the shell. How would the terminal remember commands executed by something like emacs or vim? Those are both applications where the user is typing input and hitting enter, like they would at a cmd prompt, but without something that resembles a command history.

@KalleOlaviNiemitalo
Copy link

You already have src/host/history.cpp and src/host/history.h, for programs like cmd.exe or netsh.exe that don't implement their own line editing. Surely it would be technically possible to make the console host save and restore this history, or extend the pseudoconsole channel to let WindowsTerminal.exe do it.

@DHowett
Copy link
Member

DHowett commented Aug 6, 2020

The console host maintaining an application’s history is an architectural mistake the likes of which we are not intending to make again.

@DHowett DHowett added Resolution-Won't-Fix We're just really obstinate about this. There's probably a good reason. and removed Resolution-External For issues that are outside this codebase labels Aug 6, 2020
@DHowett
Copy link
Member

DHowett commented Aug 6, 2020

That includes extending it in any way that would make it more enticing or more featureful such that an application would prefer to use it over its own line editing and history management.

We maintain that code because we have to, not because it was good or worthwhile.

@alibarut
Copy link

alibarut commented Dec 6, 2022

You can use https://mridgers.github.io/clink/

@NewtonChutney
Copy link

I daily drive pwsh, so I don't exactly need cmd's history but I'd like to see this bit of code in action..
Where is the feature toggle present? 😂

You already have src/host/history.cpp and src/host/history.h, for programs like cmd.exe or netsh.exe that don't implement their own line editing. Surely it would be technically possible to make the console host save and restore this history, or extend the pseudoconsole channel to let WindowsTerminal.exe do it.

@zadjii-msft
Copy link
Member

Sorry, still foggy from the holidays. Re:

Where is the feature toggle present? 😂

Could you elaborate? Which feature toggle?

@NewtonChutney
Copy link

@zadjii-msft, KalleOlaviNiemitalo had said:

You already have src/host/history.cpp and src/host/history.h, for programs like cmd.exe or netsh.exe that don't implement their own line editing. Surely it would be technically possible to make the console host save and restore this history, or extend the pseudoconsole channel to let WindowsTerminal.exe do it.

But I couldn't find references of this setting/toggle..
This just piqued my interest, and I wanted to see it in action.. 😅

@zadjii-msft
Copy link
Member

I mean, it's not really a "terminal" feature, so to speak. It's an artifact of the console API. If a console application enables ENABLE_PROCESSED_OUTPUT (e.g., cmd.exe, python.exe), then conhost itself (the console API server) will maintain an internal history of commands that were entered. This history is only in conhost's memory, and is lost when the console is closed. Other applications, like PowerShell, which might want a more elaborate line-editing experience than what conhost provides, disable that mode, and manage all input and history themselves.

@KalleOlaviNiemitalo
Copy link

@NewtonChutney if you run cmd.exe in conhost (with or without Windows Terminal), and type a few commands, then you can use the up and down arrow keys to revisit those commands; that uses the history feature that is implemented in those files. There is also some function key that pops up a menu based on this history; that is implemented in some other part of conhost. The console API can manipulate the history programmatically and IIRC the DOSKEY command uses those functions.

@NewtonChutney
Copy link

Ahhh, those files were related to session history.. Sorry for misinterpreting them as cross-session history handling.. ᓚᘏᗢ

@KalleOlaviNiemitalo
Copy link

IIUC, it would be possible to fork conhost from this repository, add the history save/restore feature, install the binary in Windows, and register it as DelegationConsole so that Windows runs it when you start a console application. Even if Microsoft won't accept a pull request with such a change. If you changed its CLSID, then it would be installable side by side with openconsole of Windows Terminal, and would be able to launch Windows Terminal for the UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Tag-Fix Doesn't match tag requirements Resolution-Won't-Fix We're just really obstinate about this. There's probably a good reason.
Projects
None yet
Development

No branches or pull requests

7 participants