Advertisement
the-technoholik

VBoxManage made simple

Jan 28th, 2015
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.16 KB | None | 0 0
  1. # Functions for controlling VirtualBox VMs
  2. vm-start() {
  3.     if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
  4.     VBoxManage startvm $1 --type headless
  5. }
  6.  
  7. vm-savestate() {
  8.     if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
  9.     VBoxManage controlvm $1 savestate
  10. }
  11.  
  12. vm-powerbutton() {
  13.     if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
  14.     VBoxManage controlvm $1 acpipowerbutton
  15. }
  16.  
  17. vm-poweroff() {
  18.     if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
  19.     echo -n "Do you really want to poweroff $1 ? [y]es/no  "
  20.     read answer
  21.     if [[ "$answer" = "y" || "$answer" = "yes" ]]; then
  22.         VBoxManage controlvm $1 poweroff
  23.     fi
  24. }
  25.  
  26. alias vm-running='VBoxManage list runningvms'
  27.    
  28. export VIRTUAL_MACHINES="$(VBoxManage list vms | awk '{print $1;}' | sed 's/"//g' | xargs)"
  29.  
  30. # Autocompletion
  31. _CompleteVm() {
  32.     local cur prev opts
  33.     COMPREPLY=()
  34.     cur="${COMP_WORDS[COMP_CWORD]}"
  35.     prev="${COMP_WORDS[COMP_CWORD-1]}"
  36.  
  37.     COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  38.     return 0
  39. }
  40. complete -F _CompleteVm -W "$VIRTUAL_MACHINES" vm-start vm-savestate vm-powerbutton vm-poweroff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement