_pass 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #compdef pass
  2. #autoload
  3. # Copyright (C) 2012:
  4. # Johan Venant <jvenant@invicem.pro>
  5. # Brian Mattern <rephorm@rephorm.com>
  6. # Jason A. Donenfeld <Jason@zx2c4.com>
  7. # All Rights Reserved.
  8. #
  9. # This file is licensed under the GPLv2+.
  10. # Please visit http://git.zx2c4.com/password-store/tree/COPYING for more information.
  11. #
  12. # Oh my zsh plugin maintainer: Santiago Borrazás <sanbor@gmail.com>
  13. _pass () {
  14. local cmd
  15. if (( CURRENT > 2)); then
  16. cmd=${words[2]}
  17. # Set the context for the subcommand.
  18. curcontext="${curcontext%:*:*}:pass-$cmd"
  19. # Narrow the range of words we are looking at to exclude `pass'
  20. (( CURRENT-- ))
  21. shift words
  22. # Run the completion for the subcommand
  23. case "${cmd}" in
  24. init)
  25. _arguments : \
  26. "-r[re-encrypt existing passwords]" \
  27. "--reencrypt[re-encrypt existing passwords]"
  28. _pass_complete_keys
  29. ;;
  30. ls|list|edit)
  31. _pass_complete_entries_with_subdirs
  32. ;;
  33. insert)
  34. _arguments : \
  35. "-e[echo password to console]" \
  36. "--echo[echo password to console]" \
  37. "-m[multiline]" \
  38. "--multiline[multiline]"
  39. _pass_complete_entries_with_subdirs
  40. ;;
  41. generate)
  42. _arguments : \
  43. "-n[don't include symbols in password]" \
  44. "--no-symbols[don't include symbols in password]" \
  45. "-c[copy password to the clipboard]" \
  46. "--clip[copy password to the clipboard]"
  47. _pass_complete_entries_with_subdirs
  48. ;;
  49. rm)
  50. _arguments : \
  51. "-f[force deletion]" \
  52. "--force[force deletion]" \
  53. "-r[recursively delete]" \
  54. "--recursive[recursively delete]"
  55. _pass_complete_entries_with_subdirs
  56. ;;
  57. git)
  58. local -a subcommands
  59. subcommands=(
  60. "init:Initialize git repository"
  61. "push:Push to remote repository"
  62. "pull:Pull from remote repository"
  63. "config:Show git config"
  64. "log:Show git log"
  65. "reflog:Show git reflog"
  66. )
  67. _describe -t commands 'pass git' subcommands
  68. ;;
  69. show|*)
  70. _pass_cmd_show
  71. ;;
  72. esac
  73. else
  74. local -a subcommands
  75. subcommands=(
  76. "init:Initialize new password storage"
  77. "ls:List passwords"
  78. "show:Decrypt and print a password"
  79. "insert:Insert a new password"
  80. "generate:Generate a new password using pwgen"
  81. "edit:Edit a password with \$EDITOR"
  82. "rm:Remove the password"
  83. "git:Call git on the password store"
  84. "version:Output version information"
  85. "help:Output help message"
  86. )
  87. _describe -t commands 'pass' subcommands
  88. _arguments : \
  89. "--version[Output version information]" \
  90. "--help[Output help message]"
  91. _pass_cmd_show
  92. fi
  93. }
  94. _pass_cmd_show () {
  95. _arguments : \
  96. "-c[put it on the clipboard]" \
  97. "--clip[put it on the clipboard]"
  98. _pass_complete_entries
  99. }
  100. _pass_complete_entries_helper () {
  101. local IFS=$'\n'
  102. local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
  103. _values -C 'passwords' $(find -L "$prefix" \( -name .git -o -name .gpg-id \) -prune -o $@ -print | sed -e "s#${prefix}.##" -e 's#\.gpg##' | sort)
  104. }
  105. _pass_complete_entries_with_subdirs () {
  106. _pass_complete_entries_helper
  107. }
  108. _pass_complete_entries () {
  109. _pass_complete_entries_helper -type f
  110. }
  111. _pass_complete_keys () {
  112. local IFS=$'\n'
  113. # Extract names and email addresses from gpg --list-keys
  114. _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')
  115. }