This teaches the choose/list commands to use -F.
---
 trunk/cmd-choose-session.c |   33 +++++++++++++++++----------------
 trunk/cmd-list-sessions.c  |   10 ++--------
 2 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/trunk/cmd-choose-session.c b/trunk/cmd-choose-session.c
index d3e5354..d6b7939 100644
--- a/trunk/cmd-choose-session.c
+++ b/trunk/cmd-choose-session.c
@@ -33,8 +33,8 @@ void  cmd_choose_session_free(void *);
 
 const struct cmd_entry cmd_choose_session_entry = {
        "choose-session", NULL,
-       "t:", 0, 1,
-       CMD_TARGET_WINDOW_USAGE " [template]",
+       "F:t:", 0, 1,
+       CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
        0,
        NULL,
        NULL,
@@ -53,9 +53,10 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx 
*ctx)
        struct cmd_choose_session_data  *cdata;
        struct winlink                  *wl;
        struct session                  *s;
-       struct session_group            *sg;
-       u_int                            idx, sgidx, cur;
-       char                             tmp[64];
+       struct format_tree              *ft;
+       const char                      *template;
+       char                            *line;
+       u_int                            idx, cur;
 
        if (ctx->curclient == NULL) {
                ctx->error(ctx, "must be run interactively");
@@ -68,24 +69,24 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx 
*ctx)
        if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
                return (0);
 
+       if ((template = args_get(args, 'F')) == NULL)
+               template = DEFAULT_SESSION_TEMPLATE;
+
        cur = idx = 0;
        RB_FOREACH(s, sessions, &sessions) {
                if (s == ctx->curclient->session)
                        cur = idx;
                idx++;
 
-               sg = session_group_find(s);
-               if (sg == NULL)
-                       *tmp = '\0';
-               else {
-                       sgidx = session_group_index(sg);
-                       xsnprintf(tmp, sizeof tmp, " (group %u)", sgidx);
-               }
+               ft = format_create();
+               format_add(ft, "line", "%u", idx);
+               format_session(ft, s);
+
+               line = format_expand(ft, template);
+               window_choose_add(wl->window->active, s->idx, "%s", line);
+               xfree(line);
 
-               window_choose_add(wl->window->active, s->idx,
-                   "%s: %u windows [%ux%u]%s%s", s->name,
-                   winlink_count(&s->windows), s->sx, s->sy,
-                   tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
+               format_free(ft);
        }
 
        cdata = xmalloc(sizeof *cdata);
diff --git a/trunk/cmd-list-sessions.c b/trunk/cmd-list-sessions.c
index 1ddc574..d43baf4 100644
--- a/trunk/cmd-list-sessions.c
+++ b/trunk/cmd-list-sessions.c
@@ -49,14 +49,8 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
        const char              *template;
        char                    *line;
 
-       template = args_get(args, 'F');
-       if (template == NULL) {
-               template = "#{session_name}: #{session_windows} windows "
-                   "(created #{session_created_string}) [#{session_width}x"
-                   "#{session_height}]#{?session_grouped, (group ,}"
-                   "#{session_group}#{?session_grouped,),}"
-                   "#{?session_attached, (attached),}";
-       }
+       if ((template = args_get(args, 'F')) == NULL)
+               template = DEFAULT_SESSION_TEMPLATE;
 
        n = 0;
        RB_FOREACH(s, sessions, &sessions) {
-- 
1.7.10


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to