Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Multiline pass file support #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 46 additions & 8 deletions pash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

pw_add() {
name=$1
multiline=$2

# Take the flag out of the positional parameter array
for arg in "$@"
do
shift
[ "$arg" = true ] || [ "$arg" = false ] && continue
set -- "$@" "$arg"
done

if yn "Generate a password?"; then
# Generate a password by reading '/dev/urandom' with the
Expand Down Expand Up @@ -32,6 +41,18 @@ pw_add() {

[ "$pass" ] || die "Failed to generate a password"

if [ "$multiline" = true ]; then
line="dummy"
nl="
"
echo "Enter additional contents of $name and press enter on empty line when finished"
until [ "$line" = "" ]
do
read -r line
[ "$line" != "" ] && pass="${pass}${nl}${line}"
done
fi

# 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
Expand Down Expand Up @@ -86,7 +107,9 @@ pw_copy() {
$PASH_CLIP </dev/null
} &

pw_show "$1" | $PASH_CLIP
pass=$(pw_show "$1")
echo "${pass%%'
'*}" | $PASH_CLIP
}

pw_list() {
Expand Down Expand Up @@ -155,12 +178,12 @@ die() {
usage() { printf %s "\
pash 2.3.0 - simple password manager.

=> [a]dd [name] - Create a new password entry.
=> [c]opy [name] - Copy entry to the clipboard.
=> [d]el [name] - Delete a password entry.
=> [l]ist - List all entries.
=> [s]how [name] - Show password for an entry.
=> [t]ree - List all entries in a tree.
=> [a]dd -[-m]ultiline [name] - Create a new password entry.
=> [c]opy [name] - Copy entry to the clipboard.
=> [d]el [name] - Delete a password entry.
=> [l]ist - List all entries.
=> [s]how [name] - Show password for an entry.
=> [t]ree - List all entries in a tree.

Using a key pair: export PASH_KEYID=XXXXXXXX
Password length: export PASH_LENGTH=50
Expand All @@ -175,6 +198,21 @@ exit 0
main() {
: "${PASH_DIR:=${XDG_DATA_HOME:=$HOME/.local/share}/pash}"

multiline=false

# Take the flag out of the positional parameter array
for arg in "$@"
do
shift
case $arg in
*-m*)
multiline=true
continue
;;
esac
set -- "$@" "$arg"
done

# Look for both 'gpg' and 'gpg2',
# preferring 'gpg2' if it is available.
command -v gpg >/dev/null 2>&1 && gpg=gpg
Expand Down Expand Up @@ -220,7 +258,7 @@ main() {
trap 'stty echo icanon' INT EXIT

case $1 in
a*) pw_add "$2" ;;
a*) pw_add "$2" "$multiline" ;;
c*) pw_copy "$2" ;;
d*) pw_del "$2" ;;
s*) pw_show "$2" ;;
Expand Down