From 5e5fc527d6764b736c38bf24c865f19ea2cf65b9 Mon Sep 17 00:00:00 2001 From: Ben Grande Date: Wed, 26 Feb 2025 19:35:35 +0100 Subject: [PATCH] Unify method to query available terminals Because of some exceptions such as gnome-terminal and kgx, the ordering was getting convoluted when considering precedence. Instead of adding new if statements every time a terminal requires precedence, run only add a new entry to the for loop. Also allows the user to enforce a terminal with environment variable TERMINAL. --- app-menu/qubes-run-terminal | 49 ++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/app-menu/qubes-run-terminal b/app-menu/qubes-run-terminal index 82fa8c17..6f9c3224 100755 --- a/app-menu/qubes-run-terminal +++ b/app-menu/qubes-run-terminal @@ -1,32 +1,41 @@ #!/bin/sh # Try to find a terminal emulator that's installed and run it. +set -eu -is_command() { - # bogus warning from ShellCheck < 0.5.0 - # shellcheck disable=SC2039 - type "$1" >/dev/null 2>&1 +is_cmd(){ + command -v "$1" >/dev/null } -if is_command x-terminal-emulator; then - exec x-terminal-emulator -fi - -if is_command ptyxis; then - exec ptyxis -fi +exec_cmd(){ + if is_cmd "$1"; then + exec "$1" + fi +} -if is_command gnome-terminal; then - exec qubes-run-gnome-terminal -fi +reassign_term(){ + if ! is_cmd "$1"; then + return + fi + case "$1" in + gnome-terminal) terminal="qubes-run-$1";; + kgx) terminal="qubes-run-gnome-console";; + esac +} -if is_command kgx; then - exec qubes-run-gnome-console +if is_cmd "${TERMINAL:-}"; then + terminal="${TERMINAL}" + reassign_term "$terminal" + exec_cmd "$terminal" fi -for terminal in xfce4-terminal konsole urxvt rxvt termit terminator Eterm aterm roxterm termite lxterminal mate-terminal terminology st xterm; do - if is_command "$terminal" ; then - exec "$terminal" - fi +for terminal in \ + x-terminal-emulator ptyxis gnome-terminal kgx xfce4-terminal konsole \ + urxvt rxvt termit terminator Eterm aterm roxterm termite lxterminal \ + mate-terminal terminology st lxterm xterm +do + reassign_term "$terminal" + exec_cmd "$terminal" done echo "ERROR: No suitable terminal found." >&2 +exit 1