Skip to content

Commit

Permalink
Add edit command to pass
Browse files Browse the repository at this point in the history
Uses $EDITOR to add or edit files
  • Loading branch information
rupa committed Sep 7, 2012
1 parent 602eadd commit e45252c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions man/pass.1
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ disable keyboard echo when the password is entered and confirm the password by a
for it twice. If \fI--multiline\fP or \fI-m\fP is specified, lines will be read until
EOF or Ctrl+D is reached. Otherwise, only a single line from standard in is read.
.TP
\fBedit\fP
Add or edit password with \fB$EDITOR\fP (default \fBvi\fP).
.TP
\fBgenerate\fP [ \fI--no-symbols\fP, \fI-n\fP ] [ \fI--clip\fP, \fI-c\fP ] \fIpass-name pass-length\fP
Generate a new password using
.BR pwgen (1)
Expand Down
27 changes: 26 additions & 1 deletion src/password-store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Usage:
$program insert [--no-echo,-n | --multiline,-m] pass-name
Insert new password. Optionally, the console can be enabled to not
echo the password back. Or, optionally, it may be multiline.
$program edit
Add or edit password with $EDITOR (default vi).
$program generate [--no-symbols,-n] [--clip,-c] pass-name pass-length
Generate a new password of pass-length with optionally no symbols.
Optionally put it on the clipboard and clear board after 45 seconds.
Expand All @@ -44,7 +46,7 @@ _EOF
}
isCommand() {
case "$1" in
init|ls|list|show|insert|generate|remove|rm|delete|push|pull|git|help) return 0 ;;
init|ls|list|show|insert|edit|generate|remove|rm|delete|push|pull|git|help) return 0 ;;
*) return 1 ;;
esac
}
Expand Down Expand Up @@ -186,6 +188,29 @@ case "$command" in
git commit -m "Added given password for $path to store."
fi
;;
edit)
[ "$1" ] || {
echo "need a password to edit"
exit
}
path="$1"
mkdir -p -v "$PREFIX/$(dirname "$path")"
passfile="$PREFIX/$path.gpg"
fl=$(mktemp)
if [ -f "$passfile" ];then
gpg --decrypt "$passfile" > "$fl"
log="Edited"
else
log="Added"
fi
"${EDITOR:-vi}" "$fl"
gpg -e -r "$ID" > "$passfile" <"$fl"
rm "$fl"
[ -d $GIT ] && {
git add "$passfile"
git commit -m "$log given password for $path to store."
}
;;
generate)
clip=0
symbols="-y"
Expand Down

0 comments on commit e45252c

Please sign in to comment.