passmenu 794 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env bash
  2. shopt -s nullglob globstar
  3. typeit=0
  4. if [[ $1 == "--type" ]]; then
  5. typeit=1
  6. shift
  7. fi
  8. if [[ -n $WAYLAND_DISPLAY ]]; then
  9. dmenu="fuzzel"
  10. xdotool="ydotool type --file -"
  11. elif [[ -n $DISPLAY ]]; then
  12. dmenu=dmenu
  13. xdotool="xdotool type --clearmodifiers --file -"
  14. else
  15. echo "Error: No Wayland or X11 display detected" >&2
  16. exit 1
  17. fi
  18. prefix=${PASSWORD_STORE_DIR-~/.password-store}
  19. password_files=( "$prefix"/**/*.gpg )
  20. password_files=( "${password_files[@]#"$prefix"/}" )
  21. password_files=( "${password_files[@]%.gpg}" )
  22. password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" "-d" "$@")
  23. [[ -n $password ]] || exit
  24. if [[ $typeit -eq 0 ]]; then
  25. pass show -c "$password" 2>/dev/null
  26. else
  27. pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool
  28. fi