help / color / mirror / Atom feed
* RFC: Generalized transient_rprompt
@ 2019-11-18 14:18 Roman Perepelitsa
  0 siblings, 0 replies; only message in thread
From: Roman Perepelitsa @ 2019-11-18 14:18 UTC (permalink / raw)
  To: Zsh Users

I've mentioned in workers/44905 that I was looking for a way to
implement generalized transient_rprompt. The goal is to not only hide
right prompt when accepting a command line (like transient_rprompt
does) but to shorten left prompt, too.

Regular behavior with PROMPT='%~%# ' and RPROMPT='%n@%m':

    /tmp% echo hello         romka@adam
    /tmp% true               romka@adam
    /tmp%                    romka@adam

With transient_rprompt option set:

    /tmp% echo hello
    /tmp% true
    /tmp%                    romka@adam

With left prompt shortened down to `%#`:

    % echo hello
    % true
    /tmp%                    romka@adam

I've found what appears to be a robust implementation that achieves
this effect and am looking for feedback. Here it is:

    zle-line-init() {
      emulate -L zsh

      [[ $CONTEXT == start ]] || return 0

      while true; do
        zle .recursive-edit
        local -i ret=$?
        [[ $ret == 0 && $KEYS == $'\4' ]] || break
        [[ -o ignore_eof ]] || exit 0

      local saved_prompt=$PROMPT
      local saved_rprompt=$RPROMPT
      PROMPT='%# '
      zle .reset-prompt

      if (( ret )); then
        zle .send-break
        zle .accept-line
      return ret

    zle -N zle-line-init

I've found one case where this implementation behaves differently from
transient_rprompt. When a background job completes, normally a
notification would appear right away and prompt together with the
current command line would be reprinted. My implementation will
prevent the notification from being shown until the current line is

Is there a way to fix this discrepancy? Are there other cases where
this implementation behaves differently from transient_rprompt?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-18 14:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-18 14:18 RFC: Generalized transient_rprompt Roman Perepelitsa


This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ http://inbox.vuxu.org/zsh-users \
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:

code repositories for the project(s) associated with this inbox:


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git