help / color / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: RFC: Generalized transient_rprompt
Date: Mon, 18 Nov 2019 15:18:50 +0100
Message-ID: <CAN=4vMoPcoPyp97d=g6CVyhNw6KJ_i4gqVUQfNWd26iBMr4MsQ@mail.gmail.com> (raw)

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?


                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMoPcoPyp97d=g6CVyhNw6KJ_i4gqVUQfNWd26iBMr4MsQ@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=zsh-users@zsh.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link


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

Example config snippet for mirrors

Newsgroup available over NNTP:

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