* [PATCH] make 'set +o' useful and POSIX compatible
@ 2016-02-27 3:11 Martijn Dekker
2016-02-27 13:47 ` Martijn Dekker
2016-02-28 5:27 ` Bart Schaefer
0 siblings, 2 replies; 3+ messages in thread
From: Martijn Dekker @ 2016-02-27 3:11 UTC (permalink / raw)
To: Zsh hackers list
The command 'set -o' shows the current shell options in an unspecified
format. Less well-known is the variant 'set +o', which should output the
current shell options "in a format that is suitable for reinput to the
shell as commands that achieve the same options settings".[*]
That means it should be possible to do
save_options=$(set +o)
then change some options, then later restore the shell options with
eval "$save_options"
On zsh (as well as all pdksh variants), 'set +o' is currently inadequate
for that purpose because it only outputs the currently active shell
options, and not the inactive ones.
The zshbuiltins(1) man page also implies that 'set +o' should print the
complete current option states.
This is my first time trying my hand at a zsh patch.
Thanks,
- M.
[*]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_03
(scroll down to '+o')
diff --git a/Src/options.c b/Src/options.c
index 17c46c3..18619c8 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -847,9 +847,10 @@ printoptionnodestate(HashNode hn, int hadplus)
int optno = on->optno;
if (hadplus) {
- if (defset(on, emulation) != isset(optno))
- printf("set -o %s%s\n", defset(on, emulation) ?
- "no" : "", on->node.nam);
+ printf("set %co %s%s\n",
+ defset(on, emulation) != isset(optno) ? '-' : '+',
+ defset(on, emulation) ? "no" : "",
+ on->node.nam);
} else {
if (defset(on, emulation))
printf("no%-19s %s\n", on->node.nam, isset(optno) ? "off" : "on");
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] make 'set +o' useful and POSIX compatible
2016-02-27 3:11 [PATCH] make 'set +o' useful and POSIX compatible Martijn Dekker
@ 2016-02-27 13:47 ` Martijn Dekker
2016-02-28 5:27 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Martijn Dekker @ 2016-02-27 13:47 UTC (permalink / raw)
To: Zsh hackers list
Martijn Dekker schreef op 27-02-16 om 04:11:
> That means it should be possible to do
>
> save_options=$(set +o)
>
> then change some options, then later restore the shell options with
>
> eval "$save_options"
Hmm. There is still a problem with this.
Two options are turned off in subshells, so the command substitution
subshell $(set +o) will not store the output you want.
$ set +o >1
$ (set +o) >2
$ diff 1 2
116c116
< set -o monitor
---
> set +o monitor
177c177
< set -o zle
---
> set +o zle
This only seems to be relevant on interactive shells though, as
'monitor' and 'zle' are turned off in scripts.
- M.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] make 'set +o' useful and POSIX compatible
2016-02-27 3:11 [PATCH] make 'set +o' useful and POSIX compatible Martijn Dekker
2016-02-27 13:47 ` Martijn Dekker
@ 2016-02-28 5:27 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2016-02-28 5:27 UTC (permalink / raw)
To: Zsh hackers list
On Feb 27, 4:11am, Martijn Dekker wrote:
}
} On zsh (as well as all pdksh variants), 'set +o' is currently inadequate
} for that purpose because it only outputs the currently active shell
} options, and not the inactive ones.
This is almost certainly not coincidental. In the early years of zsh
development, ksh was only available on closed-source UNIX platforms,
so any ksh-isms that were incorporated were either derived from reading
man pages (which led by misunderstanding to the "coproc" command and
an unusual syntax for writing base-N values in arithmetic context) or
borrowed from pdksh.
I don't see any reason not to accept this patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-28 5:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-27 3:11 [PATCH] make 'set +o' useful and POSIX compatible Martijn Dekker
2016-02-27 13:47 ` Martijn Dekker
2016-02-28 5:27 ` 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).