From ef2c24e7428503127a419c9219d8b8fb3ff6b440 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 25 Nov 2019 22:38:26 +0000 Subject: [PATCH] pash-posix: longer length for comments. --- pash-posix | 72 +++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/pash-posix b/pash-posix index 4ab44b7..9b29474 100755 --- a/pash-posix +++ b/pash-posix @@ -6,33 +6,26 @@ pw_add() { pass_name=$1 if yn "Generate a password?"; then - # Use 'gpg' to generate the password. This - # could have been 'openssl', '/dev/[u]random' - # or another utility, however sticking to 'gpg' - # removes the need for another dependency. + # Use 'gpg' to generate the password. This could have + # been 'openssl', '/dev/[u]random' or another utility, + # however sticking to 'gpg' removes the need for another + # dependency. # - # The '-a' flag outputs the random bytes as - # a 'base64' encoded string to allow for the - # password to be used as well, a password. + # The '-a' flag outputs the random bytes as a 'base64' + # encoded string to allow for the password to be used as + # well, a password. # - # The 'cut' is required to actually truncate - # the password to the set length as the 'base64' - # encoding makes the resulting string longer - # than the given length. + # The 'cut' is required to actually truncate the password + # to the set length as the 'base64' encoding makes the + # resulting string longer than the given length. pass=$("$gpg" --gen-random -a "${PASH_LENGTH:-50}" |\ cut -c -"${PASH_LENGTH:-50}") else printf 'Enter password: ' - # Disable echoing of output to the - # terminal while reading user input. stty -echo - read -r pass - - # Enable echoing and leave the terminal - # how we *should* have found it. stty echo printf '\n' @@ -41,18 +34,17 @@ pw_add() { [ "$pass" ] || die "Failed to generate a password." - # Mimic the use of an array for storing - # arguments by... using the function's - # argument list. This is very apt... isn't it? + # Mimic the use of an array for storing arguments by... using + # the function's argument list. This is very apt isn't it? if [ "$PASH_KEYID" ]; then set -- --trust-model always -aer "$PASH_KEYID" else set -- -c fi - # Use 'gpg' to store the password in an encrypted file. - # The 'GPG_TTY' environment variable is set to workaround - # cases where 'gpg' cannot find an attached terminal. + # Use 'gpg' to store the password in an encrypted file. The + # 'GPG_TTY' environment variable is set to workaround cases + # where 'gpg' cannot find an attached terminal. echo "$pass" | GPG_TTY=$(tty) "$gpg" "$@" -o "$pass_name.gpg" } @@ -66,10 +58,9 @@ pw_del() { pw_show() { pass=$("$gpg" -dq "$1.gpg") - # If '$2' is defined, don't print the password - # to the terminal. This is useful when the user - # would just like the password copied to the - # clipboard. + # If '$2' is defined, don't print the password to the + # terminal. For example, this is used when the password is + # copied to the clipboard. [ "$2" ] || printf '%s\n' "$pass" } @@ -94,32 +85,29 @@ 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. + # 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. + # Read a single byte from stdin using 'dd'. POSIX 'read' has + # no support for single/'N' byte 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. + # 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. + # Handle the answer here directly, enabling this function's + # return status to be used in place of checking for '[yY]' + # throughout this program. glob "$REPLY" '[yY]' || return 1 && return 0 } glob() { - # This is a simple wrapper around a case - # statement to allow for simple string - # comparisons against globs. + # This is a simple wrapper around a case statement to allow + # for simple string comparisons against globs. # # Example: if glob "Hello World" '* World'; then case $1 in $2) return 0; esac; return 1 @@ -184,7 +172,7 @@ main() { umask 077 case $1 in - a*) pw_add "$2" && printf '%s\n' "Saved '$2' to store." ;; + a*) pw_add "$2" && printf '%s\n' "Saved '$2' to the store." ;; c*) pw_copy "$2" ;; d*) pw_del "$2" ;; s*) pw_show "$2" ;;