* Handling of *ARGZERO options, for Zsh <= 5.3
@ 2018-01-02 10:17 Sebastian Gniazdowski
2018-01-02 16:57 ` dana
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Sebastian Gniazdowski @ 2018-01-02 10:17 UTC (permalink / raw)
To: zsh-workers
Hello,
I want to filter out $0 value if it contains path to Zsh binary:
% echo ${${0:#$ZSH_ARGZERO}:-${(%):-%N}}
Above works, but for Zsh 5.3 and above. Is it possible to do this with earlier Zshells?
The goal is to have choice to avoid %N, because it cannot be altered, and to solve problems caused by *ARGZERO options. Altering $0 would allow to do `eval "$(<script)"', which can be faster. I'm actually doing a bit more, details are on http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
2018-01-02 10:17 Handling of *ARGZERO options, for Zsh <= 5.3 Sebastian Gniazdowski
@ 2018-01-02 16:57 ` dana
2018-01-02 19:35 ` Bart Schaefer
[not found] ` <etPan.5a4bdf5d.6db8c70b.13d7@AirmailxGenerated.am>
2018-01-02 19:25 ` Eric Cook
[not found] ` <etPan.5a4bbc41.719c42d6.13d7@AirmailxGenerated.am>
2 siblings, 2 replies; 9+ messages in thread
From: dana @ 2018-01-02 16:57 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: zsh-workers
On 2 Jan 2018, at 04:17, Sebastian Gniazdowski <psprint@zdharma.org> wrote:
>I want to filter out $0 value if it contains path to Zsh binary:
A lot of the time you won't have the path to the zsh binary; it will often just
be the base name:
% print $ZSH_ARGZERO
zsh
Even when you have a path you might need to deal with symlinks, &c. On mine
sometimes i'll have /usr/local/bin/zsh and other times it'll have been resolved
to /usr/local/Cellar/zsh/x.y.z/bin/zsh.
On 2 Jan 2018, at 04:17, Sebastian Gniazdowski <psprint@zdharma.org> wrote:
>Above works, but for Zsh 5.3 and above. Is it possible to do this with earlier Zshells?
If the problem is ZSH_ARGZERO, shouldn't this work in like 5.0+?
() {
setopt local_options posix_argzero
MY_ARGZERO=$0
}
dana
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
2018-01-02 10:17 Handling of *ARGZERO options, for Zsh <= 5.3 Sebastian Gniazdowski
2018-01-02 16:57 ` dana
@ 2018-01-02 19:25 ` Eric Cook
2018-01-04 2:02 ` Bart Schaefer
[not found] ` <etPan.5a4bbc41.719c42d6.13d7@AirmailxGenerated.am>
2 siblings, 1 reply; 9+ messages in thread
From: Eric Cook @ 2018-01-02 19:25 UTC (permalink / raw)
To: zsh-workers
Weird how the prompting, calender, zftp and completion system all work with fpath
and autoloading, yet `plugins' somehow need to depend on the exact location
of files to bootstrap themselves.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
2018-01-02 16:57 ` dana
@ 2018-01-02 19:35 ` Bart Schaefer
[not found] ` <etPan.5a4bdf5d.6db8c70b.13d7@AirmailxGenerated.am>
1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2018-01-02 19:35 UTC (permalink / raw)
To: dana; +Cc: Sebastian Gniazdowski, zsh-workers
On Tue, Jan 2, 2018 at 8:57 AM, dana <dana@dana.is> wrote:
>
> If the problem is ZSH_ARGZERO, shouldn't this work in like 5.0+?
>
> () {
> setopt local_options posix_argzero
> MY_ARGZERO=$0
> }
For considerably older (but still not the oldest) zsh you can use
$funcfiletrace:
zmodload zsh/parameter
print -r -- ${ZSH_ARGZERO:=${${funcfiletrace[-1]}[(ws/:/)1]}}
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
[not found] ` <etPan.5a4bbc41.719c42d6.13d7@AirmailxGenerated.am>
@ 2018-01-03 5:08 ` Sebastian Gniazdowski
0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Gniazdowski @ 2018-01-03 5:08 UTC (permalink / raw)
To: dana; +Cc: zsh-workers
On 2 Jan 2018 at 17:57:26, dana (dana@dana.is) wrote:
> If the problem is ZSH_ARGZERO, shouldn't this work in like 5.0+?
>
> () {
> setopt local_options posix_argzero
> MY_ARGZERO=$0
> }
I should be able to use this, by running it in plugin manager, and setting ZSH_BINARY or ZSH_BIN_PATH, so that this var can then be used in substitution, thanks. Although overall rather bad news, because plugins like z-sy-h can be just sourced. Someone with source-only setup (no p-m) could run such snippet himself, though. Kinda hard that Zsh doesn't set this information.
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
[not found] ` <etPan.5a4bdf5d.6db8c70b.13d7@AirmailxGenerated.am>
@ 2018-01-03 5:14 ` Sebastian Gniazdowski
2018-01-03 5:27 ` dana
0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Gniazdowski @ 2018-01-03 5:14 UTC (permalink / raw)
To: Bart Schaefer, dana; +Cc: zsh-workers
On 2 stycznia 2018 at 20:35:33, Bart Schaefer (schaefer@brasslantern.com) wrote:
> On Tue, Jan 2, 2018 at 8:57 AM, dana wrote:
> >
> > If the problem is ZSH_ARGZERO, shouldn't this work in like 5.0+?
> >
> > () {
> > setopt local_options posix_argzero
> > MY_ARGZERO=$0
> > }
>
> For considerably older (but still not the oldest) zsh you can use
> $funcfiletrace:
>
> zmodload zsh/parameter
> print -r -- ${ZSH_ARGZERO:=${${funcfiletrace[-1]}[(ws/:/)1]}}
I'm always little afraid using this in non-debug code. Pitty that there's no at least prompt escape code (zsh var would be best) that would return path to binary.
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
2018-01-03 5:14 ` Sebastian Gniazdowski
@ 2018-01-03 5:27 ` dana
2018-01-03 7:14 ` dana
0 siblings, 1 reply; 9+ messages in thread
From: dana @ 2018-01-03 5:27 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Bart Schaefer, zsh-workers
On 2 Jan 2018, at 23:14, Sebastian Gniazdowski <psprint@zdharma.org> wrote:
>Pitty that there's no at least prompt escape code (zsh var would be best) that would return path to binary.
It's slightly irritating because there's no single cross-platform way to do it.
On Linux you can use /proc/self/exe, and some BSDs have a similar mechanism, but
then there's macOS and Solaris and AIX and so on.
I have wanted this feature in the past myself, though, so i would definitely be
in favour of a ZSH_EXECUTABLE_PATH or something. In fact i may look into it now
that you bring it up.
dana
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
2018-01-03 5:27 ` dana
@ 2018-01-03 7:14 ` dana
0 siblings, 0 replies; 9+ messages in thread
From: dana @ 2018-01-03 7:14 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Bart Schaefer, zsh-workers
On 2 Jan 2018, at 23:27, dana <dana@dana.is> wrote:
>I have wanted this feature in the past myself, though, so i would definitely be
>in favour of a ZSH_EXECUTABLE_PATH or something. In fact i may look into it now
>that you bring it up.
This is how Perl handles it:
https://github.com/Perl/perl5/blob/3d10fa085102a79a96d9e335384c3f56f3b6b9cc/caretx.c
Seems rather tedious
dana
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Handling of *ARGZERO options, for Zsh <= 5.3
2018-01-02 19:25 ` Eric Cook
@ 2018-01-04 2:02 ` Bart Schaefer
0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2018-01-04 2:02 UTC (permalink / raw)
To: zsh-workers
On Tue, Jan 2, 2018 at 11:25 AM, Eric Cook <llua@gmx.com> wrote:
> Weird how the prompting, calender, zftp and completion system all work with fpath
> and autoloading, yet `plugins' somehow need to depend on the exact location
> of files to bootstrap themselves.
The thought is that plugins might be installed in non-standard
locations and might have multiple dependent files, so it's easier if
you don't have to put them all in a previously-known fpath.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-01-04 2:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-02 10:17 Handling of *ARGZERO options, for Zsh <= 5.3 Sebastian Gniazdowski
2018-01-02 16:57 ` dana
2018-01-02 19:35 ` Bart Schaefer
[not found] ` <etPan.5a4bdf5d.6db8c70b.13d7@AirmailxGenerated.am>
2018-01-03 5:14 ` Sebastian Gniazdowski
2018-01-03 5:27 ` dana
2018-01-03 7:14 ` dana
2018-01-02 19:25 ` Eric Cook
2018-01-04 2:02 ` Bart Schaefer
[not found] ` <etPan.5a4bbc41.719c42d6.13d7@AirmailxGenerated.am>
2018-01-03 5:08 ` Sebastian Gniazdowski
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).