spm

simple password manager
git clone anongit@rnpnr.xyz:spm.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 2327a1236a66c4def7544f64ee7d751bb2042732
Parent: 9b0d87b94b5f2e00d410bbf5c126aa3ed6ebec06
Author: Klemens Nanni
Date:   Thu, 16 Jun 2016 00:37:00 +0200

Make code more modular, rename _find() to search()

Diffstat:
Mspm.sh | 29+++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/spm.sh b/spm.sh @@ -21,7 +21,6 @@ umask 077 GPG_OPTS='--quiet --yes --batch' STORE_DIR="${PASSWORD_STORE_DIR:-${HOME}/.spm}" -ENTRY= ## Helper @@ -30,15 +29,11 @@ die() { exit 1 } -_find() { - ENTRY=$(find "${STORE_DIR}" \( -type f -o -type l \) \ - -iwholename "*${1}*".gpg \ - | head -n2) +check() { + [ -z "${entry}" ] && die 'No such entry' - [ -z "${ENTRY}" ] && ENTRY= && die 'No such entry' - - [ "$(printf '%s' "${ENTRY}" | wc -l)" -gt 0 ] \ - && ENTRY= && die 'Too ambigious keyword' + [ "$(printf '%s' "${entry}" | wc -l)" -gt 0 ] \ + && die 'Too ambigious keyword' } gpg() { @@ -53,6 +48,11 @@ readpw() { [ -z "${2}" ] && die 'No password specified' } +search() { + find "${STORE_DIR}" \( -type f -o -type l \) \ + -iwholename "*${1}*".gpg +} + ## Commands add() { @@ -78,14 +78,15 @@ list() { } del() { - _find "${1}" - rm -i "${ENTRY}" - printf '\n' + entry=$(search "${1}" | head -n2) + check + rm -i "${entry}"; printf '\n' } show() { - _find "${1}" - gpg --decrypt "${ENTRY}" + entry=$(search "${1}" | head -n2) + check + gpg --decrypt "${entry}" } ## Parse input