[pass] Feature request – combined insert/generate/edit for new entries

Jonas Kalderstam jonas at cowboyprogrammer.org
Sat Jul 16 09:23:47 CEST 2016

Here's a script I use all the time.

It generates a
password, and opens an editor for you. The password will be in the
clipboard (middle-mouse button for me) so you can paste into the site
and actually register successfully before saving and committing.

Call it with:

password_edit.sh <filename>

Script follows:
#!/usr/bin/env bash

# A simple wrapper for pass edit. Takes one argument, and that is the
# password file to open (which can be new). As a convenience, a new
# password is generated and placed in the clipboard so you can paste
# it with Mouse3.

if [ $# -eq 0 ]; then
echo "No arguments provided"
exit 1


# Borrowing from pass
clip() {
# This base64 business is because bash cannot store binary data in a
# shell variable. Specifically, it cannot store nulls nor
# (non-trivally) store trailing new lines.
local sleep_argv0="password store sleep on display $DISPLAY"
local before
local now
pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
before="$(xclip -o -selection "$X_SELECTION" 2>/dev/null | base64)"
echo -n "$1" | xclip -selection "$X_SELECTION" || \
die "Error: Could not copy data to the clipboard"
( exec -a "$sleep_argv0" sleep "$CLIP_TIME" )
now="$(xclip -o -selection "$X_SELECTION" | base64)"
[[ $now != $(echo -n "$1" | base64) ]] && before="$now"

# It might be nice to programmatically check to see if klipper
# exists, as well as checking for other common clipboard
# managers. But for now, this works fine -- if qdbus isn't there
# or if klipper isn't running, this essentially becomes a no-op.
# Clipboard managers frequently write their history out in
# plaintext, so we axe it here:
qdbus org.kde.klipper \
/klipper org.kde.klipper.klipper.clearClipboardHistory \

echo "$before" | base64 -d | xclip -selection "$X_SELECTION"
) 2>/dev/null & disown
#echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."

# -B - don't use ambiguious characters
# -s - added randomness
# 20 chars long
# 1 output only
pw=$(pwgen -B -s 20 1)

# Copy password to clipboard
clip "$pw"

# Open editor, paste password with Mouse3
pass edit "$1"

Kenny Evitt <kenny.evitt at gmail.com> skrev: (15 juli 2016 21:49:26 CEST)
>I often want to add an entry but also generate a new random password
>add additional info ('edit') and, given that I'm tracking the history
>of my
>entries with Git, it'd be nice (or nicest) to do all of that as a
>commit. Besides the Git history, it'd also be nice to do all of that as
>single `pass ...` command too.
>The closest I can come to this is to run `pass edit ...`. In my editor
>(Vim) I can insert the output of running `pwgen` easily enough (by
>the Vim command `:r !pwgen -s -y 32` or similar), but it'd be nice for
>`pass edit ...` to insert a password for me (if no existing entry
>the path I provide) or for another command to do so instead of `edit`.
>Password-Store mailing list
>Password-Store at lists.zx2c4.com

Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20160716/5530a7ef/attachment.html>

More information about the Password-Store mailing list