zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Stark <sstark+zsh@mailbox.org>
To: zsh-users@zsh.org
Subject: Dynamic parameters for PROMPT_SUBST functions
Date: Fri, 19 Jun 2020 08:32:33 +0200	[thread overview]
Message-ID: <20200619063233.zybs27xvqp56t4p5@singold> (raw)


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

             reply	other threads:[~2020-06-19  6:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19  6:32 Sebastian Stark [this message]
2020-06-19  6:58 ` Lawrence Velázquez
2020-06-19 10:56 ` Daniel Shahaf
2020-06-19 17:08   ` Sebastian Stark
2020-06-20 11:06     ` Daniel Shahaf
2020-06-21 15:17       ` Sebastian Stark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200619063233.zybs27xvqp56t4p5@singold \
    --to=sstark+zsh@mailbox.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).