Skip to content

Commit 76a677b

Browse files
committed
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.
1 parent 529e8b2 commit 76a677b

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

app-menu/qubes-run-terminal

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
#!/bin/sh
22
# Try to find a terminal emulator that's installed and run it.
3+
set -eu
34

4-
is_command() {
5-
# bogus warning from ShellCheck < 0.5.0
6-
# shellcheck disable=SC2039
7-
type "$1" >/dev/null 2>&1
5+
is_command(){
6+
command -v "$1" >/dev/null
87
}
98

10-
if is_command x-terminal-emulator; then
11-
exec x-terminal-emulator
12-
fi
13-
14-
if is_command ptyxis; then
15-
exec ptyxis
16-
fi
17-
18-
if is_command gnome-terminal; then
19-
exec qubes-run-gnome-terminal
20-
fi
9+
reassign_term(){
10+
case "$1" in
11+
gnome-terminal) terminal="qubes-run-$1";;
12+
kgx) terminal="qubes-run-gnome-console";;
13+
esac
14+
}
2115

22-
if is_command kgx; then
23-
exec qubes-run-gnome-console
16+
if is_command "${TERMINAL:-}"; then
17+
terminal="${TERMINAL}"
18+
reassign_term "$terminal"
19+
if is_command "$terminal"; then
20+
exec "${terminal}"
21+
fi
2422
fi
2523

26-
for terminal in xfce4-terminal konsole urxvt rxvt termit terminator Eterm aterm roxterm termite lxterminal mate-terminal terminology st xterm; do
27-
if is_command "$terminal" ; then
24+
for terminal in \
25+
x-terminal-emulator ptyxis gnome-terminal kgx xfce4-terminal konsole \
26+
urxvt rxvt termit terminator Eterm aterm roxterm termite lxterminal \
27+
mate-terminal terminology st lxterm xterm
28+
do
29+
reassign_term "$terminal"
30+
if is_command "$terminal"; then
2831
exec "$terminal"
2932
fi
3033
done
3134

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

0 commit comments

Comments
 (0)