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

Re: emulate zsh *except* pushd related options

On Tue, Dec 22, 2015 at 08:57:47PM -0800, Bart Schaefer wrote:
> On Dec 22,  9:30am, Dominik Vogt wrote:
> }
> } Is there a (safe!) way to say "emulate zsh but don't touch certain options"?
> The "emulate" command accepts the same "-o optionn_name" (or "+o") as
> shell startup, so you can do
>     emulate -L zsh -o shwordsplit ...

Unfortunately my zsh is too old for that.

> For your specific use case, the current state of the pushd and cd options
> can be enumerated this way:
>     ${(Oa)${${(kv)options[(I)*pushd*|cd*|*cd]/off/+o}/on/-o}}
> That won't work in general because some options have "on" as a substring
> of the option name.
> So if your autoloaded function begins with:
>     emulate -L zsh -o shwordsplit \
>       ${(Oa)${${(kv)options[(I)*pushd*|cd*|*cd]/off/+o}/on/-o}}
> you should get what you want.

So I'll do something like this:

  PRESERVE_OPTS=($(setopt | grep "\(^cd\)\|\(cd$\)\|\(pushd\)"))
  emulate zsh
  setopt shwordsplit "$PRESERVE_OPTS[@]"

I tried to get rid of the grep with parameter expansion but failed
to understand the syntax.  As far as I understand, this should do
the job, but it doesn't:

  pat='^(*pushd|cd*|*cd)'; PRESERVED_OPTS=(${~$(setopt)//${~pat}/})

It deletes *all* words, not just the ones not matching
(*pushd|cd*|*cd).  (Actually the parentheses seem not to work as
described for filename generation at all.)


Dominik ^_^  ^_^


Dominik Vogt
IBM Germany

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