spm

Personal fork of spm (simple password manager)
git clone git@getsh.org:spm.git
Log | Files | Refs | README | LICENSE

commit 9c319f1edb2916f725c9c394e38f665ff3aeccd8
parent 5f384cde7d0968fee58e1ed23febcd86b6dc4dc9
Author: Klemens Nanni <kl3@posteo.org>
Date:   Fri,  3 Jun 2016 01:59:37 +0200

Allow patterns in 'del', add helper function

Signed-off-by: Klemens Nanni <kl3@posteo.org>

Diffstat:
MREADME.pod | 4++--
Mspm.sh | 32+++++++++++++++++---------------
2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/README.pod b/README.pod @@ -19,9 +19,9 @@ I<add>, I<del> or I<show> command respectively followed by a name. spm will then prompt for a password or confirmation before it modifies or shows the corresponding entry. -When using the I<show> command, globbing is allowed to avoid typing +Globbing is allowed for both I<del> and I<show> commands to avoid typing potentially long entry paths. In case multiple entries match, spm exits -without showing any password but a warning instead. +without removing or showing any password but printing a warning instead. spm simply stores everything in a directory structure where passwords correspond to individually PGP encrypted files, optionally residing diff --git a/spm.sh b/spm.sh @@ -21,6 +21,7 @@ umask 077 GPG_OPTS='--quiet --yes --batch' STORE_DIR="${PASSWORD_STORE_DIR:-${HOME}/.spm}" +ENTRY= ## Helper @@ -29,6 +30,18 @@ die() { exit 1 } +_find() { + [ -z "${1}" ] && die 'Name must not be empty.' + + ENTRY=$(find "${STORE_DIR}" \( -type f -o -type l \) \ + -iwholename "*${1}*".gpg) + + [ -z "${ENTRY}" ] && ENTRY= && die 'No such entry.' + + [ "$(printf '%s' "${ENTRY}" | wc -l)" -gt 0 ] \ + && ENTRY= && die 'Too ambigious keyword.' +} + gpg() { if [ -z "${PASSWORD_STORE_KEY}" ]; then gpg2 ${GPG_OPTS} --default-recipient-self "${@}" @@ -76,24 +89,13 @@ list() { } del() { - [ -z "${1}" ] && die 'Name must not be empty.' - [ -w "${STORE_DIR}"/"${1}".gpg ] || die 'No such entry.' - - rm -i "${STORE_DIR}"/"${1}".gpg + _find "${1}" + rm -i "${ENTRY}" } show() { - [ -z "${1}" ] && die 'Name must not be empty.' - - entry=$(find "${STORE_DIR}" \( -type f -o -type l \) \ - -iwholename "*${1}*".gpg) - - [ -z "${entry}" ] && die 'No such entry.' - - [ "$(printf '%s' "${entry}" | wc -l)" -gt 0 ] \ - && die 'Too ambigious keyword.' - - gpg --decrypt "${entry}" + _find "${1}" + gpg --decrypt "${ENTRY}" } ## Parse input