Add command history based on current folder #17782

Closed
opened 2026-01-31 05:53:18 +00:00 by claunia · 2 comments
Owner

Originally created by @Liero on GitHub (Jun 23, 2022).

Currently, when I press Up/Down arrow keys, the Terminal suggest previously entered commands.

I want to traverse only previously entered commands in current folder.

Example:

After following sequence of commands:

C:\repo> git commit
C:\repo> cd src\app
C:\repo\src\app> git rm file1.txt
C:\repo\src\app> cd ..\..
C:\repo>

a new keyboard shorcut like PageUp or Ctrl+Up would suggest cd src\app and then git commit, because they were the last commands executed in the directory.

Originally created by @Liero on GitHub (Jun 23, 2022). Currently, when I press Up/Down arrow keys, the Terminal suggest previously entered commands. I want to traverse only previously entered commands in current folder. Example: After following sequence of commands: ``` C:\repo> git commit C:\repo> cd src\app C:\repo\src\app> git rm file1.txt C:\repo\src\app> cd ..\.. C:\repo> ``` a new keyboard shorcut like `PageUp` or `Ctrl+Up` would suggest `cd src\app` and then `git commit`, because they were the last commands executed in the directory.
claunia added the Issue-FeatureIssue-QuestionNeeds-TriageNeeds-Tag-Fix labels 2026-01-31 05:53:18 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jun 23, 2022):

This is a really interesting idea - probably not one that's immediately viable, but an interesting idea nonetheless.

I started typing up a response here and realized I just had a lot of thoughts here, probably more than I had time to type. So my apologies for the kinda random collection of thoughts here

The history is actually provided by the shell, not the Terminal[1]. This would be a really good request for PowerShell / PSReadline, since that's actively maintained and has all sorts of fancy completions. The intelligent auto-complete that they shipped recently might actually just do this. I'm not as familiar with pwsh as I should be.

This does have interesting ties though to #1595, #12863. cd src/app is maybe a bit trivial compared to what I expected for that, but it still counts. Is there a good way for us to stash that relative to the CWD, so that it's a quickly accessible command? Probably not as easy as just up.

[1]: technically, cmd.exe's history actually is powered by conhost. But conhost has no idea what the CWD of a process is. I suppose it could theoretically be told what the CWD is, in the same way the Terminal is, and if it is told the CWD, stash history as a map of dir -> [history]. But there's no good way to pass settings to conhost for something like that.

We theoretically wouldn't really need to worry about back-compat on this one, cause you've already opt'd in to telling us the CWD, no legacy app is gonna accidentally set that.

@zadjii-msft commented on GitHub (Jun 23, 2022): This is a really interesting idea - probably not one that's immediately viable, but an interesting idea nonetheless. _I started typing up a response here and realized I just had a lot of thoughts here, probably more than I had time to type. So my apologies for the kinda random collection of thoughts here_ The history is actually provided by the shell, not the Terminal[1]. This would be a really good request for PowerShell / PSReadline, since that's actively maintained and has all sorts of fancy completions. The intelligent auto-complete that they shipped recently might actually just do this. I'm not as familiar with pwsh as I should be. This does have interesting ties though to #1595, #12863. `cd src/app` is maybe a bit trivial compared to what I expected for that, but it still counts. Is there a good way for us to stash that relative to the CWD, so that it's a quickly accessible command? Probably not as easy as just <kbd>up</kbd>. [1]: _technically_, `cmd.exe`'s history actually is powered by conhost. But conhost has no idea what the CWD of a process is. I suppose it could theoretically be told what the CWD is, in the same way the Terminal is, and if it is told the CWD, stash history as a map of `dir -> [history]`. But there's no good way to pass settings to conhost for something like that. We theoretically wouldn't really need to worry about back-compat on this one, cause you've already opt'd in to telling us the CWD, no legacy app is gonna _accidentally_ set that.
Author
Owner

@carlos-zamora commented on GitHub (Mar 20, 2023):

Hi @Liero. As Mike said, (with the exception of CMD) shells are the ones responsible for the command history, not the Terminal. We discussed this feature more as a team today, and adding that kind of responsibility to Terminal further complicates the relationship between Terminal and the attached shell, which could be a problem for new users, especially if they switch between different terminal emulators. This might be a better suggestion for "Clink" or "Yori".

@carlos-zamora commented on GitHub (Mar 20, 2023): Hi @Liero. As Mike said, (with the exception of CMD) shells are the ones responsible for the command history, not the Terminal. We discussed this feature more as a team today, and adding that kind of responsibility to Terminal further complicates the relationship between Terminal and the attached shell, which could be a problem for new users, especially if they switch between different terminal emulators. This might be a better suggestion for "Clink" or "Yori".
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17782