From: EdĂȘnis Freindorfer Azevedo Date: Fri, 27 Aug 2021 20:24:24 +0000 (-0300) Subject: Improve name completion handling. X-Git-Tag: lxc-5.0.0~91^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8aa4490505f9ad5a957f3f9797a9ccc080d3bb5d;p=thirdparty%2Flxc.git Improve name completion handling. 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 --- diff --git a/config/bash/lxc.in b/config/bash/lxc.in index f1dc9e217..ca6caa85d 100644 --- a/config/bash/lxc.in +++ b/config/bash/lxc.in @@ -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