summaryrefslogtreecommitdiffhomepage
path: root/debian/git-buildpackage.bash-completion
blob: c6a1c824858720879f2464b44d23ddb6bb63c3d1 (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
# -*- shell-script -*-
#
# Bash tab auto-completion rules for git-buildpackage.
#
# Copyright (C) 2010  Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
# Copyright (C) 2010  Guido Guenther <agx@sigxcpu.org>
#
# Distributed under the GNU General Public License, version 2.0.

_gbp_branches ()
{
     [ -d .git ] || return 0
     git  for-each-ref --format="%(refname:short)" refs/heads
}


_gbp_options ()
{
    $1 --help | egrep -o '^ +\-\-[a-z\-]+=?'
}


_gbp_comp ()
{
    local cur="${COMP_WORDS[COMP_CWORD]}"
    local prev="${COMP_WORDS[COMP_CWORD - 1]}"
    local options=$1
    local branch_opts=$2

# COMPREPLY considers '=' as a word. For $prev we prefer the word before the actual "="
    if [[ "$prev" == "=" ]]
    then
        prev="${COMP_WORDS[COMP_CWORD - 2]}"
    elif [[ "$cur" == "=" ]]
    then
        cur=""
    fi

    if [[ "${branch_opts}" == *$prev* ]]; then
	local refs=$(_gbp_branches)
        COMPREPLY=( $(compgen -W "$refs" -- $cur ) )
        return 0
    fi

    COMPREPLY=($(compgen -W "$options" -- $cur))
}


have git-buildpackage &&
_git_buildpackage()
{
    local options=$(_gbp_options git-buildpackage)
    local branch_opts="--git-debian-branch\= --git-upstream-branch\="

    _gbp_comp "$options" "$branch_opts"
}
[ "${have:-}" ] && complete -F _git_buildpackage -o default git-buildpackage


have git-dch &&
_git_dch ()
{
    local options=$(_gbp_options git-dch)
    local branch_opts="--debian-branch\="

    _gbp_comp "$options" "$branch_opts"
}
[ "${have:-}" ] && complete -F _git_dch -o default git-dch


have git-import-orig &&
_git_import_orig ()
{
    local options=$(_gbp_options git-import-orig)
    local branch_opts="--debian-branch\= --upstream-branch\="

    _gbp_comp "$options" "$branch_opts"
}
[ "${have:-}" ] && complete -F _git_import_orig -o default git-import-orig


have git-import-dsc &&
_git_import_dsc ()
{
    local options=$(_gbp_options git-import-dsc)
    local branch_opts="--debian-branch\= --upstream-branch\="

    _gbp_comp "$options" "$branch_opts"
}
[ "${have:-}" ] && complete -F _git_import_dsc -o default git-import-dsc