File: debdiff.bash_completion

package info (click to toggle)
devscripts 2.17.6%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,160 kB
  • sloc: perl: 17,547; sh: 8,903; python: 998; makefile: 219; ansic: 11
file content (126 lines) | stat: -rw-r--r-- 4,218 bytes parent folder | download | duplicates (3)
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
# /usr/share/bash-completion/completions/debdiff
# Bash command completion for ‘debdiff(1)’.
# Documentation: ‘bash(1)’, section “Programmable Completion”.

# Copyright © 2016 Ben Finney <ben+debian@benfinney.id.au>
# Copyright © 2015, Nicholas Bamber <nicholas@periapt.co.uk>

_debdiff()
{
    local options i
    local command_name=debdiff
    local file_list_mode=normal
    local -i move_from=-1
    local -i move_to=-1

    local cur prev words cword
    _init_completion || return

    options='-h --help -v --version'
    options+=' -q --quiet'
    options+=' -d --dirs --nodirs'
    options+=' -w --ignore-space'
    options+=' --diffstat --no-diffstat'
    options+=' --auto-ver-sort --no-auto-ver-sort'
    options+=' --unpack-tarballs --no-unpack-tarballs'
    options+=' --control --nocontrol --controlfiles'
    options+=' --wdiff-source-control --no-wdiff-source-control --wp --wl --wt'
    options+=' --show-moved --noshow-moved --renamed'
    options+=' --debs-dir'
    options+=' --from'
    options+=' --move --move-regex'
    options+=' --exclude'

    unset COMPREPLY

    case "$prev" in
        "$command_name")
            options+=' --noconf --no-conf'
            ;;

        --debs-dir)
            COMPREPLY=( $( compgen -A directory -- "$cur" ) )
            ;;

    esac

    if [[ -v COMPREPLY ]] ; then
        return 0
    fi

    for (( i=1; i<${#words[@]}; i++ )); do
        if [[ $file_list_mode == @(deb|dsc|changes) ]]; then
            if (( i == ${#words[@]}-1 )); then
                break
            else
                COMPREPLY=()
                return 0
            fi
        fi
        if (( ${move_from} == -1  && ${move_to} == -1 )); then
            file_list_mode=normal
        elif (( ${move_from} >= 0 && ${move_to} == -1 )); then
            file_list_mode=from
        elif (( ${move_from} >= 0 && ${move_to} >= 0 && ${move_to} < ${move_from} )); then
            file_list_mode=to
        else
            COMPREPLY=( ) 
            return 0
        fi
        if [[ $file_list_mode == normal && ${words[i]} == --from ]]; then
            move_from=0
            file_list_mode=from
        elif [[ $file_list_mode == normal && ${words[i]} == *.deb ]]; then
            file_list_mode=deb
        elif [[ $file_list_mode == normal && ${words[i]} == *.dsc ]]; then
            file_list_mode=dsc
        elif [[ $file_list_mode == normal && ${words[i]} == *.changes ]]; then
            file_list_mode=changes
        elif [[ $file_list_mode == from && ${words[i]} == *.deb ]]; then
            (( ++move_from ))
        elif [[ $file_list_mode == from && ${words[i]} == --to ]]; then
            move_to=0
            file_list_mode=to
        elif [[ $file_list_mode = to && ${words[i]} == *.deb ]]; then
            (( ++move_to ))
        fi
    done

    if [[ $file_list_mode == normal ]]; then

        if [[ $cur == -* ]]; then
            COMPREPLY=( $( compgen -W "${options}" -- "$cur" ) )
        else
            declare -a _compreply=( $( compgen -o filenames -G '*.@(deb|dsc|changes)' ) )
            COMPREPLY=( $( compgen -W "${_compreply[*]}"  -- "$cur" ) )
        fi
    elif [[ $file_list_mode == deb ]]; then
        declare -a _compreply=( $( compgen -o filenames -G '*.deb' ) )
        COMPREPLY=( $( compgen -W "${_compreply[*]}"  -- "$cur" ) )
    elif [[ $file_list_mode = dsc ]]; then
        declare -a _compreply=( $( compgen -o filenames -G '*.dsc' ) )
        COMPREPLY=( $( compgen -W "${_compreply[*]}"  -- "$cur" ) )
    elif [[ $file_list_mode = changes ]]; then
        declare -a _compreply=( $( compgen -o filenames -G '*.changes' ) )
        COMPREPLY=( $( compgen -W "${_compreply[*]}"  -- "$cur" ) )
    else
        options=$(find . -name '*.deb' | sed -e's!\.\/!!' |  paste -s -d' ')
        if [[ $file_list_mode == from ]]; then
            if (( $move_from > 0 )); then
                options+=' --to'
            fi
        fi
        COMPREPLY=( $( compgen -W "${options}" -- "$cur" ) )
    fi

    return 0
} &&
complete -F _debdiff debdiff


# Local variables:
# coding: utf-8
# mode: shell-script
# indent-tabs-mode: nil
# End:
# vim: fileencoding=utf-8 filetype=sh expandtab shiftwidth=4 :