This commit is contained in:
Dylan Araps 2019-02-24 23:04:28 +02:00
parent 9ccc601033
commit 4893f6b8a1
1 changed files with 22 additions and 9 deletions

31
pash
View File

@ -3,10 +3,18 @@
# pash - simple password manager. # pash - simple password manager.
pw_add() { pw_add() {
[[ $OSTYPE == linux* ]] && yn "Generate a password?"
check_entropy
generate_password case $REPLY in
[yY])
[[ $OSTYPE == linux* ]] &&
check_entropy
generate_password
;;
*) read -rsp "Enter password: " password ;;
esac
[[ $password ]] || [[ $password ]] ||
die "Failed to generate a password." die "Failed to generate a password."
@ -15,7 +23,7 @@ pw_add() {
} }
pw_del() { pw_del() {
read -rn 1 -p "Delete pass file '$1'? [y/n]: "; printf '\n' yn "Delete pass file '$1'?"
[[ $REPLY == [yY] ]] && [[ $REPLY == [yY] ]] &&
rm "$1.gpg" rm "$1.gpg"
@ -65,15 +73,20 @@ check_entropy() {
entropy=$(<"${k_path}/entropy_avail") entropy=$(<"${k_path}/entropy_avail")
needed=$(<"${k_path}/read_wakeup_threshold") 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." 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] ]] && [[ $REPLY != [yY] ]] &&
exit 1 exit 1
} }
} }
yn() {
read -rn 1 -p "$1 [y/n]: "
printf '\n'
}
die() { die() {
printf 'error: %s\n' "$1" >&2 printf 'error: %s\n' "$1" >&2
exit 1 exit 1
@ -139,11 +152,11 @@ main() {
*) usage ;; *) usage ;;
esac esac
[[ -z $quiet && $password ]] &&
printf '%s\n' "$password"
[[ $clipboard && $password ]] && hash xclip 2>/dev/null && [[ $clipboard && $password ]] && hash xclip 2>/dev/null &&
xclip -selection clipboard &>/dev/null <<< "$password" xclip -selection clipboard &>/dev/null <<< "$password"
[[ -z $quiet && $password ]] &&
printf '%s\n' "$password"
} }
main "$@" main "$@"