Added '-o'  to set-option, which will only take effect when the value
isn't set yet. So far only added for user options.

I assumed the server runs a single thread, is that right? If not some
kind of  synchronization is needed on the region that tests if the
value is set.

On Fri, Feb 22, 2013 at 12:39 PM, Nicholas Marriott
<nicholas.marri...@gmail.com> wrote:
> Two new flags to set-option, one to "show value" and the other to say
> "only set if doesn't exist", would be fine.

Why need an option to show the value on the 'set' command?

Some more questions:

- Should this be available on non-user options?
- Is there some code style I should follow?

diff --git a/cmd-set-option.c b/cmd-set-option.c
index a09e6db..224d5e3 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -63,8 +63,8 @@ struct options_entry *cmd_set_option_choice(struct
cmd *, struct cmd_ctx *,

 const struct cmd_entry cmd_set_option_entry = {
        "set-option", "set",
-       "agqst:uw", 1, 2,
-       "[-agsquw] [-t target-session|target-window] option [value]",
+       "agoqst:uw", 1, 2,
+       "[-agosquw] [-t target-session|target-window] option [value]",
        0,
        NULL,
        NULL,
@@ -73,8 +73,8 @@ const struct cmd_entry cmd_set_option_entry = {

 const struct cmd_entry cmd_set_window_option_entry = {
        "set-window-option", "setw",
-       "agqt:u", 1, 2,
-       "[-agqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
+       "agoqt:u", 1, 2,
+       "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
        0,
        NULL,
        NULL,
@@ -187,6 +187,7 @@ cmd_set_option_user(struct cmd *self, struct
cmd_ctx *ctx, const char* optstr,
        struct session  *s;
        struct winlink  *wl;
        struct options  *oo;
+  struct options_entry *current_entry;

        if (args_has(args, 's'))
                oo = &global_options;
@@ -227,7 +228,17 @@ cmd_set_option_user(struct cmd *self, struct
cmd_ctx *ctx, const char* optstr,
                        ctx->error(ctx, "empty value");
                        return (CMD_RETURN_ERROR);
                }
-               options_set_string(oo, optstr, "%s", valstr);
+               if (args_has(args, 'o')) {
+                       if ((current_entry = options_find1(oo,
optstr)) == NULL) {
+                               options_set_string(oo, optstr, "%s", valstr);
+                       } else {
+                               if (!args_has(args, 'q'))
+                                       ctx->print(ctx, "already set:
%s -> %s", optstr, current_entry->str);
+                               return (CMD_RETURN_NORMAL);
+                       }
+               } else {
+                       options_set_string(oo, optstr, "%s", valstr);
+               }
                if (!args_has(args, 'q'))
                        ctx->info(ctx, "set option: %s -> %s", optstr, valstr);
        }

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to