diff --git a/usr/bin/launch-terminal b/usr/bin/launch-terminal index 1d8e2e2..cbd1c63 100755 --- a/usr/bin/launch-terminal +++ b/usr/bin/launch-terminal @@ -61,20 +61,20 @@ echo "$1" >> "$codefile" chmod +x "$initfile" # Command to run in the terminal emulator -cmd="\"$initfile\"" +cmd="$initfile" # Define a dictionary of supported terminal emulators 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 bash -c \"$cmd\" || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e bash -c \"$cmd\"" + ["konsole"]="konsole --noclose -e bash -c \"$cmd\"" + ["kgx"]="kgx -- bash -c \"$cmd\"" + ["gnome-terminal"]="gnome-terminal --wait -- bash -c \"$cmd\"" + ["xfce4-terminal"]="xfce4-terminal --disable-server --command bash -c \"$cmd\"" + ["qterminal"]="qterminal -e bash -c \"$cmd\"" + ["lxterminal"]="lxterminal -e bash -c \"$cmd\"" + ["mate-terminal"]="mate-terminal --disable-factory -e bash -c \"$cmd\"" + ["xterm"]="xterm -e bash -c \"$cmd\"" + ["foot"]="foot -T launch-terminal -e bash -c \"$cmd\"" ) # Define an ordered list of terminals to try @@ -84,6 +84,7 @@ declare -a term_order=( ) # Select the terminal based on the desktop environment +terminal="" case "$XDG_CURRENT_DESKTOP" in KDE) terminal="konsole" ;; GNOME) @@ -108,11 +109,15 @@ esac # If no terminal emulator is found, notify and exit if [ -z "$terminal" ]; then - notify-send -t 15000 --app-name=Snigdha\ OS "No terminal installed" \ + 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 fi +# Debugging information +echo "Selected terminal: $terminal" +echo "Command to execute: ${terminals[$terminal]}" + # Special handling for kgx to ensure proper behavior if [ "$terminal" = "kgx" ]; then sed -i '2i sleep 0.1' "$initfile" @@ -120,6 +125,7 @@ if [ "$terminal" = "kgx" ]; then fi # Run the terminal emulator with the command +exitcode=0 eval "${terminals[$terminal]}" || exitcode=$? # Clean up temporary files @@ -128,8 +134,10 @@ if [ "$codefile" != "$initfile" ]; then rm "$codefile" fi -# Exit gracefully if no terminal error occurred, otherwise propagate the error -if [ -n "${exitcode-}" ] && [ "$exitcode" != 130 ]; then +# Exit handling +if [ "$exitcode" -eq 0 ]; then + echo "Terminal executed the command successfully." +elif [ "$exitcode" -ne 130 ]; then echo "Error: Terminal launch failed with exit code $exitcode" - exit 2 + exit "$exitcode" fi