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 prompt-detection in VTE #157

Open
muru opened this issue Mar 24, 2024 · 1 comment
Open

Support for prompt-detection in VTE #157

muru opened this issue Mar 24, 2024 · 1 comment

Comments

@muru
Copy link

muru commented Mar 24, 2024

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
Copy link
Member

mika commented Mar 24, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants