diff --git a/simpleDots/bin/fzpass b/simpleDots/bin/fzpass new file mode 100755 index 0000000..cba911e --- /dev/null +++ b/simpleDots/bin/fzpass @@ -0,0 +1,28 @@ +#!/bin/bash + +## A wrapper for pass to use fzf to find passwords. + +prefix=${PASSWORD_STORE_DIR:=~/.password-store} +prefixlength=${#prefix} + +## Get all the gpg files in all directories and subdirs... +## remove the prefix, some 3 extra chars and the .gpg ending +password_files=$( find $prefix -name '*.gpg' \ + | cut --characters ${#prefix}- \ + | cut --characters 3- \ + | rev | cut --characters 5- | rev + ) + +## Send the filelist to fzf, use # for a preview and +## disable the fzf mous to use the primary selection +password=$( printf '%s\n' "${password_files[@]}" \ + | fzf --bind='#:toggle-preview' \ + --preview='pass show {}' \ + --preview-window="hidden" \ + --no-mouse \ + $@ \ + ) +## Exit if nothing was selected +test "_$password" = "_" && exit + +pass show -c "$password" 2>/dev/null diff --git a/simpleDots/bin/p b/simpleDots/bin/p deleted file mode 100755 index 79764a4..0000000 --- a/simpleDots/bin/p +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -## A wrapper for pass to use fzf to find passwords. - -prefix=${PASSWORD_STORE_DIR-~/.password-store} -password_files=( "$prefix"/**/*.gpg ) -password_files=( "${password_files[@]#"$prefix"/}" ) -password_files=( "${password_files[@]%.gpg}" ) - -password=$(printf '%s\n' "${password_files[@]}" | fzf "$@") - -[[ -n $password ]] || exit - -pass show -c "$password" 2>/dev/null