From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30629 invoked from network); 19 Jun 2020 06:33:32 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 19 Jun 2020 06:33:32 -0000 Received: (qmail 28198 invoked by alias); 19 Jun 2020 06:33:19 -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: Sender: zsh-users@zsh.org X-Seq: 24934 Received: (qmail 19280 invoked by uid 1010); 19 Jun 2020 06:33:19 -0000 X-Qmail-Scanner-Diagnostics: from mout-p-201.mailbox.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25842. spamassassin: 3.4.4. Clear:RC:0(80.241.56.171):SA:0(-2.7/5.0):. Processed in 3.000208 secs); 19 Jun 2020 06:33:19 -0000 X-Envelope-From: sstark+zsh@mailbox.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at mailbox.org designates 80.241.56.171 as permitted sender) X-Virus-Scanned: amavisd-new at heinlein-support.de Date: Fri, 19 Jun 2020 08:32:33 +0200 From: Sebastian Stark To: zsh-users@zsh.org Subject: Dynamic parameters for PROMPT_SUBST functions Message-ID: <20200619063233.zybs27xvqp56t4p5@singold> Mail-Followup-To: zsh-users@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline X-MBO-SPAM-Probability: 0 X-Rspamd-Score: -3.61 / 15.00 / 15.00 X-Rspamd-Queue-Id: 4EBED1768 X-Rspamd-UID: a620df Hello, I am trying to have a function call in my prompt that gets the return value of the last command as a parameter (%?). However I am having trouble to get this right. Instead of an actual number, what is handed to the function is the literal string %?. Is there anything I can do better or is this just not possible? I could probably use $? in the function itself, but that sounds a bit fragile to me because I maybe get a different value of $?. In this example I write the parameter to a file, because if I just print it it would get printed as a literal %? and expanded later and thus hide the issue I am facing % zsh -f % x(){print $1 >>/tmp/lll} % setopt PROMPT_SUBST % PROMPT=$'$(x %?) %m%# ' % cat /tmp/lll %? Thanks for any hints. Sebastian