Skip to content

Instantly share code, notes, and snippets.

@skyline75489
Last active October 15, 2021 23:49
Show Gist options
  • Save skyline75489/784548403f230bfa2769556a0e4cc9d7 to your computer and use it in GitHub Desktop.
Save skyline75489/784548403f230bfa2769556a0e4cc9d7 to your computer and use it in GitHub Desktop.
Windows Terminal OSC 7 for CMD
PROMPT=$E]7;file://%COMPUTERNAME%/$P$E\$P$G
@skyline75489
Copy link
Author

@j4james
Copy link

j4james commented Sep 20, 2020

As I mentioned in the PR comments, I'd also suggest we include some form of "hostname" in here, even if we don't currently choose to validate it, e.g.

PROMPT=$E]7;file://%COMPUTERNAME%/$P$E\$P$G

I'd also probably leave the $S off the end if we're planning to publish this as a recommendation. If some people prefer to have a space on the end, that's obviously their choice, but I think our recommendation should match the default format, which I believe is just $P$G.

@LuanVSO
Copy link

LuanVSO commented Sep 20, 2020

better use %%COMPUTERNAME%% otherwise the variable will only be evaluated when this command is executed

@j4james
Copy link

j4james commented Sep 20, 2020

That doesn't seem to work for me. It just ends up evaluating to %COMPUTERNAME%. I don't think it's the end of the world if we can't get it to update when the machine name changes though. That's not likely to be often is it?

@LuanVSO
Copy link

LuanVSO commented Sep 20, 2020

does it print %COMPUTERNAME% or is it stored as that?

@j4james
Copy link

j4james commented Sep 20, 2020

It prints the literal text %COMPUTERNAME%. Maybe I'm just being stupid, but I was testing by using a sequence without escapes, so I could see what was being produced. Basically something like this:

PROMPT=Esc]7;file://%%COMPUTERNAME%%/$PEsc\$P$G

And the sequence I saw being output was something like this:

Esc]7;file://%COMPUTERNAME%/C:\pathEsc\

Without the double percent chars that shows my actual computer name.

I should mention that this is with the PROMPT being set in a batch file. If I set it directly from the command line, then my computer name is displayed, but with percent chars on either side.

@LuanVSO
Copy link

LuanVSO commented Sep 20, 2020

oh, I know what's going on, its my fault, the double % strategy only works if using setx like this:

 setx PROMPT "$E]7;file://%%COMPUTERNAME%%/$P$E\$P$G"

then restart cmd

@j4james
Copy link

j4james commented Sep 20, 2020

OK, I see what you were getting at now - this works for me. I misinterpreted what you said about the variable only being evaluated the first time, so I thought at first that this version would update in "real time" (i.e. if the computer name changed during a particular session), but that's definitely not essential. This is good enough for me.

@3N4N
Copy link

3N4N commented Oct 15, 2021

It doesn't work for me. I'm using it to open new tabs/splits in Windows Terminal in he same directory. Your powershell prompt worked. But for cmd this appears to do nothing.

@LuanVSO
Copy link

LuanVSO commented Oct 15, 2021

yeah you have use osc]9;9 for it to work on wt rn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment