]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Improve name completion handling.
authorEdênis Freindorfer Azevedo <edenisfa@gmail.com>
Fri, 27 Aug 2021 20:24:24 +0000 (17:24 -0300)
committerEdênis Freindorfer Azevedo <edenisfa@gmail.com>
Mon, 6 Sep 2021 20:00:32 +0000 (17:00 -0300)
Use regex to handle short option `-n`, since short options can be
combined (e.g. `-nd`) as long as at max one requires an argument.

Also consider the case when the arg for the long option is not given
together with `--name=`.

Signed-off-by: Edênis Freindorfer Azevedo <edenisfa@gmail.com>
config/bash/lxc.in

index f1dc9e217ef5c240ef2f13369749c76800f503cb..ca6caa85dc9708587931d9cf3340476dd9c30d79 100644 (file)
@@ -27,11 +27,12 @@ _lxc_names() {
 
 _lxc_append_name() {
     local vms=$(command lxc-ls)
+    local -r shortoptnamexp="^-[0-9A-Za-mo-z]*n[0-9A-Za-mo-z]*$"
     # If `--name` or `-n` are present, do not complete with container names.
     for param in ${words[@]}; do
-        if [[ ${param} =~ ^--name=(.*)$ ]]; then
+        if [[ ${param} =~ ^--name(=(.*))?$ ]]; then
             return
-        elif [[ ${param} =~ ^-n$ ]]; then
+        elif [[ ${param} =~ ${shortoptnamexp} ]]; then
             return
         fi
         for vm in ${vms[@]}; do