The branch, master has been updated
       via  36fe146a74230e5072c367a9987b6c021320c0dd (commit)
       via  caa29af2a944a7d7232a55f1a4142095896956ce (commit)
      from  0f31d231db7502a6470fea4db9c3bf9aa48c1fd5 (commit)

- Log -----------------------------------------------------------------
commit 36fe146a74230e5072c367a9987b6c021320c0dd
Author: Nicholas Marriott <nicholas.marri...@gmail.com>
Commit: Nicholas Marriott <nicholas.marri...@gmail.com>

    Fix choose-tree usage.
---
 cmd-choose-tree.c |    2 +-
 tmux.1            |    4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c
index d1f106e..0279663 100644
--- a/cmd-choose-tree.c
+++ b/cmd-choose-tree.c
@@ -37,7 +37,7 @@ enum cmd_retval       cmd_choose_tree_exec(struct cmd *, 
struct cmd_ctx *);
 const struct cmd_entry cmd_choose_tree_entry = {
        "choose-tree", NULL,
        "S:W:swub:c:t:", 0, 1,
-       "[-swu] [-b session-template] [-c window template] [-S format] " \
+       "[-suw] [-b session-template] [-c window template] [-S format] " \
        "[-W format] " CMD_TARGET_WINDOW_USAGE,
        0,
        NULL,
diff --git a/tmux.1 b/tmux.1
index d03843e..eba13be 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1129,9 +1129,7 @@ section.
 This command works only if at least one client is attached.
 .It Xo
 .Ic choose-tree
-.Op Fl s
-.Op Fl w
-.Op Fl u
+.Op Fl suw
 .Op Fl b Ar session-template
 .Op Fl c Ar window-template
 .Op Fl S Ar format


commit caa29af2a944a7d7232a55f1a4142095896956ce
Author: Nicholas Marriott <nicholas.marri...@gmail.com>
Commit: Nicholas Marriott <nicholas.marri...@gmail.com>

    Add user options, prefixed with @. May be set to any arbitrary string.
---
 cmd-set-option.c   |   66 +++++++++++++++++++++++++++++++++++++-
 cmd-show-options.c |   90 +++++++++++++++++++++++++++++++++++++++-------------
 tmux.1             |   13 +++++++
 3 files changed, 146 insertions(+), 23 deletions(-)

diff --git a/cmd-set-option.c b/cmd-set-option.c
index f995625..a09e6db 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -27,7 +27,10 @@
  * Set an option.
  */
 
-enum cmd_retval         cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
+enum cmd_retval        cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
+
+enum cmd_retval        cmd_set_option_user(struct cmd *, struct cmd_ctx *,
+                   const char *, const char *);
 
 int    cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
            const struct options_table_entry *, struct options *,
@@ -102,6 +105,10 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
        else
                valstr = args->argv[1];
 
+       /* Is this a user option? */
+       if (*optstr == '@')
+               return (cmd_set_option_user(self, ctx, optstr, valstr));
+
        /* Find the option entry, try each table. */
        table = oe = NULL;
        if (options_table_find(optstr, &table, &oe) != 0) {
@@ -171,6 +178,63 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
        return (CMD_RETURN_NORMAL);
 }
 
+/* Set user option. */
+enum cmd_retval
+cmd_set_option_user(struct cmd *self, struct cmd_ctx *ctx, const char* optstr,
+    const char *valstr)
+{
+       struct args     *args = self->args;
+       struct session  *s;
+       struct winlink  *wl;
+       struct options  *oo;
+
+       if (args_has(args, 's'))
+               oo = &global_options;
+       else if (args_has(self->args, 'w') ||
+           self->entry == &cmd_set_window_option_entry) {
+               if (args_has(self->args, 'g'))
+                       oo = &global_w_options;
+               else {
+                       wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
+                       if (wl == NULL)
+                               return (CMD_RETURN_ERROR);
+                       oo = &wl->window->options;
+               }
+       } else {
+               if (args_has(self->args, 'g'))
+                       oo = &global_s_options;
+               else {
+                       s = cmd_find_session(ctx, args_get(args, 't'), 0);
+                       if (s == NULL)
+                               return (CMD_RETURN_ERROR);
+                       oo = &s->options;
+               }
+       }
+
+       if (args_has(args, 'u')) {
+               if (options_find1(oo, optstr) == NULL) {
+                       ctx->error(ctx, "unknown option: %s", optstr);
+                       return (CMD_RETURN_ERROR);
+               }
+               if (valstr != NULL) {
+                       ctx->error(ctx, "value passed to unset option: %s",
+                           optstr);
+                       return (CMD_RETURN_ERROR);
+               }
+               options_remove(oo, optstr);
+       } else {
+               if (valstr == NULL) {
+                       ctx->error(ctx, "empty value");
+                       return (CMD_RETURN_ERROR);
+               }
+               options_set_string(oo, optstr, "%s", valstr);
+               if (!args_has(args, 'q'))
+                       ctx->info(ctx, "set option: %s -> %s", optstr, valstr);
+       }
+       return (CMD_RETURN_NORMAL);
+}
+
+
 /* Unset an option. */
 int
 cmd_set_option_unset(struct cmd *self, struct cmd_ctx *ctx,
diff --git a/cmd-show-options.c b/cmd-show-options.c
index d396b10..62cc7e0 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -29,6 +29,11 @@
 
 enum cmd_retval         cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
 
+enum cmd_retval        cmd_show_options_one(struct cmd *, struct cmd_ctx *,
+                   struct options *);
+enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_ctx *,
+                   const struct options_table_entry *, struct options *);
+
 const struct cmd_entry cmd_show_options_entry = {
        "show-options", "show",
        "gst:vw", 0, 1,
@@ -53,12 +58,10 @@ enum cmd_retval
 cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
 {
        struct args                             *args = self->args;
-       const struct options_table_entry        *table, *oe;
        struct session                          *s;
        struct winlink                          *wl;
+       const struct options_table_entry        *table;
        struct options                          *oo;
-       struct options_entry                    *o;
-       const char                              *optval;
 
        if (args_has(self->args, 's')) {
                oo = &global_options;
@@ -86,35 +89,78 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
                }
        }
 
-       if (args->argc != 0) {
-               table = oe = NULL;
-               if (options_table_find(args->argv[0], &table, &oe) != 0) {
-                       ctx->error(ctx, "ambiguous option: %s", args->argv[0]);
-                       return (CMD_RETURN_ERROR);
-               }
-               if (oe == NULL) {
+       if (args->argc != 0)
+               return (cmd_show_options_one(self, ctx, oo));
+       else
+               return (cmd_show_options_all(self, ctx, table, oo));
+}
+
+enum cmd_retval
+cmd_show_options_one(struct cmd *self, struct cmd_ctx *ctx,
+    struct options *oo)
+{
+       struct args                             *args = self->args;
+       const struct options_table_entry        *table, *oe;
+       struct options_entry                    *o;
+       const char                              *optval;
+
+       if (*args->argv[0] == '@') {
+               if ((o = options_find1(oo, args->argv[0])) == NULL) {
                        ctx->error(ctx, "unknown option: %s", args->argv[0]);
                        return (CMD_RETURN_ERROR);
                }
+               if (args_has(self->args, 'v'))
+                       ctx->print(ctx, "%s", o->str);
+               else
+                       ctx->print(ctx, "%s \"%s\"", o->name, o->str);
+               return (CMD_RETURN_NORMAL);
+       }
+
+       table = oe = NULL;
+       if (options_table_find(args->argv[0], &table, &oe) != 0) {
+               ctx->error(ctx, "ambiguous option: %s", args->argv[0]);
+               return (CMD_RETURN_ERROR);
+       }
+       if (oe == NULL) {
+               ctx->error(ctx, "unknown option: %s", args->argv[0]);
+               return (CMD_RETURN_ERROR);
+       }
+       if ((o = options_find1(oo, oe->name)) == NULL)
+               return (CMD_RETURN_NORMAL);
+       optval = options_table_print_entry(oe, o, args_has(self->args, 'v'));
+       if (args_has(self->args, 'v'))
+               ctx->print(ctx, "%s", optval);
+       else
+               ctx->print(ctx, "%s %s", oe->name, optval);
+       return (CMD_RETURN_NORMAL);
+}
+
+enum cmd_retval
+cmd_show_options_all(struct cmd *self, struct cmd_ctx *ctx,
+    const struct options_table_entry *table, struct options *oo)
+{
+       const struct options_table_entry        *oe;
+       struct options_entry                    *o;
+       const char                              *optval;
+
+       RB_FOREACH(o, options_tree, &oo->tree) {
+               if (*o->name == '@') {
+                       if (args_has(self->args, 'v'))
+                               ctx->print(ctx, "%s", o->str);
+                       else
+                               ctx->print(ctx, "%s \"%s\"", o->name, o->str);
+               }
+       }
+
+       for (oe = table; oe->name != NULL; oe++) {
                if ((o = options_find1(oo, oe->name)) == NULL)
-                       return (CMD_RETURN_NORMAL);
+                       continue;
                optval = options_table_print_entry(oe, o,
                    args_has(self->args, 'v'));
                if (args_has(self->args, 'v'))
                        ctx->print(ctx, "%s", optval);
                else
                        ctx->print(ctx, "%s %s", oe->name, optval);
-       } else {
-               for (oe = table; oe->name != NULL; oe++) {
-                       if ((o = options_find1(oo, oe->name)) == NULL)
-                               continue;
-                       optval = options_table_print_entry(oe, o,
-                           args_has(self->args, 'v'));
-                       if (args_has(self->args, 'v'))
-                               ctx->print(ctx, "%s", optval);
-                       else
-                               ctx->print(ctx, "%s %s", oe->name, optval);
-               }
        }
 
        return (CMD_RETURN_NORMAL);
diff --git a/tmux.1 b/tmux.1
index 2773de8..d03843e 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1943,6 +1943,19 @@ All window options are documented with the
 .Ic set-window-option
 command.
 .Pp
+.Nm
+also supports user options which are prefixed with a
+.Ql \&@ .
+User options may have any name, so long as it is prefixed with
+.Ql \&@,
+and be set to any string.
+For example
+.Bd -literal -offset indent
+$ tmux setw -q @foo "abc123"
+$ tmux showw -v @foo
+abc123
+.Ed
+.Pp
 Commands which set options are as follows:
 .Bl -tag -width Ds
 .It Xo Ic set-option


-----------------------------------------------------------------------

Summary of changes:
 cmd-choose-tree.c  |    2 +-
 cmd-set-option.c   |   66 +++++++++++++++++++++++++++++++++++++-
 cmd-show-options.c |   90 +++++++++++++++++++++++++++++++++++++++-------------
 tmux.1             |   17 ++++++++--
 4 files changed, 148 insertions(+), 27 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to