JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.45k stars 2.39k forks source link

Support for OSC 9;9 #409

Closed floh96 closed 3 years ago

floh96 commented 3 years ago

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 https://github.com/microsoft/terminal/pull/8330 and https://github.com/microsoft/terminal/pull/8934.

JanDeDobbeleer commented 3 years ago

That's an easy addition. Can do.

floh96 commented 3 years ago

@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 commented 3 years ago

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

floh96 commented 3 years ago

yeah i'm using version 3.89.0

JanDeDobbeleer commented 3 years ago

I'll check this evening maybe I did something stupid

tradiff commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

tradiff commented 3 years ago

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

JanDeDobbeleer commented 3 years ago

Maybe the quotes are required.

floh96 commented 3 years ago

yeah i think the quotes are required see https://github.com/microsoft/terminal/pull/8934#issuecomment-769587247 Edit: I don't think the quotes are the problem see https://github.com/skyline75489/terminal/blob/66ce9e2917aa2fb81cf3bbf6613f3a15e643b87e/src/cascadia/TerminalCore/TerminalDispatch.cpp#L486

JanDeDobbeleer commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

floh96 commented 3 years ago

@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 commented 3 years ago

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

JanDeDobbeleer commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

lnu commented 3 years ago

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

lnu commented 3 years ago

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 commented 3 years ago

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

lnu commented 3 years ago

The same as the hyperlink. Ending with \x1b\\. The link comes from https://github.com/microsoft/terminal/issues/8166.

lnu commented 3 years ago

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

lnu commented 3 years ago

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 commented 3 years ago

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

lnu commented 3 years ago

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

=> https://github.com/JanDeDobbeleer/oh-my-posh3/pull/413

lnu commented 3 years ago

@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 commented 3 years ago

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

lnu commented 3 years ago

@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 commented 3 years ago

I'm adjusting it

JanDeDobbeleer commented 3 years ago

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 commented 3 years ago

Available in 3.39.1

lnu commented 3 years ago

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

floh96 commented 3 years ago

@lnu i will check after work

floh96 commented 3 years ago

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

JanDeDobbeleer commented 3 years ago

@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 commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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

same as here https://github.com/JanDeDobbeleer/oh-my-posh/discussions/1508?

lnu commented 2 years ago

fixed here with https://github.com/JanDeDobbeleer/oh-my-posh/pull/1516

joaociocca commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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

JanDeDobbeleer commented 2 years ago

@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 commented 2 years ago

@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

github-actions[bot] commented 9 months ago

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.