From 4893f6b8a1b2ef7ceab726cbe16e4b76e7d1c826 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 24 Feb 2019 23:04:28 +0200 Subject: [PATCH] inital --- pash | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/pash b/pash index b713e9f..120da08 100755 --- a/pash +++ b/pash @@ -3,10 +3,18 @@ # pash - simple password manager. pw_add() { - [[ $OSTYPE == linux* ]] && - check_entropy + yn "Generate a password?" - generate_password + case $REPLY in + [yY]) + [[ $OSTYPE == linux* ]] && + check_entropy + + generate_password + ;; + + *) read -rsp "Enter password: " password ;; + esac [[ $password ]] || die "Failed to generate a password." @@ -15,7 +23,7 @@ pw_add() { } pw_del() { - read -rn 1 -p "Delete pass file '$1'? [y/n]: "; printf '\n' + yn "Delete pass file '$1'?" [[ $REPLY == [yY] ]] && rm "$1.gpg" @@ -65,15 +73,20 @@ check_entropy() { entropy=$(<"${k_path}/entropy_avail") needed=$(<"${k_path}/read_wakeup_threshold") - ((${entropy:=0} < ${needed:=1})) && { + [[ ${entropy:=0} -lt ${needed:=1} ]] && { printf '%s\n' "warn: Not enough entropy to generate a secure password." - read -rn 1 -p "warn: Continue anyway? [y/n]: "; printf '\n' + yn "warn: Continue anyway?" [[ $REPLY != [yY] ]] && exit 1 } } +yn() { + read -rn 1 -p "$1 [y/n]: " + printf '\n' +} + die() { printf 'error: %s\n' "$1" >&2 exit 1 @@ -139,11 +152,11 @@ main() { *) usage ;; esac - [[ -z $quiet && $password ]] && - printf '%s\n' "$password" - [[ $clipboard && $password ]] && hash xclip 2>/dev/null && xclip -selection clipboard &>/dev/null <<< "$password" + + [[ -z $quiet && $password ]] && + printf '%s\n' "$password" } main "$@"