=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/status.c,v retrieving revision 1.182 retrieving revision 1.183 diff -c -r1.182 -r1.183 *** src/usr.bin/tmux/status.c 2018/10/18 08:38:01 1.182 --- src/usr.bin/tmux/status.c 2019/02/09 18:18:36 1.183 *************** *** 1,4 **** ! /* $OpenBSD: status.c,v 1.182 2018/10/18 08:38:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: status.c,v 1.183 2019/02/09 18:18:36 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 45,52 **** static const char *status_prompt_down_history(u_int *); static void status_prompt_add_history(const char *); ! static const char **status_prompt_complete_list(u_int *, const char *); ! static char *status_prompt_complete_prefix(const char **, u_int); static char *status_prompt_complete(struct session *, const char *); /* Status prompt history. */ --- 45,52 ---- static const char *status_prompt_down_history(u_int *); static void status_prompt_add_history(const char *); ! static char **status_prompt_complete_list(u_int *, const char *); ! static char *status_prompt_complete_prefix(char **, u_int); static char *status_prompt_complete(struct session *, const char *); /* Status prompt history. */ *************** *** 1479,1490 **** } /* Build completion list. */ ! static const char ** status_prompt_complete_list(u_int *size, const char *s) { ! const char **list = NULL, **layout; const struct cmd_entry **cmdent; const struct options_table_entry *oe; const char *layouts[] = { "even-horizontal", "even-vertical", "main-horizontal", "main-vertical", "tiled", NULL --- 1479,1494 ---- } /* Build completion list. */ ! char ** status_prompt_complete_list(u_int *size, const char *s) { ! char **list = NULL; ! const char **layout, *value, *cp; const struct cmd_entry **cmdent; const struct options_table_entry *oe; + u_int items, idx; + size_t slen = strlen(s), valuelen; + struct options_entry *o; const char *layouts[] = { "even-horizontal", "even-vertical", "main-horizontal", "main-vertical", "tiled", NULL *************** *** 1492,1520 **** *size = 0; for (cmdent = cmd_table; *cmdent != NULL; cmdent++) { ! if (strncmp((*cmdent)->name, s, strlen(s)) == 0) { list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = (*cmdent)->name; } } for (oe = options_table; oe->name != NULL; oe++) { ! if (strncmp(oe->name, s, strlen(s)) == 0) { list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = oe->name; } } for (layout = layouts; *layout != NULL; layout++) { ! if (strncmp(*layout, s, strlen(s)) == 0) { list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = *layout; } } return (list); } /* Find longest prefix. */ static char * ! status_prompt_complete_prefix(const char **list, u_int size) { char *out; u_int i; --- 1496,1539 ---- *size = 0; for (cmdent = cmd_table; *cmdent != NULL; cmdent++) { ! if (strncmp((*cmdent)->name, s, slen) == 0) { list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrdup((*cmdent)->name); } } for (oe = options_table; oe->name != NULL; oe++) { ! if (strncmp(oe->name, s, slen) == 0) { list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrdup(oe->name); } } for (layout = layouts; *layout != NULL; layout++) { ! if (strncmp(*layout, s, slen) == 0) { list = xreallocarray(list, (*size) + 1, sizeof *list); ! list[(*size)++] = xstrdup(*layout); } } + o = options_get_only(global_options, "command-alias"); + if (o != NULL && options_array_size(o, &items) != -1) { + for (idx = 0; idx < items; idx++) { + value = options_array_get(o, idx); + if (value == NULL || (cp = strchr(value, '=')) == NULL) + continue; + valuelen = cp - value; + if (slen > valuelen || strncmp(value, s, slen) != 0) + continue; + list = xreallocarray(list, (*size) + 1, sizeof *list); + list[(*size)++] = xstrndup(value, valuelen); + } + } + for (idx = 0; idx < (*size); idx++) + log_debug("complete %u: %s", idx, list[idx]); return (list); } /* Find longest prefix. */ static char * ! status_prompt_complete_prefix(char **list, u_int size) { char *out; u_int i; *************** *** 1537,1543 **** static char * status_prompt_complete(struct session *session, const char *s) { ! const char **list = NULL, *colon; u_int size = 0, i; struct session *s_loop; struct winlink *wl; --- 1556,1563 ---- static char * status_prompt_complete(struct session *session, const char *s) { ! char **list = NULL; ! const char *colon; u_int size = 0, i; struct session *s_loop; struct winlink *wl; *************** *** 1556,1561 **** --- 1576,1583 ---- xasprintf(&out, "%s ", list[0]); else out = status_prompt_complete_prefix(list, size); + for (i = 0; i < size; i++) + free(list[i]); free(list); return (out); }