2024-02-23 10:47:27 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-06-07 09:27:44 -04:00
|
|
|
# SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
2024-02-23 10:47:27 -05:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
me="${0##*/}"
|
|
|
|
|
|
|
|
usage(){
|
2024-06-07 09:27:44 -04:00
|
|
|
printf '%s\n' "Usage: ${me} [QVM-RUN_OPTIONS] <QUBE>
|
2024-02-23 10:47:27 -05:00
|
|
|
Examples:
|
2024-06-07 09:27:44 -04:00
|
|
|
${me} --dispvm=<DVM_TEMPLATE>
|
|
|
|
${me} -u root <QUBE>
|
|
|
|
${me} <QUBE>
|
|
|
|
The application to open can be specified with environment variables:
|
|
|
|
QVM_TERMINAL=xterm ${me} -u root <QUBE>
|
|
|
|
QVM_FILE_MANAGER=thunar ${me} -u root <QUBE>" >&2
|
2024-02-23 10:47:27 -05:00
|
|
|
exit "${1-"1"}"
|
|
|
|
}
|
|
|
|
|
|
|
|
case "${me}" in
|
2024-06-07 09:27:44 -04:00
|
|
|
*-terminal) service="${QVM_TERMINAL:-"qubes-run-terminal"}";;
|
|
|
|
*-file-manager) service="${QVM_FILE_MANAGER:-"qubes-open-file-manager"}";;
|
2024-02-23 10:47:27 -05:00
|
|
|
*) printf '%s\n' "Invalid script name: ${me}" exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
case "${1-}" in
|
|
|
|
-h|--help)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
"")
|
|
|
|
## Try to run on focused window, if Dom0 is focused, it will prompt you to
|
|
|
|
## select a qube window.
|
|
|
|
id="$(xdotool getwindowfocus)"
|
|
|
|
qube="$(xprop -id "${id}" -notype _QUBES_VMNAME | awk -F '"' '{print $2}')"
|
|
|
|
if test -n "${qube}"; then
|
|
|
|
exec qvm-run --service -- "${qube}" "qubes.StartApp+${service}"
|
|
|
|
fi
|
|
|
|
echo "Select a qube window ..."
|
|
|
|
id="$(xdotool selectwindow)"
|
|
|
|
qube="$(xprop -id "${id}" -notype _QUBES_VMNAME | awk -F '"' '{print $2}')"
|
|
|
|
if test -n "${qube}"; then
|
|
|
|
qvm-run --service -- "${qube}" "qubes.StartApp+${service}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
qvm-run --service "${@}" -- "qubes.StartApp+${service}"
|
|
|
|
;;
|
|
|
|
esac
|