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>
_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