Skip to content

Instantly share code, notes, and snippets.

@benjmin-r
Created April 28, 2014 12:34
Show Gist options
  • Save benjmin-r/11370468 to your computer and use it in GitHub Desktop.
Save benjmin-r/11370468 to your computer and use it in GitHub Desktop.
##
## Simple password management in ksh-compatible shell
## You'll need a unix-like system and a working GPG configuration
export GPG_KEY=""
function pwgrep() {
gpg --batch -q -d -r $GPG_KEY $HOME/.auth/pwdb.asc | grep $*
}
function pwcat() {
gpg --batch -q -d -r $GPG_KEY $HOME/.auth/pwdb.asc
}
function pwinit() {
mkdir -p $HOME/.auth
if [ ! -f $HOME/.auth/pwdb.asc ] ; then
echo -n | gpg -q --batch -a -e -r $GPG_KEY > $HOME/.auth/pwdb.asc
fi
}
function pwedit() {
[ -z $EDITOR ] && EDITOR=vi
file=`mktemp /tmp/pwedit.XXXXXX`
gpg -q -d --batch -r $GPG_KEY $HOME/.auth/pwdb.asc > $file && \
$EDITOR $file && \
gpg -q --batch -a -e -r $GPG_KEY $file && \
mv ${file}.asc $HOME/.auth/pwdb.asc
rm -f $file ${file}.asc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment