_lpass 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #compdef lpass
  2. _lpass() {
  3. local cmd has_color has_sync has_interactive
  4. if (( CURRENT > 2)); then
  5. cmd=${words[2]}
  6. # Set the context for the subcommand.
  7. curcontext="${curcontext%:*:*}:lpass-$cmd"
  8. # Narrow the range of words we are looking at to exclude `lpass'
  9. (( CURRENT-- ))
  10. shift words
  11. # Run the completion for the subcommand
  12. case "${cmd}" in
  13. login)
  14. _arguments : \
  15. '--trust[Cause subsequent logins to not require multifactor authentication.]' \
  16. '--plaintext-key[Save plaintext decryption key to the hard disk]' \
  17. '--force[Do not ask on saving plaintext key]'
  18. has_color=1
  19. ;;
  20. logout)
  21. _arguments : '--force[Force confirmation]'
  22. has_color=1
  23. ;;
  24. show)
  25. _arguments : \
  26. '(-c --clip)'{-c,--clip}'[Copy output to clipboard]' \
  27. '(-x --expand-multi)'{-x,---expand-multi}'[Show the requested information from all of the matching sites]' \
  28. '(--all --username --password --url --notes --field= --id --name --attach=)'{--all,--username,--password,--url,--notes,--field=,--id,--name,--attach=}'[Output the specific field]' \
  29. '(--basic-regexp,--fixed-string)'{-G,--basic-regexp}'[Find a site by substring or regular expression]' \
  30. '--format=[Format output with printf-style placeholders]'
  31. _lpass_complete_uniqenames
  32. has_color=1
  33. has_sync=1
  34. ;;
  35. ls)
  36. _arguments : \
  37. '(-l --long)'{-l,--long}'[Also list the last modification time and username]' \
  38. '-u[List username]' \
  39. '-m[List modification time]' \
  40. '--format=[Format output with printf-style placeholders]'
  41. _lpass_complete_groups
  42. has_color=1
  43. has_sync=1
  44. ;;
  45. mv)
  46. _lpass_complete_uniqenames
  47. _lpass_complete_groups
  48. has_color=1
  49. ;;
  50. duplicate|rm)
  51. _lpass_complete_uniqenames
  52. has_color=1
  53. has_sync=1
  54. ;;
  55. add)
  56. _arguments : '(--username --password --url --notes --field=)'{--username,--password,--url,--notes,--field=}'[Add field]'
  57. _lpass_complete_uniqenames
  58. has_color=1
  59. has_sync=1
  60. has_interactive=1
  61. ;;
  62. edit)
  63. _arguments : '(--name --username --password --url --notes --field=)'{--name,--username,--password,--url,--notes,--field=}'[Update field]'
  64. _lpass_complete_uniqenames
  65. has_color=1
  66. has_sync=1
  67. has_interactive=1
  68. ;;
  69. generate)
  70. _arguments : \
  71. '(-c --clip)'{-c,--clip}'[Copy output to clipboard]' \
  72. '--username=[USERNAME]' \
  73. '--url=[URL]' \
  74. '--no-symbols[Do not use symbols]'
  75. has_sync=1
  76. ;;
  77. status)
  78. _arguments : '(-q --quiet)'{-q,--quiet}'[Supress output to stdout]'
  79. has_color=1
  80. ;;
  81. sync)
  82. _arguments : '(-b --background)'{-b,--background}'[Run sync in background]'
  83. has_color=1
  84. ;;
  85. export)
  86. _arguments : '--fields=[Field list]'
  87. has_color=1
  88. has_sync=1
  89. ;;
  90. import)
  91. if ((CURRENT < 3)); then
  92. _files
  93. fi
  94. ;;
  95. esac
  96. if [ -n "$has_sync" ] || [ -n "$has_color" ] || [ -n "$has_interactive" ]; then
  97. local -a generic_options
  98. if [ "$has_sync" -eq 1 ]; then
  99. generic_options+=('--sync=[Synchronize local cache with server: auto | now | no]')
  100. fi
  101. if [ "$has_color" -eq 1 ]; then
  102. generic_options+=('--color=[Color: auto | never | always]')
  103. fi
  104. if [ "$has_interactive" -eq 1 ]; then
  105. generic_options+=("--non-interactive[Use stardard input instead of $EDITOR]")
  106. fi
  107. _arguments $generic_options
  108. fi
  109. else
  110. local -a subcommands
  111. subcommands=(
  112. "login:Authenticate with the LastPass server and initialize a local cache"
  113. "logout:Remove the local cache and stored encryption keys"
  114. "passwd:Change your LastPass password"
  115. "show:Display a password or selected field"
  116. "ls:List names in groups in a tree structure"
  117. "mv:Move the specified entry to a new group"
  118. "add:Add a new entry"
  119. "edit:Edit the selected field"
  120. "generate:Create a randomly generated password"
  121. "duplicate:Create a duplicate entry of the one specified"
  122. "rm:Remove the specified entry"
  123. "status:Show current login status"
  124. "sync:Synchronize local cache with server"
  125. "export:Dump all account information including passwords as unencrypted csv to stdout"
  126. "import:Upload accounts from an unencrypted CSV file to the server"
  127. "share:Manipulate shared folders (only enterprise or premium user)"
  128. )
  129. _describe -t commands 'lpass' subcommands
  130. _arguments : \
  131. '(-h --help)'{-h,--help}'[show help]' \
  132. '(-v --version)'{-v,--version}'[show version]'
  133. fi
  134. }
  135. _lpass_complete_uniqenames(){
  136. local -a entries
  137. while read i; do
  138. if [ -n "$i" ]; then
  139. entries+=("$i")
  140. fi
  141. done < <(lpass ls --sync auto --format "%an" --color=never)
  142. compadd -a entries
  143. }
  144. _lpass_complete_groups() {
  145. local -a entries
  146. while read i; do
  147. if [ -n "$i" ]; then
  148. entries+=("$i")
  149. fi
  150. done < <(lpass ls --sync auto --format "%aN" --color=never | grep -E "\/$")
  151. compadd -a entries
  152. }
  153. _lpass
  154. # Local Variables:
  155. # mode: Shell-Script
  156. # sh-indentation: 2
  157. # indent-tabs-mode: nil
  158. # sh-basic-offset: 2
  159. # End:
  160. # vim: ft=zsh sw=2 ts=2 et