103 lines
2.5 KiB
Diff
103 lines
2.5 KiB
Diff
From 03f7d19ef75af75cdc8cb15cb022e5fe367c4760 Mon Sep 17 00:00:00 2001
|
|
From: yin-xiujiang <yinxiujiang@kylinos.cn>
|
|
Date: Thu, 6 May 2021 14:32:32 +0800
|
|
Subject: [PATCH 092/104] completion isula images
|
|
|
|
---
|
|
src/contrib/completion/isula | 64 ++++++++++++++++++++++++++----------
|
|
1 file changed, 47 insertions(+), 17 deletions(-)
|
|
|
|
diff --git a/src/contrib/completion/isula b/src/contrib/completion/isula
|
|
index a12d90a5..a2adc083 100644
|
|
--- a/src/contrib/completion/isula
|
|
+++ b/src/contrib/completion/isula
|
|
@@ -1,5 +1,7 @@
|
|
#!/usr/bin/env bash
|
|
-_isula_isula() {
|
|
+
|
|
+_isula_isula()
|
|
+{
|
|
local isula_management_commands=(
|
|
volume
|
|
)
|
|
@@ -65,32 +67,60 @@ _isula_isula() {
|
|
esac
|
|
}
|
|
|
|
-_isula_default()
|
|
+_isula_default()
|
|
{
|
|
COMPREPLY=( $( compgen -d -f -- $cur ) )
|
|
}
|
|
|
|
-_isula() {
|
|
+_isula_isula_list_images_with_tag()
|
|
+{
|
|
+ local images_with_tag=()
|
|
+ case "$cur" in
|
|
+ *:*)
|
|
+ front=${cur%:*}
|
|
+ #先去掉第一行,然后过滤指定镜像名
|
|
+ images_with_tag=($(isula images |awk 'NR>1'|grep -w "$front"| awk '{print $2}'))
|
|
+ cur=${cur##*:}
|
|
+ ;;
|
|
+ *)
|
|
+ images_with_tag=($(isula images |awk 'NR>1{printf "%s:%s\n",$1,$2}'))
|
|
+ ;;
|
|
+ esac
|
|
+
|
|
+ COMPREPLY=( $( compgen -W "${images_with_tag[*]}" -- "$cur" ) )
|
|
+}
|
|
+
|
|
+_isula_isula_rmi()
|
|
+{
|
|
+ _isula_isula_list_images_with_tag
|
|
+}
|
|
+
|
|
+_isula_isula_tag()
|
|
+{
|
|
+ _isula_isula_list_images_with_tag
|
|
+}
|
|
+
|
|
+_isula_isula_images()
|
|
+{
|
|
+ _isula_isula_list_images_with_tag
|
|
+}
|
|
+
|
|
+_isula()
|
|
+{
|
|
COMPREPLY=()
|
|
|
|
- #An array variable consisting of the individual words in the current command line
|
|
- local words=(${COMP_WORDS[*]})
|
|
- #An index into ${word} of the word containing the current cursor position
|
|
- local cword=$COMP_CWORD
|
|
- local cur="${words[$cword]}"
|
|
- local prev="${words[$cword-1]}"
|
|
+ local cur prev words cword
|
|
+ _get_comp_words_by_ref -n : cur prev words cword
|
|
local command='isula'
|
|
-
|
|
+ if [ $cword -gt 1 ] ; then
|
|
+ command="isula_${words[1]}"
|
|
+ fi
|
|
local completions_func=_isula_${command//-/_}
|
|
-
|
|
- #The completion of the secondary command will be added later
|
|
- if [ $cword -lt 2 ] ; then
|
|
- completions_func=_isula_${command//-/_}
|
|
+ if declare -F $completions_func >/dev/null; then
|
|
+ $completions_func
|
|
else
|
|
- completions_func=_isula_default
|
|
+ _isula_default
|
|
fi
|
|
-
|
|
- declare -F $completions_func >/dev/null && $completions_func
|
|
return 0
|
|
}
|
|
|
|
--
|
|
2.25.1
|
|
|