Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active January 28, 2021 04:05
Show Gist options
  • Save Konfekt/dc03f194df97b8c6a64d0b435e892402 to your computer and use it in GitHub Desktop.
Save Konfekt/dc03f194df97b8c6a64d0b435e892402 to your computer and use it in GitHub Desktop.
passy: pastes anywhere passwords managed by password-store selected from a fuzzy finder menu

Bind this shell script to a hotkey. On hitting the hotkey, you can fuzzy search a password among those managed by the command-line tool https://www.passwordstore.org/. On selecting one of them, it is pasted at the current cursor position.

This script depends on "rofi", "dmenu", "zenity", "xsel" and "xdotool" which most linux distros offer as install packages.

To bind this shell script to a hotkey, say Meta+P:

  1. Paste the below shell-script code into a file, say ~/bin/passy, make it executable.
  2. Install xbindkeys, make it autostart on logging into X, and add
"~/bin/passy"
  Mod4 + p

to ~/.xbindkeysrc.

The shell-script code:

#!/usr/bin/env bash

# Passy, fuzzy search and select and paste passwords managed by password-store. Based on:
# https://github.com/BarbUk/dotfiles/blob/master/bin/snippy
# https://github.com/peco/peco/wiki/Sample-Usage
# https://git.zx2c4.com/password-store/tree/contrib/dmenu/passmenu

DIR=${HOME}/.password-store
MENU_ENGINE="rofi"
DMENU_ARGS='-dmenu -i -sort -lines 25'
MENU_ARGS=${DMENU_ARGS}

cd "${DIR}" || exit
# Use the filenames in the password-store directory as menu entries.
# Get the menu selection from the user.
FILE=$(find . -type f -name "*.gpg" \
    | sed 's@\./\(.\+\?\)\.gpg@\1@' \
    | ${MENU_ENGINE} ${MENU_ARGS} -p '')
# just exit if nothing was selected
[[ -z "${FILE}" ]] && exit

pass show "$FILE" \
	| { IFS= read -r pass; printf %s "$pass"; } \
	| xdotool type --clearmodifiers --file -
@Konfekt
Copy link
Author

Konfekt commented May 30, 2020

See the snippy.sh repository for the counterpart for pasting user defined snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment