diff --git a/README.md b/README.md index ee1ba8a..7470a78 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a script heavily inspired by [rofi-pass](https://github.com/carnager/rofi-pass), but with FZF instead of Rofi. There's still a lot to do and this is just the first version. As it is now, it is only compatible with [Sway](https://github.com/swaywm/sway) (see TODO section) ### TODO -- Figure out a way to keep ydotool running after the popup terminal closes. Right now we can only support Sway because swaymsg is used to move the terminal out of the way +- Figure out a way to keep ydotool / xdotool running after the popup terminal closes. Right now we can only support Sway because swaymsg is used to move the terminal out of the way - Add detection for different fields, and show them only if they are there. Right now every field is hardcoded - Add copy to clipboard option - Make the most used pass entries show up first (don't know if it can be done with fzf) diff --git a/fzf-pass b/fzf-pass index 6973f82..325a553 100755 --- a/fzf-pass +++ b/fzf-pass @@ -1,44 +1,58 @@ #!/usr/bin/env bash -cd $HOME/.password-store -PASSFILE=$(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g' | sed 's/^..//' | fzf) +TO_WINDOW="$1" +PASS_WINDOW="$(xdotool getactivewindow)" + +set -euo pipefail +IFS=$'\n\t' + +cd "$HOME/.password-store" || exit 1 +PASSFILE="$(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g' | sed 's/^..//' | fzf)" if [ -z "$PASSFILE" ]; then exit 0 fi -PASSDATA="$(pass $PASSFILE)" -USRNAME="$(echo "$PASSDATA" | egrep -i "username:|user:" | head -1 | cut -d' ' -f2-)" -PASS="$(echo "$PASSDATA" | head -n 1)" -URL="$(echo $PASSDATA | grep url: | cut -d' ' -f2-)" - -RESP=$(cat < /dev/null; then + MENU+=("OTP") +fi +if echo "$PASSDATA" | grep -i '^username: ' > /dev/null; then + MENU+=("USERNAME") + MENU="$(echo $MENU | grep -v '^username: ')" +fi +MENU+=("PASSWORD") + +RESP=$(printf "%s\n" "${MENU[@]}" | fzf --tac) + +if [ "$RESP" = "DISPLAY" ]; then + echo "$PASSDATA" + sleep 30 + exit 0 +fi + +O="$(echo "$PASSDATA" | head -n 1)" +if [ "$RESP" != "PASSWORD" ]; then + O="$(echo "$PASSDATA" | awk -F ':' -v VAR="$RESP" '$1==VAR { Z=substr($0, length($1) + 2); gsub(/^[ \t]+|[ \t]+$/, "", Z); print Z }')" +fi +if [ "$RESP" == "OTP" ]; then + O="$(pass otp "$PASSFILE")" +fi +if [ "$RESP" == "USERNAME" ]; then + O="$(pass show "$PASSFILE" | grep -i '^username: ' | sed 's/^[^:]\+\: *//')" +fi + +if [ -z "$TO_WINDOW" ]; then + echo $O + exit +fi + +# xdotool windowminimize "$PASS_WINDOW" +xdotool windowactivate "$TO_WINDOW" +sleep 0.5 +xdotool type "$O" +echo Done | aosd_cat -p 4 -n "Anonymous Pro 99" -R lime +sleep 15 diff --git a/fzf-pass-window-control b/fzf-pass-window-control new file mode 100755 index 0000000..624ef04 --- /dev/null +++ b/fzf-pass-window-control @@ -0,0 +1,4 @@ +#!/bin/bash + +W="$(xdotool getactivewindow)" +x-terminal-emulator -e bash -c "$(dirname "$0")/fzf-pass $W"