From 7fc4c53d780ac546436b025f69ace4c8e13074ad Mon Sep 17 00:00:00 2001 From: Konano Date: Fri, 8 Nov 2024 17:53:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils.sh):=20=E6=B7=BB=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E8=BE=93=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/utils.sh b/utils.sh index 31adeae..535f441 100755 --- a/utils.sh +++ b/utils.sh @@ -56,7 +56,7 @@ confirm_action() { } command_exists() { - command -v "$@" >/dev/null 2>&1; + command -v "$@" >/dev/null 2>&1 } pkg_install() { @@ -69,6 +69,25 @@ pkg_install() { fi } +read_password() { + echo -n "Password: " + password="" + while IFS= read -r -s -n1 char; do + if [[ $char == $'\0' ]]; then + break + elif [[ $char == $'\177' ]]; then + if [ -n "$password" ]; then + password=${password%?} + echo -ne "\b \b" + fi + else + password+="$char" + echo -n "*" + fi + done + echo +} + # ============================================================ check_internet_access