Display last used command as tab name #16294

Closed
opened 2026-01-31 05:03:04 +00:00 by claunia · 9 comments
Owner

Originally created by @Timsonrobl on GitHub (Dec 28, 2021).

Description of the new feature/enhancement

When running multiple tabs of Windows Terminal with long running tasks with extensive console output it's easy to forget which tab is running which task. Sometimes you can scroll all the way up to see the command but sometimes it's already gone, and if terminal is reused for next task you have to find it in the middle of thousand lines of output. You can currently manually change tab name to reduce confusion, but it can quickly become a bother if you need to run many tasks and monitor output.
Adding profile option for tab names to automatically reflect last used command in each tab would greatly improve user expirience in such cases.

Proposed technical implementation details (optional)

Add profile option for tab names to reflect last used command in each tab by default instead of profile name.

Originally created by @Timsonrobl on GitHub (Dec 28, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement When running multiple tabs of Windows Terminal with long running tasks with extensive console output it's easy to forget which tab is running which task. Sometimes you can scroll all the way up to see the command but sometimes it's already gone, and if terminal is reused for next task you have to find it in the middle of thousand lines of output. You can currently manually change tab name to reduce confusion, but it can quickly become a bother if you need to run many tasks and monitor output. Adding profile option for tab names to automatically reflect last used command in each tab would greatly improve user expirience in such cases. <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) Add profile option for tab names to reflect last used command in each tab by default instead of profile name. <!-- A clear and concise description of what you want to happen. -->
claunia added the Issue-QuestionNeeds-TriageNeeds-Tag-FixResolution-Answered labels 2026-01-31 05:03:04 +00:00
Author
Owner

@Timsonrobl commented on GitHub (Dec 28, 2021):

Also another implementation option, probably harder to implement but even better: option to change tab name at runtime to a reflect last used command in the tab rename interface (maybe a button in a text field, next to the cross icon that cancels rename operation).

@Timsonrobl commented on GitHub (Dec 28, 2021): Also another implementation option, probably harder to implement but even better: option to change tab name at runtime to a reflect last used command in the tab rename interface (maybe a button in a text field, next to the cross icon that cancels rename operation).
Author
Owner

@ysc3839 commented on GitHub (Dec 29, 2021):

So what is "last used command"?
The "Command line" option in profile setting page?
image

@ysc3839 commented on GitHub (Dec 29, 2021): So what is "last used command"? The "Command line" option in profile setting page? ![image](https://user-images.githubusercontent.com/12028138/147648938-a8be0aaa-04ce-4808-b0de-52409a42549a.png)
Author
Owner

@Timsonrobl commented on GitHub (Dec 29, 2021):

@ysc3839 no, I mean last command used inside shell
image

@Timsonrobl commented on GitHub (Dec 29, 2021): @ysc3839 no, I mean last command used inside shell ![image](https://user-images.githubusercontent.com/9917883/147656594-74256995-ed40-426c-b54a-718a937aac43.png)
Author
Owner

@eryksun commented on GitHub (Dec 29, 2021):

A feature such as this would best addressed in the shell, maybe with some hook for GNU Readline in bash or PSReadLine in PowerShell. Bear in mind that in many cases the console's command history doesn't even have the last line of input that was read because many console applications and shells read low-level key presses or characters, with line-input mode disabled.

@eryksun commented on GitHub (Dec 29, 2021): A feature such as this would best addressed in the shell, maybe with some hook for GNU Readline in bash or PSReadLine in PowerShell. Bear in mind that in many cases the console's command history doesn't even have the last line of input that was read because many console applications and shells read low-level key presses or characters, with line-input mode disabled.
Author
Owner

@ysc3839 commented on GitHub (Dec 29, 2021):

This should provided by the shell instead of terminal.
I would suggest using Oh My Zsh. It has this feature out of box.

@ysc3839 commented on GitHub (Dec 29, 2021): This should provided by the shell instead of terminal. I would suggest using [Oh My Zsh](https://ohmyz.sh/). It has this feature out of box.
Author
Owner

@Timsonrobl commented on GitHub (Dec 29, 2021):

This should provided by the shell instead of terminal. I would suggest using Oh My Zsh. It has this feature out of box.

Thank you, I'll try that. But that would only apply when working in WSL, what are the options in Windows shells like cmd and PowerShell?

@Timsonrobl commented on GitHub (Dec 29, 2021): > This should provided by the shell instead of terminal. I would suggest using [Oh My Zsh](https://ohmyz.sh/). It has this feature out of box. Thank you, I'll try that. But that would only apply when working in WSL, what are the options in Windows shells like cmd and PowerShell?
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Dec 29, 2021):

Doesn't cmd already change the title when you run a command? Although it also restores the title after the command finishes, and I suppose you don't want that.

For PowerShell, you could do one of:

  • Set the window title when each command finishes.
    function prompt() {
        $Host.UI.RawUI.WindowTitle = (Get-History)[-1].CommandLine
        "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
    }
    
  • Set the window title whenever PSReadLine reads a line.
    function PSConsoleHostReadLine {
        Microsoft.PowerShell.Core\Set-StrictMode -Off
        ($Host.UI.RawUI.WindowTitle = [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext))
    }
    
  • Wait for https://github.com/PowerShell/PowerShell/issues/14484.
@KalleOlaviNiemitalo commented on GitHub (Dec 29, 2021): Doesn't cmd already change the title when you run a command? Although it also restores the title after the command finishes, and I suppose you don't want that. For PowerShell, you could do one of: * Set the window title when each command finishes. ```PowerShell function prompt() { $Host.UI.RawUI.WindowTitle = (Get-History)[-1].CommandLine "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " } ``` * Set the window title whenever PSReadLine reads a line. ```PowerShell function PSConsoleHostReadLine { Microsoft.PowerShell.Core\Set-StrictMode -Off ($Host.UI.RawUI.WindowTitle = [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext)) } ``` * Wait for <https://github.com/PowerShell/PowerShell/issues/14484>.
Author
Owner

@Timsonrobl commented on GitHub (Dec 29, 2021):

  • Set the window title whenever PSReadLine reads a line.
    function PSConsoleHostReadLine {
        Microsoft.PowerShell.Core\Set-StrictMode -Off
        ($Host.UI.RawUI.WindowTitle = [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext))
    }
    

@KalleOlaviNiemitalo thank you so much, option 2 for PowerShell was exactly what I was looking for!

@Timsonrobl commented on GitHub (Dec 29, 2021): > * Set the window title whenever PSReadLine reads a line. > ```powershell > function PSConsoleHostReadLine { > Microsoft.PowerShell.Core\Set-StrictMode -Off > ($Host.UI.RawUI.WindowTitle = [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext)) > } > ``` @KalleOlaviNiemitalo thank you so much, option 2 for PowerShell was exactly what I was looking for!
Author
Owner

@zadjii-msft commented on GitHub (Jan 3, 2022):

Yea, as others have noted, this is something that should ideally be handled by your shell, since the Terminal itself doesn't really know the difference between you "running a command" or just typing a new line in vim 😄

@zadjii-msft commented on GitHub (Jan 3, 2022): Yea, as others have noted, this is something that should ideally be handled by your shell, since the Terminal itself doesn't really know the difference between you "running a command" or just typing a _new line in vim_ 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16294