Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Dynamic parameters for PROMPT_SUBST functions




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



Messages sorted by: Reverse Date, Date, Thread, Author