=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-list-sessions.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- src/usr.bin/tmux/cmd-list-sessions.c 2011/01/04 00:42:46 1.9 +++ src/usr.bin/tmux/cmd-list-sessions.c 2011/08/26 10:53:16 1.10 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-sessions.c,v 1.9 2011/01/04 00:42:46 nicm Exp $ */ +/* $OpenBSD: cmd-list-sessions.c,v 1.10 2011/08/26 10:53:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,40 +31,45 @@ const struct cmd_entry cmd_list_sessions_entry = { "list-sessions", "ls", - "", 0, 0, - "", + "F:", 0, 0, + "[-F format]", 0, NULL, NULL, cmd_list_sessions_exec }; -/* ARGSUSED */ int -cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx) +cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx) { + struct args *args = self->args; struct session *s; - struct session_group *sg; - char *tim, tmp[64]; - u_int idx; - time_t t; + u_int n; + struct format_tree *ft; + 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),}"; + } + + n = 0; RB_FOREACH(s, sessions, &sessions) { - sg = session_group_find(s); - if (sg == NULL) - *tmp = '\0'; - else { - idx = session_group_index(sg); - xsnprintf(tmp, sizeof tmp, " (group %u)", idx); - } + ft = format_create(); + format_add(ft, "line", "%u", n); + format_session(ft, s); - t = s->creation_time.tv_sec; - tim = ctime(&t); - *strchr(tim, '\n') = '\0'; + line = format_expand(ft, template); + ctx->print(ctx, "%s", line); + xfree(line); - ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s", - s->name, winlink_count(&s->windows), tim, s->sx, s->sy, - tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)"); + format_free(ft); + n++; } return (0);