From 2d598da654e510d4a0be7e67fa801346da9c63fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?h=CE=B1rsh=20v=CE=B1ir=CE=B1gi?= Date: Sat, 27 Jan 2024 10:14:26 +0530 Subject: [PATCH] Code optimised --- src/ask.sh | 11 +++++------ src/package.sh | 8 ++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/ask.sh b/src/ask.sh index 24a0c74..a5a5a65 100644 --- a/src/ask.sh +++ b/src/ask.sh @@ -27,9 +27,9 @@ ask.case(){ read -p " ? [Y/n] " ARGS; echo; case "${ARGS}" in - y|Y) return 0;; + y|Y|'') return 0;; n|N) { say.error "Process Aborted.\n" && exit 1; };; - *) { say.error "You have to enter only\n\t\t'Y' for Yes &\n\t\t'n' for No.\n" && exit 1; };; + *) { say.error "You have to enter only \n\t\t'Y' for Yes & \n\t\t'n' for No.\n" && exit 1; };; esac } @@ -43,16 +43,15 @@ ask.case(){ ask.choice(){ PS3=" ${1} > "; + shift; local ARGs=("${@}"); - # leave first variable of array for title. - local ARGs2=("${ARGs[@]:1}"); echo; - select ARG in "${ARGs2[@]}" + select ARG in "${ARGs[@]}" do text.isdigit "${REPLY}" || { say.error "You can only input 'digits'.\n" && exit 1; }; - [[ "${REPLY}" -gt "${#ARGs2[@]}" ]] && + [[ "${REPLY}" -gt "${#ARGs[@]}" ]] && say.error "You should input correct digits.\n" && exit 1; askChoice="${ARG}"; askReply="${REPLY}"; diff --git a/src/package.sh b/src/package.sh index f8bcf5c..3af0839 100644 --- a/src/package.sh +++ b/src/package.sh @@ -45,9 +45,7 @@ pkg.size(){ 'MB') echo "${Size}";; 'kB') echo "$(( Size/1024 ))";; 'B') echo "$(( Size/1048576 ))";; - esac - # return function. - return; + esac } # pkg.chart(pkgs) @@ -114,9 +112,7 @@ pkg.install(){ do spinner.start 'Installing' "${ARG}"; # started installation. - if os.is_termux; then - apt-get install -qq "${ARG}" > /dev/null; - elif os.is_shell.zsh; then + if os.is_termux || os.is_shell.zsh; then apt-get install -qq "${ARG}" > /dev/null; else sudo apt-get install -qq "${ARG}" > /dev/null;