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

Re: Using script to find location of global rcs files.

On 26 Jan 2019, at 12:10, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> 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


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