From 866bbff0eb207e2a7a393af302abafe9386d75c4 Mon Sep 17 00:00:00 2001 From: drduh Date: Fri, 31 Jul 2015 00:53:28 -0400 Subject: [PATCH] Indent by 2 spaces throughout. Add example for copying password to clipboard on OS X. --- README.md | 4 ++++ pwd.sh | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a769397..9ca93e2 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ Options can also be passed on the command line, e.g., `./pwd.sh d dropbox` to delete the password called 'dropbox'. +Combine with other programs by piping output, e.g., + +`./pwd.sh r github | grep github | cut -f1 -d ' ' | pbcopy` to copy a password to clipboard on OS X. + The script and `pwd.sh.safe` encrypted file can be safely shared between machines over public channels (Google Drive, Dropbox, etc). A sample `gpg.conf` configuration file is provided for your consideration. diff --git a/pwd.sh b/pwd.sh index 06a7302..3086194 100755 --- a/pwd.sh +++ b/pwd.sh @@ -23,6 +23,7 @@ get_pass () { password='' prompt="${1}" + while IFS= read -p "${prompt}" -r -s -n 1 char ; do if [[ ${char} == $'\0' ]] ; then break @@ -57,7 +58,6 @@ decrypt () { encrypt () { # Encrypt with a password. - ${gpg} \ --symmetric --armor --batch --yes \ --passphrase-fd 3 \ @@ -145,17 +145,17 @@ create_username () { # Create a new username and password. if [[ -z "${2+x}" ]] ; then - read -p " + read -p " Username: " username else - username="${2}" + username="${2}" fi if [[ -z "${3+x}" ]] ; then - read -p " + read -p " Generate password? (y/n, default: y) " rand_pass else - rand_pass="" + rand_pass="" fi if [[ "${rand_pass}" =~ ^([nN][oO]|[nN])$ ]]; then @@ -182,11 +182,11 @@ sanity_check () { sanity_check if [[ -z "${1+x}" ]] ; then - read -n 1 -p " + read -n 1 -p " Read, write, or delete password? (r/w/d, default: r) " action - printf "\n" + printf "\n" else - action="${1}" + action="${1}" fi if [[ "${action}" =~ ^([wW])$ ]] ; then @@ -198,7 +198,7 @@ elif [[ "${action}" =~ ^([dD])$ ]] ; then read -p " Username to delete? " username else - username="${2}" + username="${2}" fi write_pass