grml / grml-etc-core

Grmls core configuration files for zsh, vim, screen…
http://git.grml.org/?p=grml-etc-core.git
272 stars 75 forks source link

Support for prompt-detection in VTE #157

Open muru opened 3 months ago

muru commented 3 months ago

VTE (which is the base of many Linux terminal emulators like GNOME Terminal, Terminator, Xfce Terminal, etc.) now supports identifying prompts using OSC codes, and therefore jumping between prompts in the terminal output. This is quite useful when lookup back through commands with voluminous output, as you can just press CtrlShift to jump directly to the previous prompt (and so the start of the output). For this, the /etc/profile.d/vte.sh file adds some customization to PS1, which is naturally lost when using the grml themes:

# Enclose the primary prompt between
# ← OSC 133;D;retval ST (report exit status of previous command)
# ← OSC 133;A ST (mark beginning of prompt)
# → OSC 133;B ST (mark end of prompt, beginning of command line)
# [snip]
PS1=$'%{\e]133;D;%?\e\\\e]133;A\e\\%}'"$PS1"$'%{\e]133;B\e\\%}'

I can work around this by doing something like:

zstyle ':prompt:grml:*:items:user' pre $'%{\e]133;D;%?\e\\\e]133;A\e\\%}'
zstyle ':prompt:grml:*:items:sad-smiley' post $'%{\e]133;B\e\\%}%f'

But it would be nice if these could be added by GRML itself, maybe as a configurable theme item.


Looking at it a bit more, something like this seems to be more in the spirit of things:

__vte_prompt_start () {
    if [[ ${VTE_VERSION:-0} -ge 7600 ]]
    then
        REPLY=$'%{\e]133;D;%?\e\\\e]133;A\e\\%}'
    fi
}
__vte_prompt_end () {
    if [[ ${VTE_VERSION:-0} -ge 7600 ]]
    then
        REPLY=$'%{\e]133;B\e\\%}'
    fi
}
grml_theme_add_token prompt_start -i __vte_prompt_start '' ''
grml_theme_add_token prompt_end -i __vte_prompt_end '' ''
zstyle ':prompt:grml:left:setup' items prompt_start rc user at host path vcs percent
zstyle ':prompt:grml:right:setup' items sad-smiley prompt_end

Would it be fine to make a PR adding tokens like these?

mika commented 3 months ago

Thanks for the information, wasn't aware of this issue!

A fix for this would be more than welcome, @ft what do you think of @muru's suggestion for a PR?