Skip to content

Commit a1f3420

Browse files
committed
🧹 terminal-helper: cleanup with formatter & shellcheck
1 parent 0e78970 commit a1f3420

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

‎src/scripts/terminal-helper‎

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,76 @@ usage() {
2121
echo "Usage: ${0##*/} [cmd]"
2222
echo ' -s [shell] Change shell to [shell]'
2323
echo ' -h This help'
24-
exit 1
24+
exit "$1"
2525
}
2626

2727
opts='s:h'
2828

2929
while getopts "${opts}" arg; do
3030
case "${arg}" in
31-
s) LAUNCHER_CMD="$OPTARG" ;;
32-
h|?) usage 0 ;;
33-
*) echo "invalid argument '${arg}'"; usage 1 ;;
31+
s) LAUNCHER_CMD="$OPTARG" ;;
32+
h | ?) usage 0 ;;
33+
*)
34+
echo "invalid argument '${arg}'"
35+
usage 1
36+
;;
3437
esac
3538
done
3639

37-
shift $(($OPTIND - 1))
40+
# OPTIND is a global variable
41+
shift $((OPTIND - 1))
3842

3943
file="$(mktemp)"
40-
echo "$1" > "$file"
44+
echo "$1" >"$file"
4145
cmd="${LAUNCHER_CMD} \"$file\""
42-
echo $cmd
46+
echo "$cmd"
4347

44-
#declare -a terminals=(x-terminal-emulator mate-terminal gnome-terminal terminator xfce4-terminal urxvt rxvt termit Eterm aterm uxterm xterm roxterm termite lxterminal terminology st qterminal lilyterm tilix terminix konsole kitty guake tilda alacritty)
4548
terminal=""
46-
declare -A terminals=( ["alacritty"]="alacritty -e $cmd || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e $cmd" ["rio"]="rio -e $cmd" ["ghostty"]="ghostty -e $cmd" ["kitty"]="kitty $cmd" ["konsole"]="konsole -e $cmd" ["gnome-console"]="kgx --wait -e $cmd" ["gnome-terminal"]="gnome-terminal --wait -- $cmd" ["xfce4-terminal"]="xfce4-terminal --disable-server --command '$cmd'" ["lxterminal"]="lxterminal -e $cmd" ["xterm"]="xterm -e $cmd" ["st"]="st $cmd" ["foot"]="foot $cmd")
47-
declare -a term_order=( "alacritty" "rio" "ghostty" "kitty" "konsole" "gnome-console" "gnome-terminal" "xfce4-terminal" "lxterminal" "xterm" "st" "foot")
49+
declare -A terminals=(
50+
["alacritty"]="alacritty -e $cmd || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e $cmd"
51+
["foot"]="foot $cmd"
52+
["ghostty"]="ghostty -e $cmd"
53+
["gnome-console"]="kgx --wait -e $cmd"
54+
["gnome-terminal"]="gnome-terminal --wait -- $cmd"
55+
["kitty"]="kitty $cmd"
56+
["konsole"]="konsole -e $cmd"
57+
["lxterminal"]="lxterminal -e $cmd"
58+
["rio"]="rio -e $cmd"
59+
["st"]="st $cmd"
60+
["xfce4-terminal"]="xfce4-terminal --disable-server --command '$cmd'"
61+
["xterm"]="xterm -e $cmd"
62+
)
63+
declare -a term_order=(
64+
"alacritty"
65+
"rio"
66+
"ghostty"
67+
"kitty"
68+
"konsole"
69+
"gnome-console"
70+
"gnome-terminal"
71+
"xfce4-terminal"
72+
"lxterminal"
73+
"xterm"
74+
"st"
75+
"foot"
76+
)
4877

49-
if [ -z "$terminal" ] || ! command -v "$terminal" &> /dev/null; then
50-
for entry in ${term_order[@]}; do
51-
if command -v "$entry" > /dev/null 2>&1; then
52-
terminal="$entry"
53-
break;
54-
fi
55-
done
78+
if [ -z "$terminal" ] || ! command -v "$terminal" &>/dev/null; then
79+
for entry in "${term_order[@]}"; do
80+
if command -v "$entry" >/dev/null 2>&1; then
81+
terminal="$entry"
82+
break
83+
fi
84+
done
5685
fi
5786

5887
if [ -z "$terminal" ]; then
5988
notify-send -t 1500 --app-name=CachyOS "No terminal installed" "Could not find a terminal emulator. Please install one."
6089
exit 1
6190
fi
6291

63-
eval "${terminals[${terminal}]}" || { rm "$file"; exit 2; }
92+
eval "${terminals[${terminal}]}" || {
93+
rm "$file"
94+
exit 2
95+
}
6496
rm "$file"

0 commit comments

Comments
 (0)