Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
88 changes: 51 additions & 37 deletions fzf-pass
Original file line number Diff line number Diff line change
@@ -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 <<EOF | fzf
Autotype
Username
Password
OTP
URL
EOF
);

swaymsg move container to workspace 9

case "$RESP" in
Autotype)
ydotool type "$USRNAME" && ydotool key Tab && ydotool type "$PASS" && ydotool key Enter
;;
Username)
ydotool type "$USRNAME"
;;
Password)
ydotool type "$PASS"
;;
OTP)
ydotool type "$(pass otp $PASSFILE)"
;;
URL)
ydotool type "$URL"
;;
*)
exit 1
esac
PASSDATA=$(pass "$PASSFILE")

MENU=($(echo "$PASSDATA" | tail -n +2 | sed 's/\:.*//' ))
MENU+=("DISPLAY")
if echo "$PASSDATA" | grep '^otpauth' > /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
4 changes: 4 additions & 0 deletions fzf-pass-window-control
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

W="$(xdotool getactivewindow)"
x-terminal-emulator -e bash -c "$(dirname "$0")/fzf-pass $W"