From 72a410c1ade4ce6d25f54b842b8910d1f228159e Mon Sep 17 00:00:00 2001 From: Filip Pokryvka Date: Mon, 26 Aug 2024 12:00:50 +0200 Subject: [PATCH] nmcli: fix bash completion for fields The code handling options with supposes, that options are split by `=`, which is not the case. This fixes the following: ``` nmcli -f ipv4.ad\t\t nmcli -f ipv4.ad=ipv4.addresses nmcli --field ipv4.ad\t\t nmcli --field ipv4.ad=ipv4.addresses ``` Using options with values separated with `=` remains broken, but this change doesn't affect it: ``` nmcli --field=ipv4.ad\t\t nmcli --field=ipv4.ad ``` Also, `man` and `usage` uses `--color auto|yes|no`, not `--color=auto|yes|no`. So, this fix should be sufficient. Bug report: https://bugzilla.redhat.com/show_bug.cgi?id=2115827 --- src/nmcli/nmcli.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/nmcli/nmcli.c b/src/nmcli/nmcli.c index 359bba8e06..cfe4c5f4a7 100644 --- a/src/nmcli/nmcli.c +++ b/src/nmcli/nmcli.c @@ -163,17 +163,18 @@ complete_one(gpointer key, gpointer value, gpointer user_data) last = prefix; if ((!*last && !strchr(name, '.')) || matches(last, name)) { - if (option != prefix) { + if (!nm_streq0(option, prefix)) { /* value prefix was not a standalone argument, * it was part of --option= argument. * Repeat the part leading to "=". */ - nmc_print("%s=", option); + nmc_print("%s\n", option); + } else { + nmc_print("%.*s%s%s\n", + (int) (last - prefix), + prefix, + name, + nm_streq(last, name) ? "," : ""); } - nmc_print("%.*s%s%s\n", - (int) (last - prefix), - prefix, - name, - strcmp(last, name) == 0 ? "," : ""); } } @@ -225,13 +226,14 @@ complete_option_with_value(const char *option, const char *prefix, ...) va_start(args, prefix); while ((candidate = va_arg(args, const char *))) { if (!*prefix || matches(prefix, candidate)) { - if (option != prefix) { + if (!nm_streq0(option, prefix)) { /* value prefix was not a standalone argument, * it was part of --option= argument. * Repeat the part leading to "=". */ - nmc_print("%s=", option); + nmc_print("%s%s\n", option, candidate + strlen(prefix)); + } else { + nmc_print("%s\n", candidate); } - nmc_print("%s\n", candidate); } } va_end(args);