mirror of
https://github.com/Snigdha-OS/snigdhaos-pkgbuilds.git
synced 2025-09-21 12:04:59 +02:00
🧹 chore(bump): rename && refactor
This commit is contained in:
@@ -14,20 +14,19 @@ CYAN="\033[1;36m"
|
|||||||
LAUNCH_TERMINAL_SHELL="bash"
|
LAUNCH_TERMINAL_SHELL="bash"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
# Use echo to output the help message with colors
|
||||||
${BOLD}Usage:${RESET} ${0##*/} [cmd] [options]
|
echo -e "${BOLD}Usage:${RESET} ${0##*/} [cmd] [options]"
|
||||||
|
echo -e ""
|
||||||
${BOLD}Options:${RESET}
|
echo -e "${BOLD}Options:${RESET}"
|
||||||
-s [shell] Change the shell to [shell].
|
echo -e " -s [shell] Change the shell to [shell]."
|
||||||
-h Display this help message.
|
echo -e " -h Display this help message."
|
||||||
|
echo -e ""
|
||||||
${BOLD}Description:${RESET}
|
echo -e "${BOLD}Description:${RESET}"
|
||||||
This script launches a specified command in an appropriate terminal emulator,
|
echo -e " This script launches a specified command in an appropriate terminal emulator,"
|
||||||
automatically detecting the best option based on the desktop environment.
|
echo -e " automatically detecting the best option based on the desktop environment."
|
||||||
|
echo -e ""
|
||||||
${BOLD}Examples:${RESET}
|
echo -e "${BOLD}Examples:${RESET}"
|
||||||
${CYAN}${0##*/} "echo Hello World" -s zsh${RESET}
|
echo -e " ${CYAN}${0##*/} \"echo Hello World\" -s zsh${RESET}"
|
||||||
EOF
|
|
||||||
exit "${1:-0}"
|
exit "${1:-0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,32 +50,18 @@ if [ $# -lt 1 ]; then
|
|||||||
fi
|
fi
|
||||||
COMMAND="$1"
|
COMMAND="$1"
|
||||||
|
|
||||||
# Temporary file for shell script execution
|
|
||||||
initfile="$(mktemp)"
|
|
||||||
codefile="$initfile"
|
|
||||||
trap 'rm -f "$initfile" "$codefile"' EXIT
|
|
||||||
|
|
||||||
echo "#!/usr/bin/env $LAUNCH_TERMINAL_SHELL" >"$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
|
# Detect terminal emulator
|
||||||
declare -A terminals=(
|
declare -A terminals=(
|
||||||
["alacritty"]="alacritty -e $cmd || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e $cmd"
|
["alacritty"]="alacritty -e bash -c"
|
||||||
["konsole"]="konsole -e $cmd"
|
["konsole"]="konsole -e bash -c"
|
||||||
["kgx"]="kgx -e $cmd"
|
["kgx"]="kgx -- bash -c"
|
||||||
["gnome-terminal"]="gnome-terminal --wait -- $cmd"
|
["gnome-terminal"]="gnome-terminal -- bash -c"
|
||||||
["xfce4-terminal"]="xfce4-terminal --disable-server --command '$cmd'"
|
["xfce4-terminal"]="xfce4-terminal --disable-server --command"
|
||||||
["qterminal"]="qterminal -e $cmd"
|
["qterminal"]="qterminal -e bash -c"
|
||||||
["lxterminal"]="lxterminal -e $cmd"
|
["lxterminal"]="lxterminal -e bash -c"
|
||||||
["mate-terminal"]="mate-terminal --disable-factory -e $cmd"
|
["mate-terminal"]="mate-terminal --disable-factory -e bash -c"
|
||||||
["xterm"]="xterm -e $cmd"
|
["xterm"]="xterm -e bash -c"
|
||||||
["foot"]="foot -T exec-terminal -e $cmd"
|
["foot"]="foot -T exec-terminal -e bash -c"
|
||||||
)
|
)
|
||||||
term_order=("alacritty" "konsole" "kgx" "gnome-terminal" "mate-terminal" "xfce4-terminal" "qterminal" "lxterminal" "xterm" "foot")
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Special case for "kgx" terminal
|
# Debug detected terminal
|
||||||
if [ "$terminal" == "kgx" ]; then
|
echo -e "${YELLOW}Detected terminal:${RESET} ${BOLD}${terminal}${RESET}"
|
||||||
sed -i '2i sleep 0.1' "$initfile"
|
|
||||||
echo 'kill -SIGINT $PPID' >>"$initfile"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Launch the selected terminal
|
# Launch the command in the terminal
|
||||||
echo -e "${CYAN}Launching command in terminal:${RESET} ${BOLD}${terminal}${RESET}"
|
echo -e "${CYAN}Launching command:${RESET} ${BOLD}${COMMAND}${RESET}"
|
||||||
eval "${terminals[${terminal}]}" || exitcode=$?
|
eval "${terminals[${terminal}]} \"${COMMAND}\"" || {
|
||||||
|
echo -e "${RED}Failed to launch command!${RESET}"
|
||||||
# Clean up temporary files and handle errors
|
|
||||||
if [ -n "$exitcode" ] && [ "$exitcode" != 130 ]; then
|
|
||||||
echo -e "${RED}Command failed with exit code:${RESET} ${exitcode}"
|
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
}
|
||||||
|
|
||||||
# Success message
|
# Success message
|
||||||
echo -e "${GREEN}Command executed successfully!${RESET}"
|
echo -e "${GREEN}Command executed successfully in terminal!${RESET}"
|
Reference in New Issue
Block a user