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

Support for OSC 9;9 #409

Closed
floh96 opened this issue Feb 13, 2021 · 49 comments
Closed

Support for OSC 9;9 #409

floh96 opened this issue Feb 13, 2021 · 49 comments
Labels
🚀 feat New feature

Comments

@floh96
Copy link
Contributor

floh96 commented Feb 13, 2021

It would be nice if the oh-my-posh v3 powershell module would support OSC 9;9. It was supported in v2.
Windows Terminal added support for OSC 9;9 for the preview version (1.6) recently see microsoft/terminal#8330 and microsoft/terminal#8934.

@JanDeDobbeleer JanDeDobbeleer added the 🚀 feat New feature label Feb 13, 2021
@JanDeDobbeleer
Copy link
Owner

That's an easy addition. Can do.

@floh96
Copy link
Contributor Author

floh96 commented Feb 14, 2021

@JanDeDobbeleer do i need to configure it? it's not working in powershell 7 on windows 10 in windows terminal preview (1.6).
(without oh-my-posh i added this to my profile and it's working fine.)

@JanDeDobbeleer
Copy link
Owner

@floh96 you updated right? I didn't validate it yet, but that's exactly what's added to the prompt now.

@floh96
Copy link
Contributor Author

floh96 commented Feb 14, 2021

yeah i'm using version 3.89.0

@JanDeDobbeleer
Copy link
Owner

I'll check this evening maybe I did something stupid

@tradiff
Copy link
Contributor

tradiff commented Feb 14, 2021

Alright I'll go ahead and ask. I skimmed the linked issues, and the PR Jan wrote, and I don't get it.
ELI5, what's OSC 9;9?

@floh96
Copy link
Contributor Author

floh96 commented Feb 14, 2021

@travistx it's an ansi escape sequence that informs the terminal (windows terminal and conemu are supporting it) about the current working directory. When your current working directory is C:\Users for example and you are duplicating your tab in windows terminal with ctrl+shift+d (the keybinding is not bound in the default configuration, you must manually add it to your settings.json in windows terminal) the working directory of the new tab is also C:\Users.

@tradiff
Copy link
Contributor

tradiff commented Feb 14, 2021

I built OMP3 from source, the way I usually do, and can confirm this isn't working for me either. I confirmed OMP3 is emitting something that looks correct with my limited knowledge of this. Here's the output, base64 encoded:

G105Ozk7QzpcUHJvamVjdHNcUGVyc29uYWxcb2gtbXktcG9zaDNcc3JjGzc=

CTRL+SHIFT+D opens a new tab with my normal starting directory.
Windows Terminal Version: 1.5.10411.0
PowerShell 7.1.2

@floh96
Copy link
Contributor Author

floh96 commented Feb 14, 2021

@travistx it's only supported in the windows terminal preview version (1.6) atm i should have mentioned that

@tradiff
Copy link
Contributor

tradiff commented Feb 14, 2021

Test preview also. Same result.
Windows Terminal Preview Version: 1.6.10412.0

@JanDeDobbeleer
Copy link
Owner

Maybe the quotes are required.

@floh96
Copy link
Contributor Author

floh96 commented Feb 14, 2021

JanDeDobbeleer added a commit that referenced this issue Feb 14, 2021
@JanDeDobbeleer
Copy link
Owner

@travistx @floh96 I adjusted the sequence according to what's expected and yet still it doesn't work for V3. A bit puzzled here tbh.

@lnu
Copy link
Contributor

lnu commented Feb 14, 2021

But is it integrated in the latest windows terminal preview?
Even if I try manually with printf it does not work.
something like this should work printf "\e]9;9;C:\\\x9c"

@JanDeDobbeleer
Copy link
Owner

@lnu fair point, I assumed so. Allow me to validate on ConEmu.

@floh96
Copy link
Contributor Author

floh96 commented Feb 14, 2021

@lnu it is working with windows terminal preview 1.6 without oh-my-posh for me if i add this gist to my powershell profile
also OSC 9;9 is only working on windows paths see comment.
Also you can see in the linked pull requests that it's released in the 1.6 preview.

@lnu
Copy link
Contributor

lnu commented Feb 14, 2021

@JanDeDobbeleer maybe it has something to do with the config of your windows terminal like default starting folder or something like that

@JanDeDobbeleer
Copy link
Owner

@lnu I feel a bit like an idiot as it should work in my latest PR according to the spec. I'll take a look tomorrow during my lunch break, maybe I made a silly mistake I just don't see now.

@chenxiaolong
Copy link

I got it working on the fix-path-notification branch with either of these additional changes:

diff --git a/src/ansi_formats.go b/src/ansi_formats.go
index 0306d09..fb0e910 100644
--- a/src/ansi_formats.go
+++ b/src/ansi_formats.go
@@ -76,7 +76,7 @@ func (a *ansiFormats) init(shell string) {
 		a.escapeLeft = ""
 		a.escapeRight = ""
 		a.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\"
-		a.osc99 = "\x1b]9;9;\"%s\"\x9c"
+		a.osc99 = "\x1b]9;9;\"%s\"\x1b\\"
 	}
 }
 

