Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham
	autolearn_force=no version=3.4.1
Message-ID: <56D113E0.4090609@inlv.org>
Date: Sat, 27 Feb 2016 04:11:28 +0100
From: Martijn Dekker <martijn@inlv.org>
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
MIME-Version: 1.0
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] make 'set +o' useful and POSIX compatible
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Seq: zsh-workers 38036

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");

