diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-02 16:24:30 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-02 16:24:30 +0000 |
commit | a83250997fb91be059f1d51db62806ea30413d77 (patch) | |
tree | 7c534d9250a0ff8514097fdf2cde5cbfb0566a29 /usr.bin/tmux/cmd.c | |
parent | f47602648183b202fd7112a07074022cd3e8ba12 (diff) |
When matching the session names with -t, look for exact matches first before
trying partial matches.
Avoids problems where two ambiguous matches are present before an exact match
(eg foo1, foo2, foo would give an error on trying -tfoo), reported by Natacha
Port? natbsd at instinctive dot eu.
Diffstat (limited to 'usr.bin/tmux/cmd.c')
-rw-r--r-- | usr.bin/tmux/cmd.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index 483d338af4b..2b761f256a9 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.27 2009/10/26 21:42:04 deraadt Exp $ */ +/* $OpenBSD: cmd.c,v 1.28 2009/11/02 16:24:29 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -488,19 +488,25 @@ cmd_lookup_session(const char *name, int *ambiguous) *ambiguous = 0; /* - * Look for matches. Session names must be unique so an exact match - * can't be ambigious and can just be returned. + * Look for matches. First look for exact matches - session names must + * be unique so an exact match can't be ambigious and can just be + * returned. */ - sfound = NULL; for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { if ((s = ARRAY_ITEM(&sessions, i)) == NULL) continue; - - /* Check for an exact match and return it if found. */ if (strcmp(name, s->name) == 0) return (s); - - /* Then check for pattern matches. */ + } + + /* + * Otherwise look for partial matches, returning early if it is found to + * be ambiguous. + */ + sfound = NULL; + for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { + if ((s = ARRAY_ITEM(&sessions, i)) == NULL) + continue; if (strncmp(name, s->name, strlen(name)) == 0 || fnmatch(name, s->name, 0) == 0) { if (sfound != NULL) { @@ -510,7 +516,6 @@ cmd_lookup_session(const char *name, int *ambiguous) sfound = s; } } - return (sfound); } |