or

diff --git a/src/ansi_formats.go b/src/ansi_formats.go
index 0306d09..778251e 100644
--- a/src/ansi_formats.go
+++ b/src/ansi_formats.go
@@ -76,7 +76,7 @@ func (a *ansiFormats) init(shell string) {
 		a.escapeLeft = ""
 		a.escapeRight = ""
 		a.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\"
-		a.osc99 = "\x1b]9;9;\"%s\"\x9c"
+		a.osc99 = "\x1b]9;9;\"%s\"\x07"
 	}
 }
 

I was looking at https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC:

Note. These codes may ends with ‘ESC\’ (two symbols - ESC and BackSlash) or ‘BELL’ (symbol with code \x07, same as ‘^a’ in *nix). For simplifying, endings in the following table marked as ‘ST’.

My understanding is that the sequence can either end in \x1b\\ (ie. \x1b\x5c) or \x07 by itself.

@lnu
Copy link
Contributor

lnu commented Feb 14, 2021

You're right. With this it works printf "\e]9;9;d:\\dev\e\\" which translates to \x1b]9;9d:\\dev\x1b\\
But somehow, it works when duplicating a tab but not when splitting.

@JanDeDobbeleer
Copy link
Owner

I'll adjust, validate and merge! Thanks @chenxiaolong you made my day.

@lnu
Copy link
Contributor

lnu commented Feb 14, 2021

by the way, I've seen you named the template osc99. Maybe we should rename the hyperlink template to osc8.

@lnu
Copy link
Contributor

lnu commented Feb 14, 2021

Did anyone try with wsl. It crashes when duplicating on my side. I found this script while googling:https://gist.github.com/skyline75489/d655aede4c729eff178a1c0bfd10f622

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Feb 14, 2021

@lnu did you go for the first or second sample @chenxiaolong provided? The link you shared is using the first variation.

@lnu
Copy link
Contributor

lnu commented Feb 14, 2021

The same as the hyperlink. Ending with \x1b\\. The link comes from microsoft/terminal#8166.

@lnu
Copy link
Contributor

lnu commented Feb 14, 2021

