pash-posix: Add comments and simplify yn()
This commit is contained in:
parent
9d9cbf3622
commit
54b99259b7
25
pash-posix
25
pash-posix
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user