-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
529e8b2
commit 68b8642
Showing
1 changed file
with
26 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
#!/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(){ | ||
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 |