_pass 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # This file is licensed under the GPLv2+.
  9. # Please visit https://git.zx2c4.com/password-store/tree/COPYING for more information.
  10. # If you use multiple repositories, you can configure completion like this:
  11. #
  12. # compdef _pass workpass
  13. # zstyle ':completion::complete:workpass::' prefix "$HOME/work/pass"
  14. # workpass() {
  15. # PASSWORD_STORE_DIR=$HOME/work/pass pass $@
  16. # }
  17. # If you use multiple repositories, you can configure completion like this:
  18. #
  19. # compdef _pass workpass
  20. # zstyle ':completion::complete:workpass::' prefix "$HOME/work/pass"
  21. # workpass() {
  22. # PASSWORD_STORE_DIR=$HOME/work/pass pass $@
  23. # }
  24. _pass () {
  25. local cmd
  26. if (( CURRENT > 2)); then
  27. cmd=${words[2]}
  28. # Set the context for the subcommand.
  29. curcontext="${curcontext%:*:*}:pass-$cmd"
  30. # Narrow the range of words we are looking at to exclude `pass'
  31. (( CURRENT-- ))
  32. shift words
  33. # Run the completion for the subcommand
  34. case "${cmd}" in
  35. init)
  36. _arguments : \
  37. "-p[gpg-id will only be applied to this subfolder]" \
  38. "--path[gpg-id will only be applied to this subfolder]"
  39. _pass_complete_keys
  40. ;;
  41. ls|list|edit)
  42. _pass_complete_entries_with_subdirs
  43. ;;
  44. insert)
  45. _arguments : \
  46. "-e[echo password to console]" \
  47. "--echo[echo password to console]" \
  48. "-m[multiline]" \
  49. "--multiline[multiline]"
  50. _pass_complete_entries_with_subdirs
  51. ;;
  52. generate)
  53. _arguments : \
  54. "-n[don't include symbols in password]" \
  55. "--no-symbols[don't include symbols in password]" \
  56. "-c[copy password to the clipboard]" \
  57. "--clip[copy password to the clipboard]" \
  58. "-f[force overwrite]" \
  59. "--force[force overwrite]" \
  60. "-i[replace first line]" \
  61. "--in-place[replace first line]"
  62. _pass_complete_entries_with_subdirs
  63. ;;
  64. cp|copy|mv|rename)
  65. _arguments : \
  66. "-f[force rename]" \
  67. "--force[force rename]"
  68. _pass_complete_entries_with_subdirs
  69. ;;
  70. rm)
  71. _arguments : \
  72. "-f[force deletion]" \
  73. "--force[force deletion]" \
  74. "-r[recursively delete]" \
  75. "--recursive[recursively delete]"
  76. _pass_complete_entries_with_subdirs
  77. ;;
  78. git)
  79. local -a subcommands
  80. subcommands=(
  81. "init:Initialize git repository"
  82. "push:Push to remote repository"
  83. "pull:Pull from remote repository"
  84. "config:Show git config"
  85. "log:Show git log"
  86. "reflog:Show git reflog"
  87. )
  88. _describe -t commands 'pass git' subcommands
  89. ;;
  90. show|*)
  91. _pass_cmd_show
  92. ;;
  93. esac
  94. else
  95. local -a subcommands
  96. subcommands=(
  97. "init:Initialize new password storage"
  98. "ls:List passwords"
  99. "find:Find password files or directories based on pattern"
  100. "grep:Search inside decrypted password files for matching pattern"
  101. "show:Decrypt and print a password"
  102. "insert:Insert a new password"
  103. "generate:Generate a new password using pwgen"
  104. "edit:Edit a password with \$EDITOR"
  105. "mv:Rename the password"
  106. "cp:Copy the password"
  107. "rm:Remove the password"
  108. "git:Call git on the password store"
  109. "version:Output version information"
  110. "help:Output help message"
  111. )
  112. _describe -t commands 'pass' subcommands
  113. _arguments : \
  114. "--version[Output version information]" \
  115. "--help[Output help message]"
  116. _pass_cmd_show
  117. fi
  118. }
  119. _pass_cmd_show () {
  120. _arguments : \
  121. "-c[put it on the clipboard]" \
  122. "--clip[put it on the clipboard]"
  123. _pass_complete_entries
  124. }
  125. _pass_complete_entries_helper () {
  126. local IFS=$'\n'
  127. local prefix
  128. zstyle -s ":completion:${curcontext}:" prefix prefix || prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
  129. _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##' -e 's#\\#\\\\#' | sort):-""}
  130. }
  131. _pass_complete_entries_with_subdirs () {
  132. _pass_complete_entries_helper
  133. }
  134. _pass_complete_entries () {
  135. _pass_complete_entries_helper -type f
  136. }
  137. _pass_complete_keys () {
  138. local IFS=$'\n'
  139. # Extract names and email addresses from gpg --list-keys
  140. _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')
  141. }
  142. _pass