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
|
pass_name=$1
|
||||||
set -- -c
|
set -- -c
|
||||||
|
|
||||||
yn "Generate a password?"
|
if yn "Generate a password?"; then
|
||||||
|
|
||||||
if glob "$REPLY" '[yY]'; then
|
|
||||||
pass=$("$gpg" --gen-random --armor "${PASH_LENGTH:-50}" |\
|
pass=$("$gpg" --gen-random --armor "${PASH_LENGTH:-50}" |\
|
||||||
cut -c -"${PASH_LENGTH:-50}")
|
cut -c -"${PASH_LENGTH:-50}")
|
||||||
|
|
||||||
|
@ -30,9 +28,7 @@ pw_add() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_del() {
|
pw_del() {
|
||||||
yn "Delete pass file '$1'?"
|
yn "Delete pass file '$1'?" && {
|
||||||
|
|
||||||
glob "$REPLY" '[yY]' && {
|
|
||||||
rm -f "$1.gpg"
|
rm -f "$1.gpg"
|
||||||
rmdir -p "${1%/*}" 2>/dev/null
|
rmdir -p "${1%/*}" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
@ -64,10 +60,27 @@ pw_list() {
|
||||||
|
|
||||||
yn() {
|
yn() {
|
||||||
printf '%s [y/n]: ' "$1"
|
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
|
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)
|
REPLY=$(dd ibs=1 count=1 2>/dev/null)
|
||||||
|
|
||||||
|
# Disable raw input, leaving the terminal
|
||||||
|
# how we *should* have found it.
|
||||||
stty icanon
|
stty icanon
|
||||||
|
|
||||||
printf '\n'
|
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() {
|
die() {
|
||||||
|
|
Loading…
Reference in New Issue