pash-posix: Add comments and simplify yn()

This commit is contained in:
Dylan Araps 2019-11-25 21:47:17 +00:00
parent 9d9cbf3622
commit 54b99259b7
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 19 additions and 6 deletions

View File

@ -6,9 +6,7 @@ pw_add() {
pass_name=$1
set -- -c
yn "Generate a password?"
if glob "$REPLY" '[yY]'; then
if yn "Generate a password?"; then
pass=$("$gpg" --gen-random --armor "${PASH_LENGTH:-50}" |\
cut -c -"${PASH_LENGTH:-50}")
@ -30,9 +28,7 @@ pw_add() {
}
pw_del() {
yn "Delete pass file '$1'?"
glob "$REPLY" '[yY]' && {
yn "Delete pass file '$1'?" && {
rm -f "$1.gpg"
rmdir -p "${1%/*}" 2>/dev/null
}
@ -64,10 +60,27 @@ pw_list() {
yn() {
printf '%s [y/n]: ' "$1"
# Enable raw input to allow for a single
# byte to be read from stdin without needing
# to wait for the user to press Return.
stty -icanon
# Read a single byte from stdin using 'dd'.
# POSIX 'read' has no support for single or
# 'N' character based input from the user.
REPLY=$(dd ibs=1 count=1 2>/dev/null)
# Disable raw input, leaving the terminal
# how we *should* have found it.
stty icanon
printf '\n'
# Handle the answer here directly enabling
# this function's return status to be used
# in place of repeating this code throughout.
glob "$REPLY" '[yY]' || return 1 && return 0
}
die() {