]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
tools: Add bash completion for Linux loader command
authorJan Kiszka <jan.kiszka@siemens.com>
Sun, 10 May 2015 21:54:27 +0000 (23:54 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Sun, 7 Jun 2015 17:05:37 +0000 (19:05 +0200)
Teach the new subcommand "cell linux" to the bash completion script.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools/jailhouse-completion.bash

index a326724e221d9b05dcbc0d09e096ccb07bcee197..e69dc8bf0207232ab4ae51303d148030a45aab36 100644 (file)
@@ -1,9 +1,11 @@
 # bash completion for jailhouse
 #
 # Copyright (c) Benjamin Block, 2014
+# Copyright (c) Siemens AG, 2015
 #
 # Authors:
 #  Benjamin Block <bebl@mageta.org>
+#  Jan Kiszka <jan.kiszka@siemens.com>
 #
 # This work is licensed under the terms of the GNU GPL, version 2.  See
 # the COPYING file in the top-level directory.
@@ -99,6 +101,48 @@ function _jailhouse_get_id() {
        return 0;
 }
 
+function _jailhouse_cell_linux() {
+       local cur prev word
+
+       cur="${COMP_WORDS[COMP_CWORD]}"
+       prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+       options="-h --help -i --initrd -c --cmdline -w --write-params"
+
+       # if we already have begun to write an option
+       if [[ "$cur" == -* ]]; then
+               COMPREPLY=( $( compgen -W "${options}" -- "${cur}") )
+       else
+               # if the previous was on of the following options
+               case "${prev}" in
+               -i|--initrd|-w|--write-params)
+                       # search an existing file
+                       _filedir
+                       return $?
+                       ;;
+               -c|--cmdline)
+                       # we can't really predict this
+                       return 0
+                       ;;
+               esac
+
+               # neither option, nor followup of one. Lets assume we want
+               # the cell or the kernel
+               for n in `seq ${COMP_CWORD-1}`; do
+                       word="${COMP_WORDS[n]}"
+                       if [[ "${word}" == *.cell ]] && ( [ $n -eq 1 ] ||
+                           [[ "${COMP_WORDS[n-1]}" != -* ]] ); then
+                               # we already have a cell, this is the kernel
+                               _filedir
+                               return 0
+                       fi
+               done
+               _filedir "cell"
+       fi
+
+       return 0
+}
+
 function _jailhouse_cell() {
        local cur prev quoted_cur
 
@@ -167,6 +211,9 @@ function _jailhouse_cell() {
                # takes only one argument (id/name)
                _jailhouse_get_id "${cur}" "${prev}" || return 1
                ;;
+       linux)
+               _jailhouse_cell_linux || return 1
+               ;;
        list)
                # list all cells
 
@@ -237,7 +284,7 @@ function _jailhouse() {
        command="enable disable cell config --help"
 
        # second level
-       command_cell="create load start shutdown destroy list stats"
+       command_cell="create load start shutdown destroy linux list stats"
        command_config="create collect"
 
        # ${COMP_WORDS} array containing the words on the current command line