A script to open your favorite terminal as root it's for minimal template users but should work for "full" template users i don't like to type in dom0 "qvm-run -u root" then the name of the vm it's annoying you can misstype the name and typing again is annoying.
#!/bin/bash
# Function to find matching VM
find_vm() {
local pattern="$1"
local matching_vms
# Find VMs matching the pattern
matching_vms=$(qvm-ls --no-spinner | grep -E "^${pattern}" | awk '{print $1}')
# Count number of matching VMs
local match_count=$(echo "$matching_vms" | wc -l)
# Handle matching logic
if [ -z "$matching_vms" ]; then
zenity --error --text="No VM found matching '$pattern'" --width=300
exit 1
elif [ "$match_count" -gt 1 ]; then
# If multiple matches, let user choose
local chosen_vm=$(echo "$matching_vms" | zenity --list \
--title="Multiple VMs Match" \
--text="Select a VM:" \
--column="VM Name" \
--width=300 \
--height=300)
# If user cancels selection
if [ -z "$chosen_vm" ]; then
exit 1
fi
echo "$chosen_vm"
else
# If exactly one match
echo "$matching_vms"
fi
}
# Function to detect default terminal in the VM
get_vm_default_terminal() {
local vm_name="$1"
# List of terminal commands to try in order
local terminal_commands=(
"alacritty"
"konsole"
"gnome-terminal"
"xfce4-terminal"
"tilix"
"mate-terminal"
"xterm"
)
# Try each terminal command
for terminal in "${terminal_commands[@]}"; do
# Use qvm-run to check if the terminal exists
if qvm-run -u root "$vm_name" "command -v $terminal" > /dev/null 2>&1; then
echo "$terminal"
return 0
fi
done
# If no terminal found
zenity --error --text="No terminal found in VM $vm_name" --width=300
exit 1
}
# Prompt user to enter VM name pattern
vm_pattern=$(zenity --entry \
--title="Open Root Terminal" \
--text="Which VM should be opened as root? (Use * for partial match)" \
--width=300)
# Check if user canceled
if [ -z "$vm_pattern" ]; then
zenity --error --text="No VM name entered. Exiting." --width=300
exit 1
fi
# Replace * with .* for regex matching
vm_pattern=$(echo "$vm_pattern" | sed 's/\*/.*/')
# Find matching VM
vm_name=$(find_vm "$vm_pattern")
# Get default terminal in the VM
vm_terminal=$(get_vm_default_terminal "$vm_name")
# Run the detected terminal as root in the specified VM
qvm-run -u root "$vm_name" "$vm_terminal"