#!/bin/bash

[ -z "$LIBVIRT_DEFAULT_URI" ]&&CONNURI="qemu:///system"||CONNURI="$LIBVIRT_DEFAULT_URI"
[ -z "$1" ]&&echo "Viciously refusing to connect to the KVM console of the zero pointer." >&2&&exit 1

virtmhelp() {
	echo -e "USAGE:\tvirtmc|virtme|virtmp"
	echo
	(
		echo ";virtmc:;Shows the domain's console screen"
		echo ";virtme:;Shows the domain editor without going to the console screen"
		echo ";virtmp:;Shows the domain's performance"
	)|column -s\; -t --table-right 2
}
[ "$1" == "-h" ]&&virtmhelp&&exit 0

case "$(basename $0)" in
	virtmc) virt-manager -c "$CONNURI" --show-domain-console "$1";;
	virtme) virt-manager -c "$CONNURI" --show-domain-editor "$1";;
	virtmp) virt-manager -c "$CONNURI" --show-domain-performance "$1";;
	*) echo "Fatal exception: do not simply symlink stuff without knowing what you do!" >&2;exit 1;;
esac