summaryrefslogtreecommitdiff
path: root/plugins/lpass/_lpass
blob: 621a7bcd7fc4963a637498e350ae7fdbb6d8208a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#compdef lpass

_lpass() {
    local cmd has_color has_sync has_interactive
  	if (( CURRENT > 2)); then
        cmd=${words[2]}
        # Set the context for the subcommand.
        curcontext="${curcontext%:*:*}:lpass-$cmd"
        # Narrow the range of words we are looking at to exclude `lpass'
        (( CURRENT-- ))
        shift words
        # Run the completion for the subcommand
        case "${cmd}" in
            login)
                _arguments : \
                  '--trust[Cause subsequent logins to not require multifactor authentication.]' \
                  '--plaintext-key[Save plaintext decryption key to the hard disk]' \
                  '--force[Do not ask on saving plaintext key]'
                has_color=1
            ;;

            logout)
                _arguments : '--force[Force confirmation]'
                has_color=1
            ;;
            show)
                _arguments : \
                  '(-c --clip)'{-c,--clip}'[Copy output to clipboard]' \
                  '(-x --expand-multi)'{-x,---expand-multi}'[Show the requested information from all of the matching sites]' \
                  '(--all --username --password --url --notes --field= --id --name --attach=)'{--all,--username,--password,--url,--notes,--field=,--id,--name,--attach=}'[Output the specific field]' \
                  '(--basic-regexp,--fixed-string)'{-G,--basic-regexp}'[Find a site by substring or regular expression]' \
                  '--format=[Format output with printf-style placeholders]'
                _lpass_complete_uniqenames
                has_color=1
                has_sync=1
            ;;

            ls)
                _arguments : \
                  '(-l --long)'{-l,--long}'[Also list the last modification time and username]' \
                  '-u[List username]' \
                  '-m[List modification time]' \
                  '--format=[Format output with printf-style placeholders]'
      				  _lpass_complete_groups
                has_color=1
                has_sync=1
      			;;
            mv)
                _lpass_complete_uniqenames
                _lpass_complete_groups
                has_color=1
            ;;
            duplicate|rm)
                _lpass_complete_uniqenames
                has_color=1
                has_sync=1
            ;;
            add)
                _arguments : '(--username --password --url --notes --field=)'{--username,--password,--url,--notes,--field=}'[Add field]'
                _lpass_complete_uniqenames
                has_color=1
                has_sync=1
                has_interactive=1
            ;;
            edit)
                _arguments : '(--name --username --password --url --notes --field=)'{--name,--username,--password,--url,--notes,--field=}'[Update field]'
                _lpass_complete_uniqenames
                has_color=1
                has_sync=1
                has_interactive=1
            ;;
            generate)
                _arguments : \
                  '(-c --clip)'{-c,--clip}'[Copy output to clipboard]' \
                  '--username=[USERNAME]' \
                  '--url=[URL]' \
                  '--no-symbols[Do not use symbols]'
                has_sync=1
            ;;
            status)
               _arguments : '(-q --quiet)'{-q,--quiet}'[Supress output to stdout]'
                has_color=1
            ;;
            sync)
                _arguments : '(-b --background)'{-b,--background}'[Run sync in background]'
                has_color=1
            ;;
            export)
                _arguments : '--fields=[Field list]'
                has_color=1
                has_sync=1
            ;;
            import)
              if ((CURRENT < 3)); then
                _files
              fi
            ;;
        esac

        if [ -n "$has_sync" ] || [ -n "$has_color" ] || [ -n "$has_interactive" ]; then
            local -a generic_options
            if [ "$has_sync" -eq 1 ]; then
                generic_options+=('--sync=[Synchronize local cache with server: auto | now | no]')
            fi
            if [ "$has_color" -eq 1 ]; then
                generic_options+=('--color=[Color: auto | never | always]')
            fi
            if [ "$has_interactive" -eq 1 ]; then
                generic_options+=("--non-interactive[Use standard input instead of $EDITOR]")
            fi
            _arguments $generic_options
        fi
    else
        local -a subcommands
        subcommands=(
          "login:Authenticate with the LastPass server and initialize a local cache"
          "logout:Remove the local cache and stored encryption keys"
          "passwd:Change your LastPass password"
          "show:Display a password or selected field"
          "ls:List names in groups in a tree structure"
          "mv:Move the specified entry to a new group"
          "add:Add a new entry"
          "edit:Edit the selected field"
          "generate:Create a randomly generated password"
          "duplicate:Create a duplicate entry of the one specified"
          "rm:Remove the specified entry"
          "status:Show current login status"
          "sync:Synchronize local cache with server"
          "export:Dump all account information including passwords as unencrypted csv to stdout"
          "import:Upload accounts from an unencrypted CSV file to the server"
          "share:Manipulate shared folders (only enterprise or premium user)"
        )
        _describe -t commands 'lpass' subcommands
        _arguments : \
          '(-h --help)'{-h,--help}'[show help]' \
          '(-v --version)'{-v,--version}'[show version]'

    fi
}

_lpass_complete_uniqenames(){
  local -a entries
  while read i;  do
    if [ -n "$i" ]; then
      entries+=("$i")
    fi
  done < <(lpass ls --sync auto --format "%an" --color=never)
  compadd -a entries
}


_lpass_complete_groups() {
  local -a entries
  while read i;  do
    if [ -n "$i" ]; then
      entries+=("$i")
    fi
  done < <(lpass ls --sync auto --format "%aN" --color=never | grep -E "\/$")
  compadd -a entries
}

_lpass
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et