Commits

Daniele Varrazzo committed d40e073

bash -- playing with commands completion

Comments (0)

Files changed (2)

+_vm_start()
+{
+    local cur
+    if [ $COMP_CWORD == 1 ]; then
+        cur=${COMP_WORDS[COMP_CWORD]}
+
+        case "$1" in
+            "vm-start")
+                vms=$(VBoxManage -q list vms | awk -F\" '{ print $2 }')
+                ;;
+            "vm-stop")
+                vms=$(VBoxManage -q list runningvms | awk -F\" '{ print $2 }')
+                ;;
+        esac
+
+        COMPREPLY=( $( compgen -W "${vms}" -- $cur ) )
+    fi
+}
+
+complete -o default -o nospace -F _vm_start vm-start vm-stop
+
 # Create all the links to config files I may want on a new system
 
 ln -s etc/bash_aliases .bash_aliases
+ln -s etc/bash_completion .bash_completion
 ln -s etc/ackrc .ackrc
 ln -s etc/git/gitconfig .gitconfig
 ln -s etc/git/gitignore .gitignore