From 91eb9206d0bb246e9a7d4ab74c0a5a7b38e377c3 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 2 Oct 2007 17:35:00 +0000 Subject: [PATCH] Warn on ambiguous commands. --- TODO | 1 - tmux.c | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index ccd5aa39..cca7a5cc 100644 --- a/TODO +++ b/TODO @@ -43,6 +43,5 @@ close window kill session - fix resize (width problems with multiple clients?) -- deal properly with ambiguous ops... list-sessions & list-windows - handle tmux in tmux (check $TMUX and abort) - check for some reqd terminfo caps on startup diff --git a/tmux.c b/tmux.c index 9e3fbf00..2e62d5a1 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.18 2007-10-01 14:53:29 nicm Exp $ */ +/* $Id: tmux.c,v 1.19 2007-10-02 17:35:00 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -49,7 +49,7 @@ struct op op_table[] = { { "list-sessions", "ls", op_list_sessions }, { "list-windows", "lsw", op_list_windows }, { "new-session", "new", op_new/*_session*/ }, - { "rename-window", NULL, op_rename }, + { "rename-window", "renw", op_rename }, }; #define NOP (sizeof op_table / sizeof op_table[0]) @@ -158,7 +158,7 @@ sigreset(void) int main(int argc, char **argv) { - struct op *op; + struct op *op, *found; char *path; int opt; u_int i; @@ -185,13 +185,22 @@ main(int argc, char **argv) log_open(stderr, LOG_USER, debug_level); status_lines = 1; - + + found = NULL; for (i = 0; i < NOP; i++) { op = op_table + i; - if (strncmp(argv[0], op->cmd, strlen(argv[0])) == 0 || - (op->alias != NULL && strcmp(argv[0], op->alias) == 0)) + if (op->alias != NULL && strcmp(argv[0], op->alias) == 0) exit(op->fn(path, argc, argv)); + if (strncmp(argv[0], op->cmd, strlen(argv[0])) == 0) { + if (found != NULL) { + log_warnx("ambiguous command: %s", argv[0]); + exit(1); + } + found = op; + } } + if (found != NULL) + exit(found->fn(path, argc, argv)); exit(usage(NULL)); }