summaryrefslogtreecommitdiff
path: root/fedora/.local/bin/fzfpass
diff options
context:
space:
mode:
Diffstat (limited to 'fedora/.local/bin/fzfpass')
-rwxr-xr-xfedora/.local/bin/fzfpass88
1 files changed, 88 insertions, 0 deletions
diff --git a/fedora/.local/bin/fzfpass b/fedora/.local/bin/fzfpass
new file mode 100755
index 0000000..5190f8e
--- /dev/null
+++ b/fedora/.local/bin/fzfpass
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+set -e
+
+usage() {
+ echo "Find pass gpg files in Password-Store using fzf."
+ echo ""
+ echo "Usage: ${0##*/} [-h|--help]"
+ echo ""
+ echo "Options:"
+ echo " -h, --help : Show this message"
+ echo ""
+ echo "Shortcuts:"
+ echo " return - echo password and copy to clipboard (wayland only)"
+ echo " ctrl+a - new password (named as per the prompt)"
+ echo " ctrl+e - edit selected password"
+ echo " ctrl+g - regenerate selected password"
+ echo " ctrl+r - rename selected password"
+ echo " ctrl+x - delete selected password"
+ echo " tab - tab complete"
+ echo " esc/ctrl+c - exit"
+ exit 0
+}
+
+if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
+ usage
+fi
+
+passdir=${PASSWORD_STORE_DIR:-$HOME/.local/share/.password-store}
+cd "$passdir"
+
+# Unlock the password for this session
+pass show "$(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g' | sed 's/^..//' | head -n 1)" >/dev/null
+
+# Main fzf session
+passfile=$(
+ tree -Ffi | grep '.gpg' | sed 's/.gpg$//g' | sed 's/^..//' |
+ fzf-tmux \
+ --header="🔑 Password Manager" \
+ --reverse \
+ --no-mouse \
+ --preview="pass {}" \
+ --header="🔑 ^a: Generate | ^e: Edit | ^g: Generate (no symbol) | ^r: Rename | ^s: Generate (symbol) | ^x: Delete | tab: Replace" \
+ --bind="ctrl-a:execute(if [ -z {q} ]; then read -p \"Can't generate empty password. Press enter to continue...\"; else pass generate -n {q} < /dev/tty > /dev/tty 2>&1 && pass edit {q} < /dev/tty > /dev/tty 2>&1; fi)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \
+ --bind="ctrl-e:execute(pass edit {} < /dev/tty > /dev/tty 2>&1)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \
+ --bind="ctrl-r:execute(bash -c '
+echo -n \"Enter new name for {}: \" > /dev/tty;
+read new_name < /dev/tty;
+if [ -n \"\$new_name\" ]; then
+ pass mv {} \"\$new_name\" || echo \"Rename failed.\" > /dev/tty;
+else
+ echo \"No name entered. Rename aborted.\" > /dev/tty;
+fi' < /dev/tty > /dev/tty 2>&1)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \
+ --bind="ctrl-g:execute(if [ -z {} ]; then read -p \"Can't generate empty password. Press enter to continue...\"; else pass generate -in {} < /dev/tty > /dev/tty 2>&1 && pass edit {} < /dev/tty > /dev/tty 2>&1; fi)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \
+ --bind="ctrl-s:execute(if [ -z {} ]; then read -p \"Can't generate empty password. Press enter to continue...\"; else pass generate -i {} < /dev/tty > /dev/tty 2>&1 && pass edit {} < /dev/tty > /dev/tty 2>&1; fi)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \
+ --bind="ctrl-x:execute(pass rm {} < /dev/tty > /dev/tty 2>&1)+reload(tree -Ffi | grep '.gpg' | sed 's/.gpg$//g')" \
+ --bind="tab:replace-query"
+)
+
+show_passdata=false
+
+if [ "$1" = "-i" ]; then
+ show_passdata=true
+ shift
+fi
+
+if [ "$show_passdata" = true ]; then
+ passdata="$(pass "$passfile")"
+ echo "$passdata"
+else
+ password="$(pass show "$passfile" | head -n 1)"
+ echo "$password"
+
+ if [ -n "$password" ]; then
+ case "$(uname)" in
+ Darwin*)
+ printf "%s" "$password" | pbcopy # Use pbcopy on macOS
+ ;;
+ Linux*)
+ printf "%s" "$password" | xclip -selection clipboard # Use xclip on Linux
+ ;;
+ *)
+ echo "Unsupported operating system"
+ ;;
+ esac
+ sleep 0.1
+ fi
+fi