[lxc-devel] [lxd/master] Bash completion

simondeziel on Github lxc-bot at linuxcontainers.org
Thu Sep 17 21:48:28 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 530 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200917/d1619186/attachment.bin>
-------------- next part --------------
From e135461684a73b360eb3e8ee80d2129e53ef3e5d Mon Sep 17 00:00:00 2001
From: Simon Deziel <simon at sdeziel.info>
Date: Thu, 17 Sep 2020 17:16:30 -0400
Subject: [PATCH 1/2] bash-completion: use "list --format=csv" consistently

Signed-off-by: Simon Deziel <simon at sdeziel.info>
---
 scripts/bash/lxd-client | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/scripts/bash/lxd-client b/scripts/bash/lxd-client
index 27b1ed2018..d56d45e6ce 100644
--- a/scripts/bash/lxd-client
+++ b/scripts/bash/lxd-client
@@ -16,47 +16,37 @@ _have lxc && {
 
     _lxd_images()
     {
-      COMPREPLY=( $( compgen -W \
-        "$( lxc image list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" )
-      )
+      COMPREPLY=( $( compgen -W "$( lxc image list --format=csv | cut -d, -f1 )" "$cur" ) )
     }
 
     _lxd_remotes()
     {
-      COMPREPLY=( $( compgen -W \
-        "$( lxc remote list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" )
-      )
+      COMPREPLY=( $( compgen -W "$( lxc remote list --format=csv | cut -d, -f1 )" "$cur" ) )
     }
 
     _lxd_profiles()
     {
-      COMPREPLY=( $( compgen -W "$( lxc profile list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" ) )
+      COMPREPLY=( $( compgen -W "$( lxc profile list --format=csv | cut -d, -f1 )" "$cur" ) )
     }
 
     _lxd_projects()
     {
-      COMPREPLY=( $( compgen -W "$( lxc project list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" ) )
+      COMPREPLY=( $( compgen -W "$( lxc project list --format=csv | cut -d, -f1 )" "$cur" ) )
     }
 
     _lxd_networks()
     {
-      COMPREPLY=( $( compgen -W \
-        "$( lxc network list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" )
-      )
+      COMPREPLY=( $( compgen -W "$( lxc network list --format=csv | cut -d, -f1 )" "$cur" ) )
     }
 
     _lxd_storage_pools()
     {
-      COMPREPLY=( $( compgen -W \
-        "$( lxc storage list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" )
-      )
+      COMPREPLY=( $( compgen -W "$( lxc storage list --format=csv | cut -d, -f1 )" "$cur" ) )
     }
 
     _lxd_storage_volumes()
     {
-      COMPREPLY=( $( compgen -W \
-        "$( lxc storage volume list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" )
-      )
+      COMPREPLY=( $( compgen -W "$( lxc storage volume list --format=csv | cut -d, -f1 )" "$cur" ) )
     }
 
     COMPREPLY=()

From b5af91dfea753718bb033d3c4fb6e8c58d25ee0a Mon Sep 17 00:00:00 2001
From: Simon Deziel <simon at sdeziel.info>
Date: Thu, 17 Sep 2020 17:20:59 -0400
Subject: [PATCH 2/2] bash-completion: use regex grouping for `lxc start`

Signed-off-by: Simon Deziel <simon at sdeziel.info>
---
 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 d56d45e6ce..37769d8ec9 100644
--- a/scripts/bash/lxd-client
+++ b/scripts/bash/lxd-client
@@ -359,7 +359,7 @@ _have lxc && {
         _lxd_names
         ;;
       "start")
-        _lxd_names "STOPPED|FROZEN"
+        _lxd_names "(STOPPED|FROZEN)"
         ;;
       "stop")
         _lxd_names "RUNNING"


More information about the lxc-devel mailing list