Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Functions for controlling VirtualBox VMs
- vm-start() {
- if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
- VBoxManage startvm $1 --type headless
- }
- vm-savestate() {
- if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
- VBoxManage controlvm $1 savestate
- }
- vm-powerbutton() {
- if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
- VBoxManage controlvm $1 acpipowerbutton
- }
- vm-poweroff() {
- if [ ! "$1" ]; then echo "Missing argument" 1>&2; return 1; fi
- echo -n "Do you really want to poweroff $1 ? [y]es/no "
- read answer
- if [[ "$answer" = "y" || "$answer" = "yes" ]]; then
- VBoxManage controlvm $1 poweroff
- fi
- }
- alias vm-running='VBoxManage list runningvms'
- export VIRTUAL_MACHINES="$(VBoxManage list vms | awk '{print $1;}' | sed 's/"//g' | xargs)"
- # Autocompletion
- _CompleteVm() {
- local cur prev opts
- COMPREPLY=()
- cur="${COMP_WORDS[COMP_CWORD]}"
- prev="${COMP_WORDS[COMP_CWORD-1]}"
- COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
- return 0
- }
- complete -F _CompleteVm -W "$VIRTUAL_MACHINES" vm-start vm-savestate vm-powerbutton vm-poweroff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement