[lxc-devel] [lxd/master] Bash completion: containers state checking
mistoo on Github
lxc-bot at linuxcontainers.org
Mon Sep 26 20:44:58 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 347 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160926/0f1a80a8/attachment.bin>
-------------- next part --------------
From 4db19839a8b52275f690921adffc19fa996ec8ea Mon Sep 17 00:00:00 2001
From: mis <mistoo at gmail.com>
Date: Mon, 26 Sep 2016 22:38:46 +0200
Subject: [PATCH] Containers state checking for start, stop and exec commands
Signed-off-by: Pawel Gajda <mis at pld-linux.org>
---
config/bash/lxd-client | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/config/bash/lxd-client b/config/bash/lxd-client
index b7fe02a..aa7a267 100644
--- a/config/bash/lxd-client
+++ b/config/bash/lxd-client
@@ -3,8 +3,14 @@ _have lxc && {
{
_lxd_names()
{
+ local state=$1
+ local keys=$2
+
+ local cmd="lxc list --fast"
+ [ -n "$state" ] && cmd="$cmd | grep $state"
+
COMPREPLY=( $( compgen -W \
- "$( lxc list --fast | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' ) $1" "$cur" )
+ "$( eval $cmd | grep -Ev '(+--|NAME)' | awk '{print $2}' ) $keys" "$cur" )
)
}
@@ -91,7 +97,7 @@ _have lxc && {
_lxd_names
;;
"get"|"set"|"unset")
- _lxd_names "$global_keys"
+ _lxd_names "" "$global_keys"
;;
esac
;;
@@ -119,7 +125,7 @@ _have lxc && {
_lxd_names
;;
"exec")
- _lxd_names
+ _lxd_names "RUNNING"
;;
"file")
COMPREPLY=( $(compgen -W "pull push edit" -- $cur) )
@@ -186,12 +192,10 @@ _have lxc && {
_lxd_names
;;
"start")
- # should check if containers are stopped
- _lxd_names
+ _lxd_names "STOPPED"
;;
"stop")
- # should check if containers are started
- _lxd_names
+ _lxd_names "RUNNING"
;;
*)
;;
More information about the lxc-devel
mailing list