get-op-login 682 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. function log {
  3. if [ -t 1 ]; then
  4. echo "$@" >&2
  5. fi
  6. }
  7. function prompt_password {
  8. if command -v kdialog >/dev/null; then
  9. kdialog --password Password
  10. else
  11. zenity --password --timeout=60
  12. fi
  13. }
  14. function get_from_keepassxc {
  15. keepassxc-cli show -q "$KEEPASS_FILE" "$1" -a "$2" <<< "$3"
  16. }
  17. function get_credentials {
  18. local opPassword
  19. local password
  20. if ! password=$(prompt_password 2> /dev/null); then
  21. log "Failed to get password"
  22. return 1
  23. fi
  24. if ! opPassword=$(get_from_keepassxc "$KEEPASS_OP_ENTRY" Password "$password"); then
  25. log "Failed to open vault"
  26. exit 1
  27. fi
  28. op signin -f <<<"$opPassword"
  29. }
  30. get_credentials