~ubuntu-branches/debian/jessie/password-store/jessie

« back to all changes in this revision

Viewing changes to contrib/pass.bash-completion

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-04-14 16:40:29 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140414164029-lfkwiep2sltmsaic
Tags: 1.5-1
* New upstream release (closes: #744723).
  - Fix typos in "pass generate" documentation (closes: #739949).
* Go back to recommending xclip; pass now supports asking it to copy to
  the PRIMARY selection using PASSWORD_STORE_X_SELECTION=primary.
* Use dh_python2 to stop python-support generating
  /usr/share/python-support/pass.private.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# completion file for bash
2
 
 
3
 
# Copyright (C) 2012 Jason A. Donenfeld <Jason@zx2c4.com> and
4
 
# Brian Mattern <rephorm@rephorm.com>. All Rights Reserved.
5
 
# This file is licensed under the GPLv2+. Please see COPYING for more information.
6
 
 
7
 
_pass_complete_entries () {
8
 
        prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store/}"
9
 
        suffix=".gpg"
10
 
        autoexpand=${1:-0}
11
 
 
12
 
        local IFS=$'\n'
13
 
        local items=($(compgen -f $prefix$cur))
14
 
        for item in ${items[@]}; do
15
 
                if [[ $item == $prefix.* ]]; then
16
 
                        continue
17
 
                fi
18
 
 
19
 
                # if there is a unique match, and it is a directory with one entry
20
 
                # autocomplete the subentry as well (recursively)
21
 
                if [[ ${#items[@]} -eq 1 && $autoexpand -eq 1 ]]; then
22
 
                        while [[ -d $item ]]; do
23
 
                                local subitems=($(compgen -f "$item/"))
24
 
                                if [[ ${#subitems[@]} -eq 1 ]]; then
25
 
                                        item="${subitems[0]}"
26
 
                                else
27
 
                                        break
28
 
                                fi
29
 
                        done
30
 
                fi
31
 
 
32
 
                # append / to directories
33
 
                [[ -d $item ]] && item="$item/"
34
 
 
35
 
                item="${item%$suffix}"
36
 
                COMPREPLY+=("${item#$prefix}")
37
 
        done
38
 
}
39
 
 
40
 
_pass_complete_keys () {
41
 
        local IFS=$'\n'
42
 
        local GPG=gpg2
43
 
        which $GPG >/dev/null || GPG=gpg
44
 
        # Extract names and email addresses from gpg --list-keys
45
 
        local keys="$($GPG --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')"
46
 
        COMPREPLY+=($(compgen -W "${keys}" -- ${cur}))
47
 
}
48
 
 
49
 
_pass()
50
 
{
51
 
        COMPREPLY=()
52
 
        local cur="${COMP_WORDS[COMP_CWORD]}"
53
 
        local commands="init ls show insert generate edit rm git help version"
54
 
        if [[ $COMP_CWORD -gt 1 ]]; then
55
 
                case "${COMP_WORDS[1]}" in
56
 
                        init)
57
 
                                COMPREPLY+=($(compgen -W "-e --reencrypt" -- ${cur}))
58
 
                                _pass_complete_keys
59
 
                                ;;
60
 
                        ls|list|edit)
61
 
                                _pass_complete_entries
62
 
                                ;;
63
 
                        show|-*)
64
 
                                COMPREPLY+=($(compgen -W "-c --clip" -- ${cur}))
65
 
                                _pass_complete_entries 1
66
 
                                ;;
67
 
                        insert)
68
 
                                COMPREPLY+=($(compgen -W "-e --echo -m --multiline -f --force" -- ${cur}))
69
 
                                _pass_complete_entries
70
 
                                ;;
71
 
                        generate)
72
 
                                COMPREPLY+=($(compgen -W "-n --no-symbols -c --clip -f --force" -- ${cur}))
73
 
                                _pass_complete_entries
74
 
                                ;;
75
 
                        rm|remove|delete)
76
 
                                COMPREPLY+=($(compgen -W "-r --recursive -f --force" -- ${cur}))
77
 
                                _pass_complete_entries
78
 
                                ;;
79
 
                        git)
80
 
                                COMPREPLY+=($(compgen -W "init push pull config log reflog" -- ${cur}))
81
 
                                ;;
82
 
                esac
83
 
        else
84
 
                COMPREPLY+=($(compgen -W "${commands}" -- ${cur}))
85
 
                _pass_complete_entries 1
86
 
        fi
87
 
}
88
 
 
89
 
complete -o filenames -o nospace -F _pass pass