Is there any documentation on the shell integration, both on what the escape sequences are, and how the bash integration works (e.g., I don't get why PROMPT_COMMAND is needed instead of just putting something in the PS1, or why DEBUG is used)? I'm interested in writing integrations for other shells, if that's possible.Aaron Meurer
--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Looks like the escape sequence docs went down with the googlecode site, but I can document it here easily enough.There are four escape sequences called the "FinalTerm" sequences (since FinalTerm invented them):OSC 1 3 3 ; A STSent just before start of shell promptOSC 1 3 3 ; B STSent just after end of shell prompt, before command user entersOSC 1 3 3 ; C STSent just before start of command outputOSC 1 3 3 ; D ; Ps STSent just after end of command prompt. Ps is command status, 0-255.
These enable the mark, command history, and select output of last command.Additionally, there are a few other sequences that iTerm2 defined. These are typically sent within the prompt.
These enable the rest of the shell integration feature (recent directories, per-host command history, scp upload and download, user-defined badge variables, whatever else I'm forgetting).OSC 1 3 3 7 ; S e t U s e r V a r = Ps1 = Ps2 STUser-defined vars. Ps1 is the key, Ps2 is the value. Not sent by default. Typically the user defines a shell function that invokes function like "iterm2_set_user_var key value", which causes this code to be sent.
OSC 1 3 3 7 ; S h e l l I n t e g r a t i o n V e r s i o n = Pn STReports the current version of the shell integration script. Pn is the version. Currently only "1" is defined. iTerm2 has a baked-in notion of the "current" version and if it sees a lower number the user will be prompted to upgrade.
O S C 1 3 3 7 ; R e m o t e H o s t = Ps1 @ Ps2 STReports the user name and hostname Ps1 is username, Ps2 is fully-qualified hostname. New shell integration scripts should allow the user to provide the hostname in case the DNS server is slow.O S C 1 3 3 7 ; C u r r e n t D i r = Ps1 STReports the current directory.The zsh script is the easiest to understand. bash is a mess because it doesn't have support for a proper preexec function, fish is weird, and nobody understands tcsh. Everything lives in github.com/gnachman/iterm2-website in source/misc.TBH we probably don't need to use PROMPT_COMMAND. The bash code is derived from this: https://github.com/rcaloras/bash-preexec (actually, an older version). I am certain it can be simplified. DEBUG is used because it lets us send the FinalTerm C code at the right time, which is otherwise impossible.
OSC 1 3 3 ; D ; Ps STSent just after end of command prompt. Ps is command status, 0-255.You mean command output?
These enable the mark, command history, and select output of last command.Additionally, there are a few other sequences that iTerm2 defined. These are typically sent within the prompt.Is the order important here? I notice that the zsh integration passes these after D.
These enable the rest of the shell integration feature (recent directories, per-host command history, scp upload and download, user-defined badge variables, whatever else I'm forgetting).OSC 1 3 3 7 ; S e t U s e r V a r = Ps1 = Ps2 STUser-defined vars. Ps1 is the key, Ps2 is the value. Not sent by default. Typically the user defines a shell function that invokes function like "iterm2_set_user_var key value", which causes this code to be sent.So, for instance, if I want to include the IPython prompt number, I would use this with something like ipython_prompt_number = N, right?
OSC 1 3 3 7 ; S h e l l I n t e g r a t i o n V e r s i o n = Pn STReports the current version of the shell integration script. Pn is the version. Currently only "1" is defined. iTerm2 has a baked-in notion of the "current" version and if it sees a lower number the user will be prompted to upgrade.So what should a custom shell integration use? Is it still a good idea to include this to be warned of compatibility breaks (although I would hope those don't happen).
O S C 1 3 3 7 ; R e m o t e H o s t = Ps1 @ Ps2 STReports the user name and hostname Ps1 is username, Ps2 is fully-qualified hostname. New shell integration scripts should allow the user to provide the hostname in case the DNS server is slow.O S C 1 3 3 7 ; C u r r e n t D i r = Ps1 STReports the current directory.The zsh script is the easiest to understand. bash is a mess because it doesn't have support for a proper preexec function, fish is weird, and nobody understands tcsh. Everything lives in github.com/gnachman/iterm2-website in source/misc.TBH we probably don't need to use PROMPT_COMMAND. The bash code is derived from this: https://github.com/rcaloras/bash-preexec (actually, an older version). I am certain it can be simplified. DEBUG is used because it lets us send the FinalTerm C code at the right time, which is otherwise impossible.I see. Hopefully the shells/REPLs I want to integrate this with make this easier.
I'd classify it as a harmless bug. D and A always go together, so I don't bother to track D's location. There isn't really a need for D separate from A as far as I can tell, but then I didn't invent the protocol. You could argue that the first prompt is different so separate codes are justified, but it's not a very important distinction.
What goes wrong for you when there's no command? It works ok if I just hit enter at the prompt. That doesn't get entered into command history, of course. It should be forgiving if you forget C or D, but there might be bugs there.
Multiline commands aren't supported because every shell prefixes the continued lines differently (?, >, or indentation, or something fancy like PS2). I suppose I could customize PS2, at least for bash and zsh, adding a new escape sequence to indicate a continuation.
On Tue, Aug 4, 2015 at 11:06 PM, George Nachman <gnac...@llamas.org> wrote:I'd classify it as a harmless bug. D and A always go together, so I don't bother to track D's location. There isn't really a need for D separate from A as far as I can tell, but then I didn't invent the protocol. You could argue that the first prompt is different so separate codes are justified, but it's not a very important distinction.OK, I'll just be sure to document that in my library.I guess I could see this being a problem if someone has a wacky multiline prompt and they want the arrow to appear on something other than the first line.
What goes wrong for you when there's no command? It works ok if I just hit enter at the prompt. That doesn't get entered into command history, of course. It should be forgiving if you forget C or D, but there might be bugs there.This is coming from testing printing the escape sequences directly. If I doA prompt B \n C output Dthen the arrow shows up, and I can select it with Cmd-Shift-Up, but I can't right click on it. It's basically the same asA prompt B \n A prompt BMaybe it's intended behavior?