#!/bin/sh # Select action choice=$(printf "virt-manager\nstart\nshutdown" | dmenu -i -p "Choose an action:") [ -z "$choice" ] && exit 1 # Get list of VMs based on state case "$choice" in virt-manager) setsid -f virt-manager && exit ;; start) vmlist=$(virsh --connect qemu:///system list --all | awk '/shut off/ {print $2}') ;; shutdown) vmlist=$(virsh --connect qemu:///system list --all | awk '/running/ {print $2}') ;; *) exit 1 ;; esac # Select a VM from the list vm=$(printf "%s\n" "$vmlist" | dmenu -i -p "$choice which VM?") [ -z "$vm" ] && exit 1 # Perform the action case "$choice" in start) virsh --connect qemu:///system start "$vm" && setsid -f virt-viewer --connect qemu:///system "$vm" >/dev/null 2>&1 ;; shutdown) virsh --connect qemu:///system shutdown "$vm" ;; esac