Closed Konfekt closed 6 years ago
Well, here it is:
#!/usr/bin/env bash
DIR=${HOME}/.password-store
MENU_ENGINE="rofi"
DMENU_ARGS='-dmenu -i -sort -lines 25'
# if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v"
GUIPASTE="xdotool key ctrl+v"
CLIPASTE="xdotool key ctrl+shift+v"
MENU_ARGS=${DMENU_ARGS}
is_gui(){
name="$(xprop -id "$(xdotool getwindowfocus)" WM_CLASS | cut -d'"' -f2 | tr '[:upper:]' '[:lower:]')"
[[ "$name" =~ term|tilda ]] && return 1
return 0
}
run(){
cd "${DIR}" || exit
# Use the filenames in the snippy directory as menu entries.
# Get the menu selection from the user.
# shellcheck disable=SC2086
export PASSWORD_STORE_CLIP_TIME=1
export PASSWORD_STORE_X_SELECTION=clip-board
FILE=$(find . -type f -name "*.gpg" \
| sed 's@\./\(.\+\?\)\.gpg@\1@' \
| ${MENU_ENGINE} ${MENU_ARGS} -p '❯ ')
# just return if nothing was selected
[[ -z "${FILE}" ]] && return 1
current_clip=$(xsel -b)
pass --clip "$FILE"
# Paste into the current application.
if is_gui; then
${GUIPASTE}
else
${CLIPASTE}
fi
echo -ne "$current_clip" | xsel -b --input
echo "$current_clip" > /tmp/.snippy.tmp
}
run
Perhaps it serves you.
Ok, this has become a gist:
https://gist.github.com/Konfekt/dc03f194df97b8c6a64d0b435e892402
Well, the password-store script had already a better alternative that does without the clipboard. That made me rewrite snippy in the same way, see
https://gist.github.com/Konfekt/3c8704604e9dae5c07ef1c2fd8e2225b
The advantage is that it works everywhere, independent of the application being a GUI or not.
Just as a note, with
instead of
snippy could also serve for easily retrieving and pasting passwords kept by https://www.passwordstore.org/ (https://git.zx2c4.com/password-store/).