_pass 4.0 KB

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