diff --git a/snigdhaos-libs/check-snapshot-boot b/snigdhaos-libs/check-snapshot-boot old mode 100644 new mode 100755 diff --git a/snigdhaos-libs/exec-terminal b/snigdhaos-libs/exec-terminal old mode 100644 new mode 100755 index 60bac4f8..322bf02b --- a/snigdhaos-libs/exec-terminal +++ b/snigdhaos-libs/exec-terminal @@ -1,69 +1,103 @@ #!/bin/bash set -e -LAUNCH_TERMINAL_SHELL=bash +# Color definitions +RESET="\033[0m" +BOLD="\033[1m" +RED="\033[1;31m" +GREEN="\033[1;32m" +YELLOW="\033[1;33m" +BLUE="\033[1;34m" +CYAN="\033[1;36m" -usage(){ - echo "Usage: ${0##*/} [cmd]" - echo ' -s [shell] Change shell to [shell]' - echo ' -h This help' - exit 1 +# Default shell +LAUNCH_TERMINAL_SHELL="bash" + +usage() { + cat <"$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 "$1" >>"$codefile" +echo "$COMMAND" >>"$codefile" chmod +x "$initfile" cmd="\"$initfile\"" -terminal="" -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") -declare -a term_order=("alacritty" "knosole" "kgx" "gnome-terminal" "mate-terminal" "xfce4-terminal" "qterminal" "lxterminal" "xterm" "foot") +# 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" +) +term_order=("alacritty" "konsole" "kgx" "gnome-terminal" "mate-terminal" "xfce4-terminal" "qterminal" "lxterminal" "xterm" "foot") +# Desktop environment-specific terminal preference case "$XDG_CURRENT_DESKTOP" in -KDE) - terminal="konsole" - ;; -GNOME) - if command -v "kgx" &>/dev/null; then - terminal=kgx - else - terminal=gnome-terminal - fi - ;; -XFCE) - terminal=xfce4-terminal - ;; -LXQt) - terminal=qterminal - ;; -MATE) - terminal=mate-terminal - ;; + KDE) terminal="konsole" ;; + GNOME) + if command -v "kgx" &>/dev/null; then + terminal="kgx" + else + terminal="gnome-terminal" + fi + ;; + XFCE) terminal="xfce4-terminal" ;; + LXQt) terminal="qterminal" ;; + MATE) terminal="mate-terminal" ;; esac +# Fallback: Check for available terminals if [ -z "$terminal" ] || ! command -v "$terminal" &>/dev/null; then - # shellcheck disable=SC2068 - for i in ${term_order[@]}; do + for i in "${term_order[@]}"; do if command -v "$i" &>/dev/null; then terminal="$i" break @@ -71,29 +105,28 @@ if [ -z "$terminal" ] || ! command -v "$terminal" &>/dev/null; then done fi +# Error handling if no terminal is found if [ -z "$terminal" ]; then - notify-send -t 1500 --app-name=Snigdha\ OS "No Terminal Found!" + echo -e "${RED}Error:${RESET} No terminal emulator found!" + notify-send -t 1500 --app-name="Terminal Launcher" "No terminal emulator found!" exit 1 fi +# Special case for "kgx" terminal if [ "$terminal" == "kgx" ]; then - # shellcheck disable=SC2086 - sed -i '2i sleep 0.1' $initfile - # shellcheck disable=SC2016 - # shellcheck disable=SC2086 - echo 'Kill -SIGNINT $PPID' >>$initfile + sed -i '2i sleep 0.1' "$initfile" + echo 'kill -SIGINT $PPID' >>"$initfile" fi -eval "${terminals[${terminal}]}" || { - exitcode=$? -} +# Launch the selected terminal +echo -e "${CYAN}Launching command in terminal:${RESET} ${BOLD}${terminal}${RESET}" +eval "${terminals[${terminal}]}" || exitcode=$? -rm "$initfile" - -if [ "$codefile" != "$initfile" ]; then - rm "$codefile" -fi - -if [ ! -z "$exitcode" ] && [ "$exitcode" != 130 ]; then +# 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 -fi \ No newline at end of file +fi + +# Success message +echo -e "${GREEN}Command executed successfully!${RESET}" diff --git a/snigdhaos-libs/install-package b/snigdhaos-libs/install-package old mode 100644 new mode 100755 diff --git a/snigdhaos-libs/pkexec-gui b/snigdhaos-libs/pkexec-gui old mode 100644 new mode 100755