passp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. #
  3. # password-store wrapper to disable clipboard managers
  4. # Copyright (C) 2020 Distopico <distopico@riseup.net>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Description:
  20. # --------------
  21. # Simple wrapper of password-store aka 'pass'
  22. # that prevent save copy history in some clipboard managers.
  23. #
  24. # supported:
  25. # - clipmenu
  26. # - greenclip
  27. #
  28. # Requirements:
  29. # --------------
  30. # - pass
  31. #
  32. # Usage:
  33. # ---------------
  34. # Just add an alias e.g:
  35. #
  36. # alias pass="/path/to/script/passp"
  37. #
  38. PASS_CMD="/usr/bin/pass"
  39. CLIPMENU_CTL_CMD='clipctl'
  40. CLIPMENU_DAEMON_CMD='clipmenud'
  41. GREENCLIP_DAEMON_CMD='greenclip daemon'
  42. function _pgrep() {
  43. if ! [[ -x "$(command -v pgrep)" ]]; then
  44. # Set pgrep fallback
  45. ps axf | grep "$1" | grep -v grep | awk '{print $1}'
  46. else
  47. pgrep -f "$1"
  48. fi
  49. }
  50. # If has greenclip process active
  51. processId="$(_pgrep "$GREENCLIP_DAEMON_CMD")"
  52. if ! [[ -z $processId ]]; then
  53. kill -20 $processId
  54. $PASS_CMD "$@"
  55. exit_code=$?
  56. greenclip print ' '
  57. kill -18 $processId
  58. exit $exit_code
  59. fi
  60. # if has clipmenud process active
  61. processId="$(_pgrep "$CLIPMENU_DAEMON_CMD")"
  62. if ! [[ -z $processId ]]; then
  63. $CLIPMENU_CTL_CMD disable
  64. $PASS_CMD "$@"
  65. exit_code=$?
  66. $CLIPMENU_CTL_CMD enable
  67. exit $exit_code
  68. fi
  69. # Default pass if not clipboard is ruining
  70. $PASS_CMD "$@"