Skip to content

Commit 5e5fc52

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 5e5fc52

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

app-menu/qubes-run-terminal

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
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_cmd(){
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
9+
exec_cmd(){
10+
if is_cmd "$1"; then
11+
exec "$1"
12+
fi
13+
}
1714

18-
if is_command gnome-terminal; then
19-
exec qubes-run-gnome-terminal
20-
fi
15+
reassign_term(){
16+
if ! is_cmd "$1"; then
17+
return
18+
fi
19+
case "$1" in
20+
gnome-terminal) terminal="qubes-run-$1";;
21+
kgx) terminal="qubes-run-gnome-console";;
22+
esac
23+
}
2124

22-
if is_command kgx; then
23-
exec qubes-run-gnome-console
25+
if is_cmd "${TERMINAL:-}"; then
26+
terminal="${TERMINAL}"
27+
reassign_term "$terminal"
28+
exec_cmd "$terminal"
2429
fi
2530

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
28-
exec "$terminal"
29-
fi
31+
for terminal in \
32+
x-terminal-emulator ptyxis gnome-terminal kgx xfce4-terminal konsole \
33+
urxvt rxvt termit terminator Eterm aterm roxterm termite lxterminal \
34+
mate-terminal terminology st lxterm xterm
35+
do
36+
reassign_term "$terminal"
37+
exec_cmd "$terminal"
3038
done
3139

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

0 commit comments

Comments
 (0)