zsh-users
 help / color / mirror / code / Atom feed
* Disabling an option for a single statement
@ 2022-08-22 17:46 Zach Riggle
  2022-08-23  4:18 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Zach Riggle @ 2022-08-22 17:46 UTC (permalink / raw)
  To: Zsh Users

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

Hello all!

It's not uncommon that I want to disable a specific option (in my case,
cdablevars) for a single statement.

Currently, I do something like:

( setopt no_cdable_vars; echo "${(D)variable}" )


Or use an anonymous function

() { setopt local_options un_cdable_vars; echo "${(D)variable}"


Are there any easier ways to achieve this?

*Zach Riggle*

[-- Attachment #2: Type: text/html, Size: 871 bytes --]

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

* Re: Disabling an option for a single statement
  2022-08-22 17:46 Disabling an option for a single statement Zach Riggle
@ 2022-08-23  4:18 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-08-23  4:18 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

On Mon, Aug 22, 2022 at 10:46 AM Zach Riggle <zachriggle@gmail.com> wrote:
>
> It's not uncommon that I want to disable a specific option (in my case, cdablevars) for a single statement.

There's not really a better way in general.  There are of course the
noglob and nocorrect "precommand modifiers" which have this effect for
the GLOB and CORRECT options, but it's not generalized.

You can sort of make it work with something like

alias nocdv='() { setopt localoptions nocdablevars; "$@" } '

but that doesn't affect things that happen during argument
interpretation, such as potentially ${(D)var}, so there are several
options for which using an alias is not very helpful.


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

end of thread, other threads:[~2022-08-23  4:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22 17:46 Disabling an option for a single statement Zach Riggle
2022-08-23  4:18 ` 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).