_pass 4.0 KB

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