From 93f5687d7b860bd0a0aba3b5ddce6542fec03923 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 13 Nov 2013 14:38:13 +0100 Subject: [PATCH] cli: fix bash completion for curser not at EOL If the curser is not at the end of the line, we want to complete by ignoring everything right of the curser. However, the variable $cur is set to the spaces since the last word, so we have to get rid of them first Without this, the following did not complete: $ nmcli connection modify id lo because $cur is set to ' '. Signed-off-by: Thomas Haller --- cli/completion/nmcli | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cli/completion/nmcli b/cli/completion/nmcli index 9f427ee10f..7f535bccf6 100644 --- a/cli/completion/nmcli +++ b/cli/completion/nmcli @@ -544,6 +544,13 @@ _nmcli() words[i]="$(echo "${words[i]}" | xargs 2>/dev/null || true)" done + # In case the cursor is not at the end of the line, + # $cur consists of spaces that we want do remove. + # For example: `nmcli connection modify id lo` + if [[ "$cur" =~ [[:space:]]+ ]]; then + cur='' + fi + _nmcli_complete_OPTIONS && return 0 local command="${words[1]}"