Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How reliable is %x prompt expansion?
On Mon, Feb 13, 2023 at 5:27 PM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> Hi , currently, I'm doing:
>
> 0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}
>
> on entry to each function or script.
FWIW, to get the name of the current file I use $ZSH_SCRIPT in
executable scripts and ${(%):-%x} in sourced files. To get the name of
the current function I use $0 (after `emulate -L zsh` to make sure
posix_argzero is not in effect).
> Also, I'm looking for a way to disable the promptsubst/print -P for
> a single variable, something like `print -P ${(!%)var}`, where !%
> is to denote that prompt expansion should not be done.
I do it like this:
print -P -- ${var//\%/%%}
A more useful example would be:
if [[ -e $file ]]; then
print -Pru2 -- "%F{red}error%f: file already exists: %U${file//\%/%%}%f"
fi
Note ${file//\%/%%}.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author