BarbUk / dotfiles

My dotfiles, used on archlinux, osx and debian
31 stars 3 forks source link

use snippy for password-store #1

Closed Konfekt closed 6 years ago

Konfekt commented 6 years ago

Just as a note, with

export PASSWORD_STORE_ENABLE_EXTENSIONS=true
FILE=$(find ~/.password-store -type f -name "*.gpg" \
           | sed 's@'"$HOME"'/\.password-store/\(.\+\?\)\.gpg@\1@' \
           | ${MENU_ENGINE} ${MENU_ARGS} -p')

instead of

FILE=$(find -L .  -type f | grep -v '^\.$' | sed 's!\.\/!!' | grep -vE '\.git/|\.gitconfig|\.gitkeep' | ${MENU_ENGINE} ${MENU_ARGS} -p '❯ ')

snippy could also serve for easily retrieving and pasting passwords kept by https://www.passwordstore.org/ (https://git.zx2c4.com/password-store/).

Konfekt commented 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.

Konfekt commented 6 years ago

Ok, this has become a gist:

https://gist.github.com/Konfekt/dc03f194df97b8c6a64d0b435e892402

Konfekt commented 6 years ago

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.