zsh-users
 help / color / mirror / code / Atom feed
* How reliable is %x prompt expansion?
@ 2023-02-13 16:26 Sebastian Gniazdowski
  2023-02-13 16:39 ` Roman Perepelitsa
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2023-02-13 16:26 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

Hi , currently, I'm doing:

0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}

on entry to each function or script. It works well, however, I'm planning
to update the plugin standard recommendation for $0 support and I'm
thinking if there are any circumstances where it might fail? $0 is to point
to the script/function source.

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.

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 1570 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How reliable is %x prompt expansion?
  2023-02-13 16:26 How reliable is %x prompt expansion? Sebastian Gniazdowski
@ 2023-02-13 16:39 ` Roman Perepelitsa
  0 siblings, 0 replies; 2+ messages in thread
From: Roman Perepelitsa @ 2023-02-13 16:39 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Mon, Feb 13, 2023 at 5:27 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-13 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-13 16:26 How reliable is %x prompt expansion? Sebastian Gniazdowski
2023-02-13 16:39 ` Roman Perepelitsa

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).