zsh-workers
 help / color / mirror / code / Atom feed
* [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

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