diff --git a/snigdhaos-libs/exec-terminal b/snigdhaos-libs/launch-terminal similarity index 50% rename from snigdhaos-libs/exec-terminal rename to snigdhaos-libs/launch-terminal index 322bf02b..4acec216 100755 --- a/snigdhaos-libs/exec-terminal +++ b/snigdhaos-libs/launch-terminal @@ -14,20 +14,19 @@ CYAN="\033[1;36m" LAUNCH_TERMINAL_SHELL="bash" usage() { - cat <"$initfile" -if [ "$LAUNCH_TERMINAL_SHELL" != "bash" ]; then - codefile="$(mktemp)" - echo "$LAUNCH_TERMINAL_SHELL $codefile" >>"$initfile" -fi -echo "$COMMAND" >>"$codefile" -chmod +x "$initfile" -cmd="\"$initfile\"" - # Detect terminal emulator declare -A terminals=( - ["alacritty"]="alacritty -e $cmd || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e $cmd" - ["konsole"]="konsole -e $cmd" - ["kgx"]="kgx -e $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 exec-terminal -e $cmd" + ["alacritty"]="alacritty -e bash -c" + ["konsole"]="konsole -e bash -c" + ["kgx"]="kgx -- bash -c" + ["gnome-terminal"]="gnome-terminal -- bash -c" + ["xfce4-terminal"]="xfce4-terminal --disable-server --command" + ["qterminal"]="qterminal -e bash -c" + ["lxterminal"]="lxterminal -e bash -c" + ["mate-terminal"]="mate-terminal --disable-factory -e bash -c" + ["xterm"]="xterm -e bash -c" + ["foot"]="foot -T exec-terminal -e bash -c" ) term_order=("alacritty" "konsole" "kgx" "gnome-terminal" "mate-terminal" "xfce4-terminal" "qterminal" "lxterminal" "xterm" "foot") @@ -112,21 +97,15 @@ if [ -z "$terminal" ]; then exit 1 fi -# Special case for "kgx" terminal -if [ "$terminal" == "kgx" ]; then - sed -i '2i sleep 0.1' "$initfile" - echo 'kill -SIGINT $PPID' >>"$initfile" -fi +# Debug detected terminal +echo -e "${YELLOW}Detected terminal:${RESET} ${BOLD}${terminal}${RESET}" -# Launch the selected terminal -echo -e "${CYAN}Launching command in terminal:${RESET} ${BOLD}${terminal}${RESET}" -eval "${terminals[${terminal}]}" || exitcode=$? - -# Clean up temporary files and handle errors -if [ -n "$exitcode" ] && [ "$exitcode" != 130 ]; then - echo -e "${RED}Command failed with exit code:${RESET} ${exitcode}" +# Launch the command in the terminal +echo -e "${CYAN}Launching command:${RESET} ${BOLD}${COMMAND}${RESET}" +eval "${terminals[${terminal}]} \"${COMMAND}\"" || { + echo -e "${RED}Failed to launch command!${RESET}" exit 2 -fi +} # Success message -echo -e "${GREEN}Command executed successfully!${RESET}" +echo -e "${GREEN}Command executed successfully in terminal!${RESET}"