-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Request: "Tab title" text resolves environment variables #10144
Comments
This isn't a terrible idea. It's a lot like #1320, but kind of it's own specific request. I'll leave this open as a task as a child of that one. Thanks! |
This would be useful for setting the tab title to %cd% for example, so it's easy to see what each tab is, instead of all just saying "Command Prompt" or "Windows PowerShell." That's the feature I was looking for, and I tried %cd% to see if it was a hidden ability. Ideally, there should be different options, such as just the current directory or the whole path, and whether to show e.g. "C:\Program Files\WindowsAp..." vs "...d8bbwe\WindowsTerminal.exe" vs "C:...\WindowsTerminal.exe" or some other variation, and it should show the available variables and formatting that can be used in the settings. |
@vertigo220 FWIW that's probably better served by configuring your shell to change the Terminal's title. |
Thanks. Figured out how to do it for PS, though haven't tested yet (and I hate this obsession with putting appdata-type crap in "Documents," which I guess just doesn't mean documents anymore...), but I can't find any way to do it with cmd. I've found how to change the title (no thanks to MS's help page, which shows the command usage incorrectly) and a workaround to create a makeshift profile/bashrc-type file, but I don't see a way to get it to change the title every time the directory is changed. I assume this isn't possible? |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
TUTORIAL/GUIDEFor anyone who comes across this later looking to do the same, I just spent a bit of time on this trying to get both the title to be show the CWD (current working directory) and the CWD to be used when duplicating or splitting a tab. Both involve the use of the prompt command (cmd) or variable (PS). Getting it working in PS was relatively easy, but cmd was trickier because each thing requires its own slight modification, and they seemed to conflict, so it took a good bit of trial and error. This post is meant to try and put everything together about how to do this relatively concisely while also actually explaining things. Much of it is covered here, but it doesn't fully explain everything, requires going to yet another page for more instructions, and even then still doesn't cover everything. Hopefully these instructions will be quick and easy to understand so others won't have to hunt down the various bits and piece them together and figure out the nuances like I did. CMD:I couldn't find any reference on the square bracket ("]"), semicolon, backslash, or the numbers. All I knew was 0 to show the CWD in the title, thanks to the above post, and double-9's to make the CWD available to the terminal for use when duplicating/splitting a tab. I tried to use them in various combinations together, but that didn't work. I may be wrong here, but my understanding is that they're used in this format: $e]#;... escapes the "]" and the # tells what the character strings following the ";" are used for, e.g. 0 for window title and 9;9 for setting the CWD, and the $e\ is just and escape of the backslash which separates each section of the prompt. So one section to set the title bar, one to set the CWD, and one to set the actual prompt. This led to the following:
The first chunk ($e]0;$p) sets the title bar, then a separator ($e), then the second chunk ($e]9;9;$p) sets the CWD, then another separator, and finally the prompt ($p$g). The list of what the various characters (e.g. p, g, etc) do is here. With an understanding of how it actually works, hopefully it will be easier for others to customize to their liking. The next step is to make the cmd shell run this every time a terminal is opened, so it can do its thing. There are different ways of doing this (**skip to the end of this section for how to do it on a profile basis), but I personally prefer doing it via the registry (if you don't like messing with that, skip to after the next line of code). Just go to "HKLM\SOFTWARE\Microsoft\Command Processor" and create a new key of type "String Value" (REG_SZ), name it "AutoRun" (without the quotes), and either put the prompt command in there or put the path to a .cmd file that contains the command, e.g. bashrc.cmd. You can also just run the following command from an elevated terminal (replace the actual prompt config with your own):
For a non-registry method, use the following command (replace the actual prompt config with your own):
That's all there is to it. **To do this per profile, simply go to the profile in settings and add the prompt line to the 'Command line' setting, e.g. PowerShell:***Skip to the end for setting per profile Open PowerShell and type To only set the title to the CWD:
To only duplicate/split tab using the CWD:
To do both:
I still don't fully understand this, since it seems the output of the function is the same regardless of which one is used, yet they only work as described here. Also, I feel the need to mention that I wasted yet another several minutes due to still another MS failure (I hate using MS as a reference, they can't seem to get anything right), as I copy-pasted the first function from a MS DevBlog that oh-so-helpfully used MS-Word-style slanted quotes that caused it to not work and led to me having to troubleshoot the issue. /smh ***PowerShell can also be configured on a per-profile basis in a similar way to cmd: Modify the profile 'Command line' setting, e.g. (This is a broken method, only read if you're interested in trying to get it working) Hopefully someone finds this useful. |
@zadjii-msft In addition to my question above regarding the possibility of a separate profile for cmd with Terminal to allow the use of a different prompt variable with Terminal vs the standard command window, since it is possible to get the CWD to Terminal for displaying in the tab, would it be possible to have an option to split it and make the tabs double-height, so it could have two lines, with the top being e.g. "C:\Windo..." and the bottom being "...ystem32" to allow for seeing either end of the CWD in the title to be able to better tell what tab is what? Or, at least, just display the current dir only instead of the full path, perhaps with the drive letter included, e.g. "C:...\system32?" |
Maybe - that might be covered by #2785. I don't know if
I doubt we'd enable the tabs to be two lines in height, where the first row is just the first bit of the tab title, and the second is just the end. There is Ultimately, Command Prompt is not a modern shell and not one we can make changes to. So, if you want something like |
I mean, you can totally do that today - doing something like |
Beautiful. I just put As for splitting the title, it seems once it's in the hands of Terminal, it's no longer up to the shell, ancient (cmd) or not (PS) and should be doable, though I obviously could be wrong or misunderstanding some part of this. I am slowly switching to PowerShell at least, but I still do/have a lot of batch scripts so cmd will be sticking around for a while for me, unfortunately. |
Description of the new feature/enhancement
When entering the "Tab title" text in the settings, it would be great if environment variables could be resolved. When I've tried this, for example with standard Command Prompt, all I get are strings of "%SOMEENVIRONMENTVAR%" in my tab title.
Proposed technical implementation details (optional)
For all "Tab title" strings, just run an expand pass that attempts to substitute any "%..%" sub-strings with any available environment variable.
The text was updated successfully, but these errors were encountered: