Zsh Mailing List Archive
Messages sorted by:
Re: Dynamic parameters for PROMPT_SUBST functions
- X-seq: zsh-users 24939
- From: Sebastian Stark <sstark+zsh@xxxxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Subject: Re: Dynamic parameters for PROMPT_SUBST functions
- Date: Sun, 21 Jun 2020 17:17:47 +0200
- Cc: zsh-users@xxxxxxx
- In-reply-to: <firstname.lastname@example.org>
- List-help: <mailto:email@example.com>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- List-unsubscribe: <mailto:email@example.com>
- Mail-followup-to: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20200619063233.zybs27xvqp56t4p5@singold> <firstname.lastname@example.org> <20200619170847.iq2bjrnrmon5cctd@singold> <email@example.com>
- Sender: zsh-users@xxxxxxx
Am Samstag, den 20. Juni 2020 um 13:06 schrieb Daniel Shahaf:
Sebastian Stark wrote on Fri, 19 Jun 2020 19:08 +0200:
Am Freitag, den 19. Juni 2020 um 13:04 schrieb Daniel Shahaf:
>Sebastian Stark wrote on Fri, 19 Jun 2020 08:32 +0200:
>> I am trying to have a function call in my prompt that gets the return
>> value of the last command as a parameter (%?).
>What would you do with «%?» if you could get its value?
I would try to split it into signal and return value information, so I
do not get "130" if I ctrl-c, but something like 0 and INT.
That information isn't available via %?:
% PS1='%?%# '
0% perl -E 'kill 9, $$'
zsh: killed perl -E 'kill 9, $$'
137% perl -E 'exit (9 + 128)'
Note how %? expanded to the same value in both cases.
Yes, I noticed that this is not entirely clean.
% setopt promptsubst
% PS1='$signals[1 + ($? - 128)]%# '
% (exit 137)
zsh: exit 137 ( exit 137; )
The variable «$signals» is predefined. Just make sure that $? is the
right value. (If you have other $(…) in there, they might overwrite
«$?»? I haven't tested.)
Thanks for this, I didn't know about the signals array. Also, your
solution looks pretty much like what I was looking for.
However, in my prompt variable this expands to the number, not the
signal name. Your code does the right thing when used as PS1 without
anything else, but not in combination with my other things in there.
For now I will put that on my pile of unfinished things, as it seems to
be complicated for little outcome.
Messages sorted by: