Skip to content

Instantly share code, notes, and snippets.

@e9x
Last active January 5, 2024 02:17
Show Gist options
  • Save e9x/579422200de7a0518fd0517c434b971a to your computer and use it in GitHub Desktop.
Save e9x/579422200de7a0518fd0517c434b971a to your computer and use it in GitHub Desktop.
Qubes Sensible Terminal

Qubes Sensible Terminal

This is qubes-i3-sensible-terminal but support for any DE.

Known to work in XFCE.

Setup:

  • Copy the script below to DOM0 and make it executable

    In a networked VM:

    curl -o /home/user/sensible-terminal.sh TODO

    In DOM0:

    qvm-run --pass-io your-vm "cat /home/user/sensible-terminal.sh" > /home/user/sensible-terminal.sh
    chmod +x /home/user/sensible-terminal.sh

    Make sure to review the script and make sure it's safe.

    cat /home/user/sensible-terminal.sh
  • Add a keybind to run this script when a key is pressed

    Qubes by default comes with XFCE which you can configure keyboard shortcuts on.

    In DOM0:

    xfce4-keyboard-settings

    Go to "Application Shortcuts", click on "Add"

    Command: sensible-terminal.sh

    Press "Ok", then press the key you want to bind it to, eg CTRL + ALT + T

Usage:

You should now be able to press your keybind that you set, then a terminal will open in either in a VM or DOM0 depending on the window you have focused.

#!/bin/bash
run_terminal='
for t in "$TERMINAL" xfce4-terminal gnome-terminal konsole roxterm termite lxterminal mate-terminal terminology x-terminal-emulator urxvt rxvt termit terminator Eterm aterm st xterm; do
command -v "$t" > /dev/null 2>&1 && exec "$t";
done
'
get_id() {
local id=$(xprop -root _NET_ACTIVE_WINDOW)
local id=${id#*window id # }
echo ${id%%, *} # extract id
}
get_vm() {
local id=$(get_id)
local abc=$(xprop -id $id)
local vm=$(xprop -id $id | grep '_QUBES_VMNAME(STRING)')
local vm=${vm#*\"} # extract vmname
echo ${vm%\"*} # extract vmname
}
main() {
local vm=$(get_vm)
#notify-send "vm: $vm"
if [[ -n "$vm" ]]; then
if command -v qrexec-client >/dev/null; then
qrexec-client -e -d "$vm" DEFAULT:"bash -c '$run_terminal'"
else
qvm-run "$vm" qvm-run "$vm" "bash -c '$run_terminal'"
fi
else # run terminal in dom0
exec bash -c "$run_terminal"
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment