feat(utils.sh): 添加密码输入功能

This commit is contained in:
Konano 2024-11-08 17:53:30 +08:00
parent 50c81fcaa3
commit 7fc4c53d78
Signed by: Nano
GPG Key ID: 93686B78EE43A65A

View File

@ -56,7 +56,7 @@ confirm_action() {
} }
command_exists() { command_exists() {
command -v "$@" >/dev/null 2>&1; command -v "$@" >/dev/null 2>&1
} }
pkg_install() { pkg_install() {
@ -69,6 +69,25 @@ pkg_install() {
fi 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 check_internet_access