version 1.9, 2011/01/04 00:42:46 |
version 1.10, 2011/08/26 10:53:16 |
|
|
|
|
const struct cmd_entry cmd_list_sessions_entry = { |
const struct cmd_entry cmd_list_sessions_entry = { |
"list-sessions", "ls", |
"list-sessions", "ls", |
"", 0, 0, |
"F:", 0, 0, |
"", |
"[-F format]", |
0, |
0, |
NULL, |
NULL, |
NULL, |
NULL, |
cmd_list_sessions_exec |
cmd_list_sessions_exec |
}; |
}; |
|
|
/* ARGSUSED */ |
|
int |
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 *s; |
struct session_group *sg; |
u_int n; |
char *tim, tmp[64]; |
struct format_tree *ft; |
u_int idx; |
const char *template; |
time_t t; |
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) { |
RB_FOREACH(s, sessions, &sessions) { |
sg = session_group_find(s); |
ft = format_create(); |
if (sg == NULL) |
format_add(ft, "line", "%u", n); |
*tmp = '\0'; |
format_session(ft, s); |
else { |
|
idx = session_group_index(sg); |
|
xsnprintf(tmp, sizeof tmp, " (group %u)", idx); |
|
} |
|
|
|
t = s->creation_time.tv_sec; |
line = format_expand(ft, template); |
tim = ctime(&t); |
ctx->print(ctx, "%s", line); |
*strchr(tim, '\n') = '\0'; |
xfree(line); |
|
|
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s", |
format_free(ft); |
s->name, winlink_count(&s->windows), tim, s->sx, s->sy, |
n++; |
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)"); |
|
} |
} |
|
|
return (0); |
return (0); |