mirror of
https://github.com/ben-grande/qusal.git
synced 2025-02-11 20:48:43 -05:00
![Ben Grande](/assets/img/avatar_default.png)
- Add to qvm-run: - no-gui when command doesn't require a GUI - filter-escape-chars when pass-io is set and output is not a file, such as a pipe that could later be used to print information. - Change remaining echo to printf - Add end-of-options separator when possible
81 lines
1.9 KiB
Bash
Executable File
81 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# SPDX-FileCopyrightText: 2023 - 2025 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
set -eu
|
|
|
|
me="${0##*/}"
|
|
|
|
msg(){
|
|
printf '%s\n' "${0##*/}: ${*}" >&2
|
|
}
|
|
|
|
usage(){
|
|
msg "Usage: ${me} [QVM-RUN_OPTIONS] <QUBE>
|
|
Examples:
|
|
${me} --dispvm=<DVM_TEMPLATE>
|
|
${me} -u root <QUBE>
|
|
${me} <QUBE>
|
|
The desktop application can be specified with environment variable:"
|
|
case "${me}" in
|
|
*-terminal)
|
|
msg " QVM_TERMINAL=xterm ${me} -u root <QUBE>"
|
|
;;
|
|
*-file-manager)
|
|
msg " QVM_FILE_MANAGER=thunar ${me} -u root <QUBE>"
|
|
;;
|
|
*) ;;
|
|
esac
|
|
exit "${1-"1"}"
|
|
}
|
|
|
|
check_xtools(){
|
|
fail=0
|
|
if ! command -v xdotool >/dev/null; then
|
|
msg "missing program: xdotool"
|
|
fail=1
|
|
fi
|
|
if ! command -v xprop >/dev/null; then
|
|
msg "missing program: xprop"
|
|
fail=1
|
|
fi
|
|
if test "${fail}" = "1"; then
|
|
msg "cannot determine qube by window, install missing programs or"
|
|
msg "provide the qube name by argument"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
case "${me}" in
|
|
*-terminal) service="${QVM_TERMINAL:-"qubes-run-terminal"}";;
|
|
*-file-manager) service="${QVM_FILE_MANAGER:-"qubes-open-file-manager"}";;
|
|
*) msg "Invalid script name: ${me}"; exit 1 ;;
|
|
esac
|
|
|
|
case "${1-}" in
|
|
-h|--help)
|
|
usage 1
|
|
;;
|
|
"")
|
|
check_xtools
|
|
## 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
|
|
printf '%s\n' "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
|