Merge branch 'master' of github.com:dylanaraps/pash

This commit is contained in:
Dylan Araps 2019-11-30 18:15:04 +00:00
commit 3052a416ca
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 23 additions and 9 deletions

32
pash
View File

@ -19,16 +19,15 @@ pw_add() {
dd ibs=1 obs=1 count="${PASH_LENGTH:-50}" 2>/dev/null) dd ibs=1 obs=1 count="${PASH_LENGTH:-50}" 2>/dev/null)
else else
printf 'Enter password: ' # 'sread()' is a simple wrapper function around 'read'
# to prevent user input from being printed to the terminal.
sread pass "Enter password"
sread pass2 "Enter password (again)"
# Disable terminal printing while the user inputs their # Disable this check as we dynamically populate the two
# password. POSIX 'read' has no '-s' flag which would # passwords using the 'sread()' function.
# effectively do the same thing. # shellcheck disable=2154
stty -echo [ "$pass" = "$pass2" ] || die "Passwords do not match"
read -r pass
stty echo
printf '\n'
fi fi
[ "$pass" ] || die "Failed to generate a password" [ "$pass" ] || die "Failed to generate a password"
@ -120,6 +119,21 @@ yn() {
glob "$answer" '[yY]' glob "$answer" '[yY]'
} }
sread() {
# This is a simple wrapper around POSIX 'read' to print
# a prompt and disable printing of user input.
printf '%s: ' "$2"
# Disable terminal printing while the user inputs their
# password. POSIX 'read' has no '-s' flag which would
# effectively do the same thing.
stty -echo
read -r "$1"
stty echo
printf '\n'
}
glob() { glob() {
# This is a simple wrapper around a case statement to allow # This is a simple wrapper around a case statement to allow
# for simple string comparisons against globs. # for simple string comparisons against globs.