From d7788b0d46a783fbf906ee7d13f45b0aa28f11e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Thu, 29 Aug 2013 15:29:34 +0200 Subject: [PATCH] cli: fix TAB-completion for aliases in interactive editor Before the change if an alias for a setting name existed, it was used instead of the real name and TAB-completion for the real name didn't work. before: nmcli> goto 802 no output now: nmcli> goto 802 nmcli> goto 802-11-wireless 802-11-wireless 802-11-wireless-security nmcli> goto 802-11-wireless-security (wifi-sec) connection ipv6 802-11-wireless (wifi) ipv4 --- cli/src/connections.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cli/src/connections.c b/cli/src/connections.c index 053fc1665..f1e60dbc3 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -3481,19 +3481,23 @@ static char * gen_connection_types (char *text, int state) { static int list_idx, len; - const char *c_type; + const char *c_type, *a_type; if (!state) { list_idx = 0; len = strlen (text); } - while ( (c_type = nmc_valid_connection_types[list_idx].alias) - || (c_type = nmc_valid_connection_types[list_idx].name)) { + while (nmc_valid_connection_types[list_idx].name) { + a_type = nmc_valid_connection_types[list_idx].alias; + c_type = nmc_valid_connection_types[list_idx].name; list_idx++; - if (!strncmp (text, c_type, len)) + if (a_type && !strncmp (text, a_type, len)) + return g_strdup (a_type); + if (c_type && !strncmp (text, c_type, len)) return g_strdup (c_type); } + return NULL; } @@ -3501,7 +3505,7 @@ static char * gen_setting_names (char *text, int state) { static int list_idx, len; - const char *s_name; + const char *s_name, *a_name; const NameItem *valid_settings_arr; if (!state) { @@ -3512,10 +3516,15 @@ gen_setting_names (char *text, int state) valid_settings_arr = get_valid_settings_array (nmc_completion_con_type); if (!valid_settings_arr) return NULL; - while ( (s_name = valid_settings_arr[list_idx].alias) - || (s_name = valid_settings_arr[list_idx].name)) { + while (valid_settings_arr[list_idx].name) { + a_name = valid_settings_arr[list_idx].alias; + s_name = valid_settings_arr[list_idx].name; list_idx++; - if (!strncmp (text, s_name, len)) + if (len == 0 && a_name) + return g_strdup_printf ("%s (%s)", s_name, a_name); + if (a_name && !strncmp (text, a_name, len)) + return g_strdup (a_name); + if (s_name && !strncmp (text, s_name, len)) return g_strdup (s_name); } return NULL;