zsh-users
 help / color / mirror / code / Atom feed
* Using script to find location of global rcs files.
@ 2019-01-26 12:55 Jim
  2019-01-26 18:10 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Jim @ 2019-01-26 12:55 UTC (permalink / raw)
  To: zsh

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

Hi everyone,

The manual states that the location of the global rcs files defaults to
¨/etc/¨, but on the distributions I´m using the default is ¨/etc/zsh/¨. I
want
to determine this location in a script, but so far I haven´t found a ¨zsh¨
option or variable to do this. I currently check the results of:

    strings ${whence zsh) | egrep -i ´/etc/.*z[spl].*[tvecn]´

Does anyone know a better way of determining the location of ¨etcdir¨?

Thanks,

Jim

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

* Re: Using script to find location of global rcs files.
  2019-01-26 12:55 Using script to find location of global rcs files Jim
@ 2019-01-26 18:10 ` Peter Stephenson
  2019-01-26 18:38   ` dana
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2019-01-26 18:10 UTC (permalink / raw)
  To: zsh

On Sat, 2019-01-26 at 06:55 -0600, Jim wrote:
> Hi everyone,
> 
> The manual states that the location of the global rcs files defaults to
> ¨/etc/¨, but on the distributions I´m using the default is ¨/etc/zsh/¨. I
> want
> to determine this location in a script, but so far I hav en´t found a ¨zsh¨
> option or variable to do this. I currently check the results of:
> 
>     strings ${whence zsh) | egrep -i ´/etc/.*z[spl].*[tvecn]´
> 
> Does anyone know a better way of determining the location of ¨etcdir¨?

No, I'm afraid I can't see a better way --- the value is baked into the
shell but without exposing the value at the shell language level, nor do
we install any zsh-config script that might tell you.  This is ancient
stuff from before configuration became something more than just a dark
art...

pws


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

* Re: Using script to find location of global rcs files.
  2019-01-26 18:10 ` Peter Stephenson
@ 2019-01-26 18:38   ` dana
  2019-01-27 13:11     ` Jim
  0 siblings, 1 reply; 5+ messages in thread
From: dana @ 2019-01-26 18:38 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh, linuxtechguy

On 26 Jan 2019, at 12:10, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
>No, I'm afraid I can't see a better way --- the value is baked into the
>shell but without exposing the value at the shell language level

I was also going to point out that zsh itself doesn't even know anything about
the 'etcdir' configure variable — the configure script uses that to build the
default paths for the global rc files, all of which can be overridden
independently, and only those complete file paths are used by zsh itself. So
you can't actually trust that there's just one directory that all of them live
in — though i assume that's usually the case in practice.

*If* you're OK with making the following assumptions...

* the files *do* all live in the same directory
* at least one of the files exists on the system
* the zsh in your PATH is the shell you're actually running (zsh itself
  doesn't provide a reliable way to find the path to the running shell binary;
  in some cases $ZSH_ARGZERO works well enough, but not in a script)

... then i guess you could do this?

  etcdir=${${${(f)"$( ZDOTDIR=/dev/null zsh --source-trace -ilnpc : 2>&1 )"}[1]#+}:h}

It's not great though

dana


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

* Re: Using script to find location of global rcs files.
  2019-01-26 18:38   ` dana
@ 2019-01-27 13:11     ` Jim
  2019-01-27 14:32       ` dana
  0 siblings, 1 reply; 5+ messages in thread
From: Jim @ 2019-01-27 13:11 UTC (permalink / raw)
  To: dana, zsh

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

Thanks.  Hadn´t used that combination of options before, but learned
something new.  To bad zsh doesn´t have an option to display
the build information, but I leave it to others more qualified to say if
that
is possible or practical.

On Sat, Jan 26, 2019 at 12:38 PM dana <dana@dana.is> wrote:

> On 26 Jan 2019, at 12:10, Peter Stephenson <p.w.stephenson@ntlworld.com>
> wrote:
> >No, I'm afraid I can't see a better way --- the value is baked into the
> >shell but without exposing the value at the shell language level
>
> I was also going to point out that zsh itself doesn't even know anything
> about
> the 'etcdir' configure variable — the configure script uses that to build
> the
> default paths for the global rc files, all of which can be overridden
> independently, and only those complete file paths are used by zsh itself.
> So
> you can't actually trust that there's just one directory that all of them
> live
> in — though i assume that's usually the case in practice.
>
> *If* you're OK with making the following assumptions...
>
> * the files *do* all live in the same directory
> * at least one of the files exists on the system
> * the zsh in your PATH is the shell you're actually running (zsh itself
>   doesn't provide a reliable way to find the path to the running shell
> binary;
>   in some cases $ZSH_ARGZERO works well enough, but not in a script)



> ... then i guess you could do this?
>
>   etcdir=${${${(f)"$( ZDOTDIR=/dev/null zsh --source-trace -ilnpc : 2>&1
> )"}[1]#+}:h}
>

Had some trouble with the above line of code when there is only one global
file,
It only returned a ¨.¨. Assuming I typed it correctly.
The following appears to work for one or more global files.

etcdir=${${${(z)${${(f)"$( ZDOTDIR=/dev/null zsh --source-trace -ilnpc :
2>&1 )"}#+}}[1]}:h}

Hopefully no typos here either. Not sure I transitioned correctly between
array
and scalar.

It's not great though
>
> dana
>

 Again, thanks.

Jim

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

* Re: Using script to find location of global rcs files.
  2019-01-27 13:11     ` Jim
@ 2019-01-27 14:32       ` dana
  0 siblings, 0 replies; 5+ messages in thread
From: dana @ 2019-01-27 14:32 UTC (permalink / raw)
  To: linuxtechguy; +Cc: zsh

On 27 Jan 2019, at 07:11, Jim <linux.tech.guy@gmail.com> wrote:
>Had some trouble with the above line of code when there is only one global file,
>It only returned a ¨.¨. Assuming I typed it correctly.

Oh yeah, i always forget. In recent versions of zsh (5.4+ i think) you can use
(Af) instead of (f) to fix that

dana


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

end of thread, other threads:[~2019-01-27 14:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-26 12:55 Using script to find location of global rcs files Jim
2019-01-26 18:10 ` Peter Stephenson
2019-01-26 18:38   ` dana
2019-01-27 13:11     ` Jim
2019-01-27 14:32       ` dana

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