Last active
January 4, 2019 17:38
-
-
Save etyurkin/320ad261a812053fd87522ac77e6fb84 to your computer and use it in GitHub Desktop.
Control VirtualBox VMs from Emacs with Helm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun helm--virtualbox-vms () | |
(mapcar (lambda (str) (string-trim (car (split-string str " ")) "\"" "\"")) | |
(split-string (trim (shell-command-to-string "VBoxManage list vms")) "\n"))) | |
(defun helm--virtualbox-sources () | |
`((name . "Virtual Box") | |
(candidates . ,(helm--virtualbox-vms)) | |
(action . (("Status" . (lambda (candidate) | |
(let ((vm-info (shell-command-to-string (format "VBoxManage showvminfo \"%s\"" candidate)))) | |
(save-match-data | |
(and (string-match "^State:\\s-*\\(.*\\)$" vm-info) | |
(message (format "%s: %s" candidate (match-string 1 vm-info)))))))) | |
("Start" . (lambda (candidate) | |
(message "start %s" candidate) | |
(shell-command (format "VBoxManage startvm \"%s\"" candidate)))) | |
("Pause" . (lambda (candidate) | |
(message "pause %s" candidate) | |
(shell-command (format "VBoxManage controlvm \"%s\" pause" candidate)))) | |
("Resume" . (lambda (candidate) | |
(message "resume %s" candidate) | |
(shell-command (format "VBoxManage controlvm \"%s\" resume" candidate)))) | |
("Reset" . (lambda (candidate) | |
(message "reset %s" candidate) | |
(shell-command (format "VBoxManage controlvm \"%s\" reset" candidate)))) | |
("Power off" . (lambda (candidate) | |
(message "power off %s" candidate) | |
(shell-command (format "VBoxManage controlvm \"%s\" poweroff" candidate)))) | |
("Save state" . (lambda (candidate) | |
(message "save state %s" candidate) | |
(shell-command (format "VBoxManage controlvm \"%s\" savestate" candidate)))))))) | |
(defun helm-virtualbox () | |
"Control Virtual Box VMs" | |
(interactive) | |
(helm :sources (helm--virtualbox-sources) | |
:buffer "*helm-virtualbox*")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment