File: bash-completion

package info (click to toggle)
prcs 1.3.3-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,128 kB
  • ctags: 3,354
  • sloc: cpp: 17,486; ansic: 8,132; sh: 4,710; perl: 2,729; lisp: 1,816; tcl: 1,142; lex: 354; makefile: 225; pascal: 85
file content (127 lines) | stat: -rwxr-xr-x 3,861 bytes parent folder | download | duplicates (2)
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
#-*- mode: shell-script;-*-

# Debian GNU/Linux prcs(1) completion for Bash.
# Copyright (C) 2002 Rafael Laboissiere <rafael@laboissiere.net>
# Distribute under the terms of the GNU GPL.

# This script is intended to work with the /etc/bash_completion file and the
# associated /etc/bash_completion.d/ sourcing mechanism (see Ian Macdonald's
# bashcompletion project at http://freshmeat.net/projects/bashcompletion/).
# If you are using this script standalone, please define first the "have"
# function like this:
#    have ()
#    {
#        unset -v have;
#        type $1 >&/dev/null;
#        [ $? -eq 0 ] && have="yes"
#    }

have prcs &&
_prcs()
{
    local subcommands admin_subcommands stdopt cur prev prevprev \
          repo projects extraopt

    subcommands='--help --version admin checkin checkout config delete \
                 depopulate diff execute info merge package populate \
		 rekey unpackage changes'
    admin_subcommands='--help compress uncompress access rebuild init \
                       pdelete pinfo prename'
    stdopt='--help --force --jobs --long-format --long-long-format \
            --no-action --plain-format --quiet --repository --skilled-merge \
            --version'

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
    if [ "$COMP_CWORD" -ge 2 ] ; then
        prevprev=${COMP_WORDS[COMP_CWORD-2]}
    fi

    if [ "$PRCS_REPOSITORY" ] ; then
        repo=$PRCS_REPOSITORY
    else
        repo="$HOME/PRCS"
    fi
    projects=$( \ls -1 $repo | grep ^$cur )

    if [ "$COMP_CWORD" = 1 ] ; then
	COMPREPLY=( $( compgen -W "$subcommands" | grep ^$cur ) )

    elif [ "$COMP_CWORD" = 2 ] ; then
        case "$prev" in
	admin)
	    COMPREPLY=( $( compgen -W "$admin_subcommands" | grep ^$cur ) )
            ;;
        checkin|checkout|diff|merge|rekey|info|changes\
        |populate|depopulate|package|execute)
	    case "$prev" in
		checkin)
                extraopt='--revision --unlink --jobs --version-log'
                ;;
            checkout)
                extraopt='--revision --unlink --preserve \
                          --exclude-project-file'
                ;;
            diff)
                extraopt='--revision --keywords --new \
                          --exclude-project-file'
                ;;
            merge)
                extraopt='--revision --unlink --skilled-merge'
                ;;
		    rekey)
                extraopt='--unlink'
                ;;
            info)
                extraopt='--revision --sort'
                ;;
            changes)
                extraopt='--revision'
                ;;
            populate)
                extraopt='--delete --unlink --no-keywords'
                ;;
            depopulate)
                extraopt='--unlink'
                ;;
            package)
                extraopt='--compress'
                ;;
            execute)
                extraopt='--revision --exclude-project-file \
                          --pre --all --pipe --match --not'
                ;;
            esac

            COMPREPLY=( $projects $( compgen -W "$stdopt $extraopt" \
                               -G '*.prj' | grep ^$cur ) )
            ;;
        *)
            ;;
        esac

    elif [ "$COMP_CWORD" = 3 -a "$prevprev" = admin ] ; then
        case "$prev" in
        compress|uncompress|access|rebuild|init|pdelete|prename)
            extraopt=''
            case "$prev" in
            uncompress)
                extraopt='--immediate'
            esac
            COMPREPLY=( $projects $( compgen -W "$stdopt $extraopt" \
                           -G '*.prj' | grep ^$cur ) )
            ;;
        *)
            ;;
        esac

    else
        COMPREPLY=( $( compgen -o default | grep ^$cur ) )
    fi
    
    return 0

}

[ "$have" ] && complete -F _prcs prcs