zsh-users
 help / color / 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
    hello
    /tmp% true               romka@adam
    /tmp%                    romka@adam

With transient_rprompt option set:

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

With left prompt shortened down to `%#`:

    % echo hello
    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
      done

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

      if (( ret )); then
        zle .send-break
      else
        zle .accept-line
      fi
      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
finished.

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

Roman.

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

only message in thread, back to index

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

zsh-users

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

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


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