1. Daniele Varrazzo
  2. etc

Commits

Daniele Varrazzo  committed 16cd696

bash -- playing with VBoxManage completion

  • Participants
  • Parent commits d40e073
  • Branches master

Comments (0)

Files changed (1)

File bash_completion

View file
+#!/bin/bash
+
 _vm_start()
 {
     local cur
 
 complete -o default -o nospace -F _vm_start vm-start vm-stop
 
+_vboxmanage()
+{
+    local cur prev
+
+    cur=${COMP_WORDS[COMP_CWORD]}
+    case $COMP_CWORD in
+        1)
+            cmds=$(VBoxManage -q | egrep "VBoxManage [a-z]" | cut -d ' ' -f 2 | sort | uniq)
+            COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
+            ;;
+        2)
+            prev=${COMP_WORDS[COMP_CWORD-1]}
+            case $prev in
+                startvm)
+                    vms=$(VBoxManage -q list vms | awk -F\" '{ print $2 }')
+                    COMPREPLY=( $( compgen -W "${vms}" -- $cur ) )
+                    ;;
+                controlvm)
+                    vms=$(VBoxManage -q list runningvms | awk -F\" '{ print $2 }')
+                    COMPREPLY=( $( compgen -W "${vms}" -- $cur ) )
+                    ;;
+            esac
+            ;;
+    esac
+}
+
+complete -o default -o nospace -F _vboxmanage VBoxManage vboxmanage