Skip to content

Commit

Permalink
Unify method to query available terminals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ben-grande committed Feb 26, 2025
1 parent 529e8b2 commit 76a677b
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions app-menu/qubes-run-terminal
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
#!/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_command(){
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

if is_command gnome-terminal; then
exec qubes-run-gnome-terminal
fi
reassign_term(){
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_command "${TERMINAL:-}"; then
terminal="${TERMINAL}"
reassign_term "$terminal"
if is_command "$terminal"; then
exec "${terminal}"
fi
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
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"
if is_command "$terminal"; then
exec "$terminal"
fi
done

echo "ERROR: No suitable terminal found." >&2
exit 1

0 comments on commit 76a677b

Please sign in to comment.