Created
August 11, 2024 13:00
-
-
Save mzpqnxow/c49c7aa063246a429c01d2780bf40b2c to your computer and use it in GitHub Desktop.
Simple script to start a terminal in the active qube
This file contains hidden or 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
#!/bin/bash | |
# Start a terminal inside the qube associated with the active Xorg window | |
# To use this, in dom0: | |
# - copy to ~/bin | |
# - assign it to a key binding in dom0 | |
# | |
# Use-case: | |
# Firefox (or any other app) is open in qube "personal" and you want to pop a terminal | |
# open in "personal" without having to use context menus | |
# | |
# You want this behavior to work for any qube, without having a different binding for | |
# each | |
# | |
# - mzpqnxow, 2024 CE | |
# | |
# (no copyright, released into the public domain) | |
# | |
DEFAULT_TERM=xfce4-terminal | |
FALLBACK_TERM=xterm | |
id="$(xdotool getactivewindow)" # Get window ID of active window | |
vm="$(xprop -id "$id" _QUBES_VMNAME | grep -oP '"\K[^"]*')" # Get qube name via xproperty | |
if [ "$vm" = "" ]; then | |
echo "dom0 / no active vm !!" | |
else | |
echo "Current window is for Qube named $vm" | |
echo "Running qvm-run $vm xfce4-terminal ..." | |
if ! qvm-run "$vm" $DEFAULT_TERM; then | |
qvm-run "$vm" $FALLBACK_TERM || echo "Giving up ..." | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is easy to do without much hackyness because qubes vms have rich information (including qube name) set in their window properties
I couldn't figure out how to make
xprop
emit the qube name without extra data on the line, so it grabs it withgrep -Po
- maybe someone can show me how to avoid needing that ...