Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
RFC: Generalized transient_rprompt
- X-seq: zsh-users 24446
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: RFC: Generalized transient_rprompt
- Date: Mon, 18 Nov 2019 15:18:50 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=SOjACXbXnd0qgj7S4PKlLUabzO01Ok8ndLF36Bp5Uig=; b=m7efI1K5rReJSjx6lfTkUZsWhJLq3T1VVcczoJHbocbFyQN5xlTpR2H7bupZal8j1J OfEPHVljYnk5pFOq8n3txnl+rL1e85sbjGg5/gd0FxjLeQ16Tfu1uJkBzgJHt+7o0Rd2 xVuubRO7RA7bZ3zvmmnY/uBKX0jaNkI0buxVJPBlOSRJ3fJ9a7gTFSSKWDhC8HbnHrNM vwRT4Cv2Y9oVSq+dNdt5Kv197BcAkBomuS7KMfL6QvkXTGWbNVsCwBV6DLcxpx/JFleS dYuDBgrIbAJG7A7EeJd/+5wtxrhN1u2xjsWApHyvDnQAu0LiCIefj63s0KWF1FQQjkcT gUBg==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author