_pass 3.1 KB

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