mirror of
https://github.com/Snigdha-OS/snigdhaos-system-config.git
synced 2025-09-20 19:44:58 +02:00
⚡️ perf(improvemnets): increase readiblity, error handling, simplification
This commit is contained in:
@@ -8,93 +8,100 @@ set -e
|
|||||||
LAUNCH_TERMINAL_SHELL=bash
|
LAUNCH_TERMINAL_SHELL=bash
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: ${0##*/} [cmd]"
|
echo "Usage: ${0##*/} [cmd]"
|
||||||
echo ' -s [shell] Change shell to [shell]'
|
echo ' -s [shell] Change shell to [shell]'
|
||||||
echo ' -h This help'
|
echo ' -h This help'
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
opts='s:h'
|
opts='s:h'
|
||||||
|
|
||||||
while getopts "${opts}" arg; do
|
while getopts "${opts}" arg; do
|
||||||
case "${arg}" in
|
case "${arg}" in
|
||||||
s) LAUNCH_TERMINAL_SHELL="$OPTARG" ;;
|
s) LAUNCH_TERMINAL_SHELL="$OPTARG" ;;
|
||||||
h | ?) usage 0 ;;
|
h | ?) usage 0 ;;
|
||||||
*)
|
*)
|
||||||
echo "invalid argument '${arg}'"
|
echo "invalid argument '${arg}'"
|
||||||
usage 1
|
usage 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
shift $(($OPTIND - 1))
|
shift $(($OPTIND - 1))
|
||||||
|
|
||||||
initfile="$(mktemp)"
|
initfile=$(mktemp)
|
||||||
codefile="$initfile"
|
codefile=$initfile
|
||||||
echo "#!/usr/bin/env bash" >"$initfile"
|
|
||||||
|
echo "#!/usr/bin/env bash" > "$initfile"
|
||||||
|
|
||||||
if [ "$LAUNCH_TERMINAL_SHELL" != "bash" ]; then
|
if [ "$LAUNCH_TERMINAL_SHELL" != "bash" ]; then
|
||||||
codefile="$(mktemp)"
|
codefile=$(mktemp)
|
||||||
echo "$LAUNCH_TERMINAL_SHELL $codefile" >>"$initfile"
|
echo "$LAUNCH_TERMINAL_SHELL $codefile" >> "$initfile"
|
||||||
fi
|
fi
|
||||||
echo "$1" >>"$codefile"
|
|
||||||
|
echo "$1" >> "$codefile"
|
||||||
chmod +x "$initfile"
|
chmod +x "$initfile"
|
||||||
cmd="\"$initfile\""
|
cmd="\"$initfile\""
|
||||||
|
|
||||||
terminal=""
|
declare -A terminals=(
|
||||||
declare -A terminals=(["alacritty"]="alacritty -e $cmd || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e $cmd" ["konsole"]="konsole -e $cmd" ["kgx"]="kgx -- $cmd" ["gnome-terminal"]="gnome-terminal --wait -- $cmd" ["xfce4-terminal"]="xfce4-terminal --disable-server --command '$cmd'" ["qterminal"]="qterminal -e $cmd" ["lxterminal"]="lxterminal -e $cmd" ["mate-terminal"]="mate-terminal --disable-factory -e $cmd" ["xterm"]="xterm -e $cmd" ["foot"]="foot -T launch-terminal -e $cmd")
|
["alacritty"]="alacritty -e $cmd || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e $cmd"
|
||||||
declare -a term_order=("alacritty" "konsole" "kgx" "gnome-terminal" "mate-terminal" "xfce4-terminal" "qterminal" "lxterminal" "xterm" "foot")
|
["konsole"]="konsole -e $cmd"
|
||||||
|
["kgx"]="kgx -- $cmd"
|
||||||
|
["gnome-terminal"]="gnome-terminal --wait -- $cmd"
|
||||||
|
["xfce4-terminal"]="xfce4-terminal --disable-server --command '$cmd'"
|
||||||
|
["qterminal"]="qterminal -e $cmd"
|
||||||
|
["lxterminal"]="lxterminal -e $cmd"
|
||||||
|
["mate-terminal"]="mate-terminal --disable-factory -e $cmd"
|
||||||
|
["xterm"]="xterm -e $cmd"
|
||||||
|
["foot"]="foot -T launch-terminal -e $cmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
declare -a term_order=(
|
||||||
|
"alacritty" "konsole" "kgx" "gnome-terminal" "mate-terminal"
|
||||||
|
"xfce4-terminal" "qterminal" "lxterminal" "xterm" "foot"
|
||||||
|
)
|
||||||
|
|
||||||
case "$XDG_CURRENT_DESKTOP" in
|
case "$XDG_CURRENT_DESKTOP" in
|
||||||
KDE)
|
KDE) terminal=konsole ;;
|
||||||
terminal=konsole
|
GNOME)
|
||||||
;;
|
if command -v "kgx" &> /dev/null; then
|
||||||
GNOME)
|
terminal=kgx
|
||||||
if command -v "kgx" &>/dev/null; then
|
else
|
||||||
terminal=kgx
|
terminal=gnome-terminal
|
||||||
else
|
fi
|
||||||
terminal=gnome-terminal
|
;;
|
||||||
fi
|
XFCE) terminal=xfce4-terminal ;;
|
||||||
;;
|
LXQt) terminal=qterminal ;;
|
||||||
XFCE)
|
MATE) terminal=mate-terminal ;;
|
||||||
terminal=xfce4-terminal
|
*)
|
||||||
;;
|
for i in "${term_order[@]}"; do
|
||||||
LXQt)
|
if command -v "$i" &> /dev/null; then
|
||||||
terminal=qterminal
|
terminal=$i
|
||||||
;;
|
break
|
||||||
MATE)
|
fi
|
||||||
terminal=mate-terminal
|
done
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -z "$terminal" ] || ! command -v "$terminal" &>/dev/null; then
|
|
||||||
for i in ${term_order[@]}; do
|
|
||||||
if command -v "$i" &>/dev/null; then
|
|
||||||
terminal="$i"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$terminal" ]; then
|
if [ -z "$terminal" ]; then
|
||||||
notify-send -t 15000 --app-name=Garuda\ Linux "No terminal installed" "No supported terminal emulator is installed. Please install a terminal emulator like Alacritty."
|
notify-send -t 15000 --app-name=Snigdha\ OS "No terminal installed" "No supported terminal emulator is installed. Please install a terminal emulator like Alacritty."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Special kgx, thanks gnome
|
if [ "$terminal" = "kgx" ]; then
|
||||||
if [ "$terminal" == "kgx" ]; then
|
sed -i '2i sleep 0.1' "$initfile"
|
||||||
sed -i '2i sleep 0.1' $initfile
|
echo 'kill -SIGINT $PPID' >> "$initfile"
|
||||||
echo 'kill -SIGINT $PPID' >>$initfile
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eval "${terminals[${terminal}]}" || {
|
eval "${terminals[$terminal]}" || {
|
||||||
exitcode=$?
|
exitcode=$?
|
||||||
}
|
}
|
||||||
|
|
||||||
rm "$initfile"
|
rm "$initfile"
|
||||||
if [ "$codefile" != "$initfile" ]; then
|
if [ "$codefile" != "$initfile" ]; then
|
||||||
rm "$codefile"
|
rm "$codefile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$exitcode" ] && [ "$exitcode" != 130 ]; then
|
if [ -n "$exitcode" ] && [ "$exitcode" != 130 ]; then
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
Reference in New Issue
Block a user