Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve bash completion to work when the selected project != default #12195

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions scripts/bash/lxd-client
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand All @@ -31,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()
Expand Down Expand Up @@ -245,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) )
Expand Down
Loading