[download]

local/bin/vboxmenu

   1 #!/bin/bash
   2 
   3 while read i; do
   4     vboxmanage startvm "$i"
   5 done < <(
   6     vboxmanage list vms | cut -d \" -f 2 |
   7     icon -x os | menu -i vbox | cut -d ' ' -f 3-
   8 )
   9 
  10 port=2222
  11 
  12 sleep 1 &&
  13 vboxmanage list runningvms |
  14 while IFS=\" read _ name id; do
  15     name=${name,,}
  16     name=${name// /-}
  17 
  18     vboxmanage controlvm $id natpf1 delete SSH
  19     vboxmanage controlvm $id natpf1 SSH,tcp,,$port,,22
  20 
  21     cat <<SSH
  22 Host vbox-$name
  23     HostName localhost
  24     Port $port
  25     LogLevel fatal
  26     StrictHostKeyChecking no
  27     UserKnownHostsFile /dev/null
  28 SSH
  29 
  30     (( port++ ))
  31 done > ~/.ssh/vbox &