From a853c1cd52fa745b1a3c66ae3f1504fa6abc9810 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Wed, 30 Aug 2023 17:44:10 -0400 Subject: [PATCH 1/3] scripts/bash/lxd-client: fix completion to work for non-default projects Closes #11429 Signed-off-by: Simon Deziel --- scripts/bash/lxd-client | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/bash/lxd-client b/scripts/bash/lxd-client index de2835209edd..522c00904a33 100644 --- a/scripts/bash/lxd-client +++ b/scripts/bash/lxd-client @@ -5,9 +5,12 @@ _have lxc && { { local state=$1 local keys=$2 + local project + project=$(lxc project list -f csv | sed -n 's/^\([^(]\+\) (current),.*/\1/ p') + project=${project:-"default"} - local cmd="lxc list --format=csv --columns=ns" - [ -n "$state" ] && cmd="$cmd | grep -E '$state$'" + local cmd="lxc list --format=csv --columns=ns --project $project" + [ -n "$state" ] && cmd="$cmd | grep -E ',$state$'" COMPREPLY=( $( compgen -W \ "$( eval $cmd | cut -d, -f1 ) $keys" "$cur" ) From bca525ff6d1f7866fe038c700c3c0799b348d533 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Wed, 30 Aug 2023 17:48:33 -0400 Subject: [PATCH 2/3] scripts/bash/lxd-client: use parentheses around grep -E alternations Signed-off-by: Simon Deziel --- scripts/bash/lxd-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bash/lxd-client b/scripts/bash/lxd-client index 522c00904a33..dec3e047f997 100644 --- a/scripts/bash/lxd-client +++ b/scripts/bash/lxd-client @@ -248,7 +248,7 @@ _have lxc && { _lxd_names "(STOPPED|FROZEN)" ;; "exec"|"console"|"stop"|"shell") - _lxd_names "RUNNING|READY" + _lxd_names "(RUNNING|READY)" ;; "file") COMPREPLY=( $(compgen -W "pull push edit delete mount" -- $cur) ) From 2c307e6010fdbb13b42c8dc01573f131d3874594 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Wed, 30 Aug 2023 18:02:19 -0400 Subject: [PATCH 3/3] scripts/bash/lxd-client: don't propose "(current)" as valid project Prior to this: $ lxc project list (current) default foo After this: $ lxc project list default foo Signed-off-by: Simon Deziel --- scripts/bash/lxd-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bash/lxd-client b/scripts/bash/lxd-client index dec3e047f997..33ddcdc55ce8 100644 --- a/scripts/bash/lxd-client +++ b/scripts/bash/lxd-client @@ -34,7 +34,7 @@ _have lxc && { _lxd_projects() { - COMPREPLY=( $( compgen -W "$( lxc project list --format=csv | cut -d, -f1 )" "$cur" ) ) + COMPREPLY=( $( compgen -W "$( lxc project list --format=csv | sed 's/,.\+//; s/ (current)$//' )" "$cur" ) ) } _lxd_networks()