From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, PDS_TONAME_EQ_TOLOCAL_HDRS_LCASE,RCVD_IN_DNSWL_NONE autolearn=no autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 83870823 for ; Wed, 20 Nov 2019 21:28:21 +0000 (UTC) Received: (qmail 11513 invoked by alias); 20 Nov 2019 21:28:10 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24452 Received: (qmail 11441 invoked by uid 1010); 20 Nov 2019 21:28:10 -0000 X-Qmail-Scanner-Diagnostics: from nwk-aaemail-lapp02.apple.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25635. spamassassin: 3.4.2. Clear:RC:0(17.151.62.67):SA:0(-0.0/5.0):. Processed in 2.434914 secs); 20 Nov 2019 21:28:10 -0000 X-Envelope-From: c.nebel@apple.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.apple.com designates 17.151.62.67 as permitted sender) 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== X-Va-A: X-Va-T-CD: 59716a4d7c50750214701572f0bc27ed X-Va-E-CD: c9888cd9eb096dfba39a3ce231206d48 X-Va-R-CD: 0e3c3c0894c62ea6a679d536bfc309e4 X-Va-CD: 0 X-Va-ID: 2be370d2-eb43-464f-ab22-c5db997476d4 X-V-A: X-V-T-CD: 59716a4d7c50750214701572f0bc27ed X-V-E-CD: c9888cd9eb096dfba39a3ce231206d48 X-V-R-CD: 0e3c3c0894c62ea6a679d536bfc309e4 X-V-CD: 0 X-V-ID: b4db6f57-8243-4d14-a423-0007c99e152e X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-11-20_07:,, signatures=0 Sender: c.nebel@apple.com From: Christopher Nebel Content-type: text/plain; charset=utf-8 Content-transfer-encoding: quoted-printable MIME-version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Processing "%?" in PROMPT? Message-id: <2879A761-D4D3-44C5-8D54-D58D9E3F5EBF@apple.com> Date: Wed, 20 Nov 2019 13:27:32 -0800 To: zsh-users X-Mailer: Apple Mail (2.3445.104.11) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-11-20_07:,, signatures=0 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: =E2=80=9CEX_USAGE=E2=80=9D instead = of =E2=80=9C64=E2=80=9D or =E2=80=9CSIGILL=E2=80=9D instead of = =E2=80=9C132=E2=80=9D. 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 =E2=80=98$(pretty-status %?)=E2=80=99= , which doesn=E2=80=99t work because the =E2=80=9C%?=E2=80=9D is passed = literally. I=E2=80=99ve tried various ways of evaluating =E2=80=9C%?=E2=80= =9D =E2=80=94 =E2=80=9Cprint -P %?=E2=80=9D, the =E2=80=9C(%)=E2=80=9D = expansion flag =E2=80=94 but none them work, because they expand to the = same thing as =E2=80=9C$?=E2=80=9D, 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=E2=80=99s not a promise I=E2=80=99m 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=E2=80=99m honestly = not sure if the behavior I=E2=80=99m seeing in =E2=80=9Cprint -P %?=E2=80=9D= is a bug or if it=E2=80=99s working as designed. I=E2=80=99m mostly = using zsh 5.3, but I=E2=80=99m seeing the same thing in 5.9. =E2=80=94Chris N.=