zsh-users
 help / color / mirror / code / Atom feed
* emulate zsh *except* pushd related options
@ 2015-12-22  8:30 Dominik Vogt
  2015-12-23  4:57 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Vogt @ 2015-12-22  8:30 UTC (permalink / raw)
  To: Zsh Users

There's a system-wide, autoloaded script that defines a "cd"
function that needs shwordsplit to be set.  Other than that it
should revert to the default options (because it may be used by
someone else), *except* that it should not touch the pushd related
options (autopushd, pushdminus, pushdignoredups) that are needed
for cd to do its work.  Is there a (safe!) way to say "emulate zsh
but don't touch certain options"?

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany


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

* Re: emulate zsh *except* pushd related options
  2015-12-22  8:30 emulate zsh *except* pushd related options Dominik Vogt
@ 2015-12-23  4:57 ` Bart Schaefer
  2015-12-23 14:19   ` Dominik Vogt
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2015-12-23  4:57 UTC (permalink / raw)
  To: Zsh Users

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

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.


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

* Re: emulate zsh *except* pushd related options
  2015-12-23  4:57 ` Bart Schaefer
@ 2015-12-23 14:19   ` Dominik Vogt
  2015-12-23 16:31     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Vogt @ 2015-12-23 14:19 UTC (permalink / raw)
  To: zsh-users

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

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany


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

* Re: emulate zsh *except* pushd related options
  2015-12-23 14:19   ` Dominik Vogt
@ 2015-12-23 16:31     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2015-12-23 16:31 UTC (permalink / raw)
  To: Zsh Users, vogt

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

On Dec 23, 2015 6:30 AM, "Dominik Vogt" <vogt@linux.vnet.ibm.com> wrote:
>
> On Tue, Dec 22, 2015 at 08:57:47PM -0800, Bart Schaefer wrote:
>
> >
> > 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.

You can substitute

local opts
opts=( ... )
emulate -L zsh
set $opts

> > 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 should work in older zsh too, for the value of $opts above.

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

end of thread, other threads:[~2015-12-23 16:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-22  8:30 emulate zsh *except* pushd related options Dominik Vogt
2015-12-23  4:57 ` Bart Schaefer
2015-12-23 14:19   ` Dominik Vogt
2015-12-23 16:31     ` Bart Schaefer

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