At 14:49 +0100 18 Aug 2013, Nicholas Marriott <nicholas.marri...@gmail.com> 
wrote:
>How do you show the difference between an empty value and one to be 
>unset then?

An empty value would still have a pair of single quotes after the equal 
sign, an unset value would not.

But, I'm now thinking that I should change it to emit "unset var" for 
the latter case.  Here's a patch on top of the previous one to 
accomplish that.  If these changes get applied, it may make sense to 
squash the two changes into one.

------ 8< -------

Subject: [PATCH] Unset variables in showenv -s output

In order for showenv -s output to truly replicate the effect if eval'd
by a shell, variables that aren't set need to be explicitly unset not
just set to an empty value.
---
 cmd-show-environment.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/cmd-show-environment.c b/cmd-show-environment.c
index 31058af..a49a1c2 100644
--- a/cmd-show-environment.c
+++ b/cmd-show-environment.c
@@ -48,10 +48,12 @@ sh_environment( struct cmd_q *cmdq, struct environ_entry 
*envent )
        size_t  len;
        size_t  bufsize = 128;
 
-       val = buf = xmalloc(bufsize);
-
-       if (envent->value != NULL) {
+       if (envent->value == NULL) {
+               cmdq_print(cmdq, "unset %s", envent->name);
+       }
+       else {
                old = envent->value;
+               val = buf = xmalloc(bufsize);
                *(val++) = '\'';
                len = 1;
 
@@ -78,12 +80,11 @@ sh_environment( struct cmd_q *cmdq, struct environ_entry 
*envent )
                        ++len;
                }
                *(val++) = '\'';
-       }
-
-       *val = 0;
-       cmdq_print(cmdq, "%s=%s", envent->name, buf);
+               *val = 0;
 
-       free(buf);
+               cmdq_print(cmdq, "%s=%s", envent->name, buf);
+               free(buf);
+       }
 }
 
 enum cmd_retval
-- 
1.7.10.4


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to