rbw.plugin.zsh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. if (( ! $+commands[rbw] )); then
  2. return
  3. fi
  4. # If the completion file doesn't exist yet, we need to autoload it and
  5. # bind it to `rbw`. Otherwise, compinit will have already done that.
  6. if [[ ! -f "$ZSH_CACHE_DIR/completions/_rbw" ]]; then
  7. typeset -g -A _comps
  8. autoload -Uz _rbw
  9. _comps[rbw]=_rbw
  10. fi
  11. rbw gen-completions zsh >| "$ZSH_CACHE_DIR/completions/_rbw" &|
  12. # rbwpw function copies the password of a service to the clipboard
  13. # and clears it after 20 seconds
  14. function rbwpw {
  15. if [[ $# -ne 1 ]]; then
  16. echo "usage: rbwpw <service>"
  17. return 1
  18. fi
  19. local service=$1
  20. if ! rbw unlock; then
  21. echo "rbw is locked"
  22. return 1
  23. fi
  24. local pw=$(rbw get $service 2>/dev/null)
  25. if [[ -z $pw ]]; then
  26. echo "$service not found"
  27. return 1
  28. fi
  29. echo -n $pw | clipcopy
  30. echo "password for $service copied!"
  31. {sleep 20 && clipcopy </dev/null 2>/dev/null} &|
  32. }
  33. function _rbwpw {
  34. local -a services
  35. services=("${(@f)$(rbw ls 2>/dev/null)}")
  36. [[ -n "$services" ]] && compadd -a -- services
  37. }
  38. compdef _rbwpw rbwpw