Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Issue trying to save and restore options
Sorry for the late reply.
Thanks for the help Daniel. Using redirection indeed works.
Here is what I used, in case it is useful to others:
OPTS_BACKUP=$(mktemp)
set +o > "$OPTS_BACKUP"
set -x
# More stuff
set +vx
RESTORE_STATE=$(cat "$OPTS_BACKUP")
eval "$RESTORE_STATE"
On Wed, May 23, 2018 at 11:31 AM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
wrote:
> Alexandre Rames wrote on Wed, 23 May 2018 08:54 -0700:
> > username% OPTS=$(set +o)
>
> The 'set' runs inside a subshell so it sees different options:
>
> [[[
> % set +o >1
> % printf '%s' "$(set +o)" >2
> % diff 1 2
> 116c116
> < set -o monitor
> ---
> > set +o monitor
> 177c177
> < set -o zle
> ---
> > set +o zle
> ]]]
>
> (The 'zle' option controls whether the line editor is enabled.)
>
> So, you could try capturing the output of 'set +o' using redirections
> rather than command substitutions; that should work and remain shell-
> agnostic. (If you want a shell-specific solutions there are other ways,
> e.g., check $ZSH_VERSION and then use ${(kv)options} to save the
> values.)
>
> As to whether the behaviour of +o in a subshell should be changed, I'll
> leave that for others.
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author