xclip -loops for pass
Dominique Martinet
asmadeus at codewreck.org
Thu Jun 5 21:36:32 UTC 2025
martin f. krafft wrote on Wed, Apr 23, 2025 at 07:21:54PM +0200:
> And this made me realise: `pass` uses `xclip` internally, right? Why the 45
> second wait and overwrite? `xclip -loops 1` makes the password available
> once exactly, and after a paste, the clipboard is empty.
That's a great idea, I've been using a local extension to copy arbitrary
lines to clipboard (e.g. with '<password>\nid: <id>' I'd be able to get
the id on clipboard), but getting both in a single command is even
better -- I've updated it for that so now I can request `id ''` and get
both one after another.
I'm not publishing this anywhere because lazy but feel free to use that
code, pass is easily extensible so it's probably better as an extension
than part of the core.
(it's hardcoded wl-copy, the --sensitive flag is not part of any release
yet and it is probably required if you have clipboard managers so YMMV)
Cheers,
--
Dominique Martinet | Asmadeus
-------------- next part --------------
#!/bin/bash
# License: WTFPL
### Allow copying arbitrary line to clipboard
### install
# - copy to ${PASSWORD_STORE_DIR:-~/.password-store}/.extensions/cl.bash
# - enable (in bashrc or equivalent):
# export PASSWORD_STORE_ENABLE_EXTENSIONS=true
# - optionally bash completion:
# export PASSWORD_STORE_EXTENSION_COMMANDS+=(cl)
# __password_store_extension_complete_cl() { [[ $COMP_CWORD = 2 ]] && _pass_complete_entries; }
###
clip_once() {
echo "Copying $2 to clipboard. Will clear after one paste"
echo -n "$1" | wl-copy --sensitive --paste-once --foreground
}
cmd_cl_copy() {
local pass=$1
shift
local full found
if [ "$#" = 0 ]; then
set -- ''
fi
full=$(cmd_show "$pass") || exit
for line; do
if [ -n "$line" ]; then
found=$(printf "%s\n" "$full" | sed -n -e 's/ #.*//' -e "s/^${line}[:=]\s*//p")
else
found=$(printf "%s\n" "$full" | head -n 1)
fi
if [ -z "$found" ]; then
printf "%s\n" "$line not found in pass:"
printf "%s\n" "$full" | sed -e 's/^/ /'
exit 1
fi
clip_once "$found" "'$pass $line'"
done
}
cmd_cl_help() {
cat <<-EOF
Usage: $PROGRAM cl pass-entry [key]
Copy keyed line(s) to clipboard. If no key same as 'pass show -c'
EOF
exit
}
case "$1" in
--help|-help|-h) cmd_cl_help;;
esac
cmd_cl_copy "$@"
More information about the Password-Store
mailing list