_pass 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #compdef pass
  2. #autoload
  3. # Copyright (C) 2012 - 2014:
  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 https://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. "-p[gpg-id will only be applied to this subfolder]" \
  27. "--path[gpg-id will only be applied to this subfolder]"
  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. "-f[force overwrite]" \
  48. "--force[force overwrite]" \
  49. "-i[replace first line]" \
  50. "--in-place[replace first line]"
  51. _pass_complete_entries_with_subdirs
  52. ;;
  53. cp|copy|mv|rename)
  54. _arguments : \
  55. "-f[force rename]" \
  56. "--force[force rename]"
  57. _pass_complete_entries_with_subdirs
  58. ;;
  59. rm)
  60. _arguments : \
  61. "-f[force deletion]" \
  62. "--force[force deletion]" \
  63. "-r[recursively delete]" \
  64. "--recursive[recursively delete]"
  65. _pass_complete_entries_with_subdirs
  66. ;;
  67. git)
  68. local -a subcommands
  69. subcommands=(
  70. "init:Initialize git repository"
  71. "push:Push to remote repository"
  72. "pull:Pull from remote repository"
  73. "config:Show git config"
  74. "log:Show git log"
  75. "reflog:Show git reflog"
  76. )
  77. _describe -t commands 'pass git' subcommands
  78. ;;
  79. show|*)
  80. _pass_cmd_show
  81. ;;
  82. esac
  83. else
  84. local -a subcommands
  85. subcommands=(
  86. "init:Initialize new password storage"
  87. "ls:List passwords"
  88. "find:Find password files or directories based on pattern"
  89. "grep:Search inside decrypted password files for matching pattern"
  90. "show:Decrypt and print a password"
  91. "insert:Insert a new password"
  92. "generate:Generate a new password using pwgen"
  93. "edit:Edit a password with \$EDITOR"
  94. "mv:Rename the password"
  95. "cp:Copy the password"
  96. "rm:Remove the password"
  97. "git:Call git on the password store"
  98. "version:Output version information"
  99. "help:Output help message"
  100. )
  101. _describe -t commands 'pass' subcommands
  102. _arguments : \
  103. "--version[Output version information]" \
  104. "--help[Output help message]"
  105. _pass_cmd_show
  106. fi
  107. }
  108. _pass_cmd_show () {
  109. _arguments : \
  110. "-c[put it on the clipboard]" \
  111. "--clip[put it on the clipboard]"
  112. _pass_complete_entries
  113. }
  114. _pass_complete_entries_helper () {
  115. local IFS=$'\n'
  116. local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
  117. _values -C 'passwords' ${$(find -L "$prefix" \( -name .git -o -name .gpg-id \) -prune -o $@ -print 2>/dev/null | sed -e "s#${prefix}/\{0,1\}##" -e 's#\.gpg##' | sort):-""}
  118. }
  119. _pass_complete_entries_with_subdirs () {
  120. _pass_complete_entries_helper
  121. }
  122. _pass_complete_entries () {
  123. _pass_complete_entries_helper -type f
  124. }
  125. _pass_complete_keys () {
  126. local IFS=$'\n'
  127. # Extract names and email addresses from gpg --list-keys
  128. _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')
  129. }
  130. _pass