Tweaks for text and names

This commit is contained in:
clsty
2025-10-02 05:54:35 +08:00
parent f87e6e2b6a
commit 34c9cbeedb
29 changed files with 117 additions and 132 deletions
+21 -21
View File
@@ -8,60 +8,60 @@
function try { "$@" || sleep 0; }
function v(){
echo -e "####################################################"
echo -e "${COLOR_BLUE}[$0]: Next command:${COLOR_RESET}"
echo -e "${COLOR_GREEN}$@${COLOR_RESET}"
echo -e "${STY_BLUE}[$0]: Next command:${STY_RESET}"
echo -e "${STY_GREEN}$@${STY_RESET}"
execute=true
if $ask;then
while true;do
echo -e "${COLOR_BLUE}Execute? ${COLOR_RESET}"
echo -e "${STY_BLUE}Execute? ${STY_RESET}"
echo " y = Yes"
echo " e = Exit now"
echo " s = Skip this command (NOT recommended - your setup might not work correctly)"
echo " yesforall = Yes and don't ask again; NOT recommended unless you really sure"
read -p "====> " p
case $p in
[yY]) echo -e "${COLOR_BLUE}OK, executing...${COLOR_RESET}" ;break ;;
[eE]) echo -e "${COLOR_BLUE}Exiting...${COLOR_RESET}" ;exit ;break ;;
[sS]) echo -e "${COLOR_BLUE}Alright, skipping this one...${COLOR_RESET}" ;execute=false ;break ;;
"yesforall") echo -e "${COLOR_BLUE}Alright, won't ask again. Executing...${COLOR_RESET}"; ask=false ;break ;;
*) echo -e "${COLOR_RED}Please enter [y/e/s/yesforall].${COLOR_RESET}";;
[yY]) echo -e "${STY_BLUE}OK, executing...${STY_RESET}" ;break ;;
[eE]) echo -e "${STY_BLUE}Exiting...${STY_RESET}" ;exit ;break ;;
[sS]) echo -e "${STY_BLUE}Alright, skipping this one...${STY_RESET}" ;execute=false ;break ;;
"yesforall") echo -e "${STY_BLUE}Alright, won't ask again. Executing...${STY_RESET}"; ask=false ;break ;;
*) echo -e "${STY_RED}Please enter [y/e/s/yesforall].${STY_RESET}";;
esac
done
fi
if $execute;then x "$@";else
echo -e "${COLOR_YELLOW}[$0]: Skipped \"$@\"${COLOR_RESET}"
echo -e "${STY_YELLOW}[$0]: Skipped \"$@\"${STY_RESET}"
fi
}
# When use v() for a defined function, use x() INSIDE its definition to catch errors.
function x(){
if "$@";then cmdstatus=0;else cmdstatus=1;fi # 0=normal; 1=failed; 2=failed but ignored
while [ $cmdstatus == 1 ] ;do
echo -e "${COLOR_RED}[$0]: Command \"${COLOR_GREEN}$@${COLOR_RED}\" has failed."
echo -e "${STY_RED}[$0]: Command \"${STY_GREEN}$@${STY_RED}\" has failed."
echo -e "You may need to resolve the problem manually BEFORE repeating this command."
echo -e "[Tip] If a certain package is failing to install, try installing it separately in another terminal.${COLOR_RESET}"
echo -e "[Tip] If a certain package is failing to install, try installing it separately in another terminal.${STY_RESET}"
echo " r = Repeat this command (DEFAULT)"
echo " e = Exit now"
echo " i = Ignore this error and continue (your setup might not work correctly)"
read -p " [R/e/i]: " p
case $p in
[iI]) echo -e "${COLOR_BLUE}Alright, ignore and continue...${COLOR_RESET}";cmdstatus=2;;
[eE]) echo -e "${COLOR_BLUE}Alright, will exit.${COLOR_RESET}";break;;
*) echo -e "${COLOR_BLUE}OK, repeating...${COLOR_RESET}"
[iI]) echo -e "${STY_BLUE}Alright, ignore and continue...${STY_RESET}";cmdstatus=2;;
[eE]) echo -e "${STY_BLUE}Alright, will exit.${STY_RESET}";break;;
*) echo -e "${STY_BLUE}OK, repeating...${STY_RESET}"
if "$@";then cmdstatus=0;else cmdstatus=1;fi
;;
esac
done
case $cmdstatus in
0) echo -e "${COLOR_BLUE}[$0]: Command \"${COLOR_GREEN}$@${COLOR_BLUE}\" finished.${COLOR_RESET}";;
1) echo -e "${COLOR_RED}[$0]: Command \"${COLOR_GREEN}$@${COLOR_RED}\" has failed. Exiting...${COLOR_RESET}";exit 1;;
2) echo -e "${COLOR_RED}[$0]: Command \"${COLOR_GREEN}$@${COLOR_RED}\" has failed but ignored by user.${COLOR_RESET}";;
0) echo -e "${STY_BLUE}[$0]: Command \"${STY_GREEN}$@${STY_BLUE}\" finished.${STY_RESET}";;
1) echo -e "${STY_RED}[$0]: Command \"${STY_GREEN}$@${STY_RED}\" has failed. Exiting...${STY_RESET}";exit 1;;
2) echo -e "${STY_RED}[$0]: Command \"${STY_GREEN}$@${STY_RED}\" has failed but ignored by user.${STY_RESET}";;
esac
}
function showfun(){
echo -e "${COLOR_BLUE}[$0]: The definition of function \"$1\" is as follows:${COLOR_RESET}"
printf "${COLOR_GREEN}"
echo -e "${STY_BLUE}[$0]: The definition of function \"$1\" is as follows:${STY_RESET}"
printf "${STY_GREEN}"
type -a $1
printf "${COLOR_RESET}"
printf "${STY_RESET}"
}
function remove_bashcomments_emptylines(){
mkdir -p $(dirname $2)
@@ -69,6 +69,6 @@ function remove_bashcomments_emptylines(){
}
function prevent_sudo_or_root(){
case $(whoami) in
root) echo -e "${COLOR_RED}[$0]: This script is NOT to be executed with sudo or as root. Aborting...${COLOR_RESET}";exit 1;;
root) echo -e "${STY_RED}[$0]: This script is NOT to be executed with sudo or as root. Aborting...${STY_RESET}";exit 1;;
esac
}