Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Processing "%?" in PROMPT?
- X-seq: zsh-users 24452
- From: Christopher Nebel <c.nebel@xxxxxxxxx>
- To: zsh-users <zsh-users@xxxxxxx>
- Subject: Processing "%?" in PROMPT?
- Date: Wed, 20 Nov 2019 13:27:32 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=sender : from : content-type : content-transfer-encoding : mime-version : subject : message-id : date : to; s=20180706; bh=7WeR+LRw00BVxMw/knKZaxAHdbDfiHLqmfQg8rwfjiM=; b=LiRATe7ucZETXqLiBgFOyRdbRTaiLaNaAPVT+M/AzRwGvxlEOVtlxGXzkQRtOCzwdCpV S6HzJeacrSHjc2UZYu7spehGyq7wskp6cLICAgrRl7k/CcNFHc9Wd9CnRIvKjtokeTrP r7x6K6eX/kjoOFwGxb3bX5xQJxsMfqreNROWuMqZPeJZYE6St4Wdf2d/yLtT3GzLKusq JjUW3oWy9z9L9Nd8zUdUJs7h55kmt4Wr8FJerKxB5O41R2B/m7rWESvoGoLietKIqCNL 1PmRePXlDW3WZxSVxIhcQ1zltv/HSp2lwBTzEYJLWI3fk2PgV68Rg/u3FilWImqbP60V qQ==
- 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
- Sender: c.nebel@xxxxxxxxx
In my PROMPT, I want to get the status of the last command executed before the prompt, what in prompt expansion would be %?, but I want to pass it to a function. (Why? I like the idea of %? in the prompt, but thought it would be nice to dress it up a bit by rendering it as something other than just a number: “EX_USAGE” instead of “64” or “SIGILL” instead of “132”. That means passing the value of %? to a function to generate the text that appears in the prompt.)
My first attempt was to set PROMPT to ‘$(pretty-status %?)’, which doesn’t work because the “%?” is passed literally. I’ve tried various ways of evaluating “%?” — “print -P %?”, the “(%)” expansion flag — but none them work, because they expand to the same thing as “$?”, which is the status of the last command executed anywhere, including inside command substitution for the prompt. I could use a precmd function to save $? in a global, but only if I could guarantee that it was called before anything else, and that’s not a promise I’m comfortable making.
Any suggestions? zsh clearly has the value I want, since it uses it in prompt percent expansion, but how do I get at it? I’m honestly not sure if the behavior I’m seeing in “print -P %?” is a bug or if it’s working as designed. I’m mostly using zsh 5.3, but I’m seeing the same thing in 5.9.
—Chris N.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author