-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathterminal.sh
More file actions
executable file
·69 lines (64 loc) · 1.61 KB
/
terminal.sh
File metadata and controls
executable file
·69 lines (64 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Prints a terminal prefix so callers can run: $(bash ./terminal.sh …) bash -lc 'cmd'
# gnome-terminal / cosmic-term use: term --flags -- bash -lc 'cmd'
# xterm uses: xterm -name … -T … -e bash -lc 'cmd'
ARGS=""
if [ $# -gt 0 ]; then
ARGS="$* "
fi
os_name=$(awk -F= '/^ID=/{gsub(/"/,"",$2); print $2}' /etc/os-release)
session="${XDG_SESSION_DESKTOP:-}"
case ":${XDG_CURRENT_DESKTOP:-}:" in *:COSMIC:*) session=COSMIC ;; esac
choose_terminal_by_session() {
case "${session}" in
COSMIC)
terminal="cosmic-term"
;;
gnome|Ubuntu|ubuntu|ubunt|pop|POP|Pop)
terminal="gnome-terminal"
;;
kde|plasma)
terminal="konsole"
;;
xfce)
terminal="xfce4-terminal"
;;
mate)
terminal="mate-terminal"
;;
*)
if [ "${XDG_SESSION_TYPE:-}" = wayland ] && command -v cosmic-term >/dev/null 2>&1; then
terminal="cosmic-term"
elif command -v gnome-terminal >/dev/null 2>&1; then
terminal="gnome-terminal"
else
terminal="xterm"
fi
;;
esac
}
emit_invocation() {
if [ "$terminal" = "xterm" ]; then
local _n="xterm" _t="xterm" _a
for _a in "$@"; do
case "$_a" in
--name=*) _n="${_a#--name=}" ;;
--title=*) _t="${_a#--title=}" ;;
esac
done
printf '%s\n' "xterm -name ${_n} -T ${_t} -e"
else
printf '%s\n' "$terminal ${ARGS}--"
fi
}
case "$os_name" in
debian|ubuntu|pop|fedora|arch)
choose_terminal_by_session
./install.sh "$terminal"
emit_invocation "$@"
;;
*)
echo "Unsupported OS" >&2
exit 1
;;
esac