I also did some tests with the status indicator code osc 9;4 (microsoft/terminal#8055). Would be cool to see the taskbar flashing when a long operation is running.

@lnu
Copy link
Contributor

lnu commented Feb 15, 2021

I confirm I'm not able to duplicate a wsl tab with the osc9;9 code emitted. Without it, the tab is duplicated correctly.
image

To make it work with wsl, we have to do the same as here:

_win_path=$(wslpath -m $(pwd))
printf "\033]9;9;%s\033\\" "$_win_path"

this code will correctly set the curent folder for wsl.

JanDeDobbeleer added a commit that referenced this issue Feb 15, 2021
@JanDeDobbeleer
Copy link
Owner

@lnu this still doesn't work for me in WT (have the preview), can you validate my branch so we can merge?

@lnu
Copy link
Contributor

lnu commented Feb 15, 2021

let me check this. In the meantime I'm adding a function on environment to detect wsl or not and transform the path accordingly.

=> #413

@lnu
Copy link
Contributor

lnu commented Feb 15, 2021

@JanDeDobbeleer it works with your banch on my side. Just one question: why using x033 instead of x1b like for hyperlinks? Both works so maybe we can just keep the same for all osc sequences?
I replace all 033 by x1b (also for title) and everything works.

@JanDeDobbeleer
Copy link
Owner

Yes, I was under the impression you said it didn't work with that. As what I see is @chenxiaolong first sample now?

@lnu
Copy link
Contributor

lnu commented Feb 15, 2021

@JanDeDobbeleer Ok 033, x1b all the same :). so choose which one you want and you can use it for console, hyperlink and current folder. I tested both and it's ok. Sorry for the misunderstanding.

@JanDeDobbeleer
Copy link
Owner

I'm adjusting it

JanDeDobbeleer added a commit that referenced this issue Feb 15, 2021
@JanDeDobbeleer
Copy link
Owner

let me check this. In the meantime I'm adding a function on environment to detect wsl or not and transform the path accordingly.

@lnu missed this one, in favour of merging your branch instead. Ping me on Twitter when done, I'm starting my day ;-)

@JanDeDobbeleer
Copy link
Owner

Available in 3.39.1

@lnu
Copy link
Contributor

lnu commented Feb 15, 2021

@floh96 Can you confirm all is working now with version 3.89.1?

@floh96
Copy link
Contributor Author

floh96 commented Feb 15, 2021

@lnu i will check after work

@floh96
Copy link
Contributor Author

floh96 commented Feb 15, 2021

@lnu @JanDeDobbeleer it's working now in powershell and wsl thank you ❤️

@JanDeDobbeleer
Copy link
Owner

@floh96 heads-up, I created a config switch for this at root level for the next version as enabling it by default effectively triggers a notification on iTerm2 😂

@lnu
Copy link
Contributor

lnu commented Feb 15, 2021

Sorry... just checked the doc of iterm2. The pandora box is opened: osc 9;9 not being standard across terminals, everyday will be a source of happiness 😅

@nova77
Copy link

nova77 commented Dec 30, 2021

Hey folks, this no longer seems to be working. I wonder if it's because instead of $(wslpath -m $(pwd)) it should now be just $PWD.

@lnu
Copy link
Contributor

lnu commented Dec 30, 2021

Still working in pwsh but no more with wsl, checking why.

same as here #1508?

@lnu
Copy link
Contributor

lnu commented Dec 30, 2021

fixed here with #1516

@joaociocca
Copy link

joaociocca commented May 3, 2022

Is this what's causing my bash prompt to show this weird piece of code? (I've been searching everywhere for "9;9" and all I could find were binary matches in files, and this issue)

image

also, if I up then down (go to the previous command in history then back to clear line), it goes away.

oh yeah, I'm using sonicboom_light.omp.json theme

@JanDeDobbeleer
Copy link
Owner

@joaociocca yes. And depending on the terminal you might need to disable that in the config (theme) as bot all of them support it.

@joaociocca
Copy link

@JanDeDobbeleer pardon my noobness, how can I disable it in this case?

@JanDeDobbeleer
Copy link
Owner

@joaociocca is that theme file on your file system? As there's a parameter in there osc99 which is set to true. Only needs to be removed or set to false.

@joaociocca
Copy link

@JanDeDobbeleer yes, I downloaded a copy of https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/sonicboom_light.omp.json. Found the parameter, set to false and it's all pretty now! Thanks =D

Copy link

github-actions bot commented Feb 5, 2024

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚀 feat New feature
Projects
None yet
Development

No branches or pull requests

7 participants