Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
203 - 1
# main function bound to scl command
2
_scl()
3
{
4
    local cur actions cur_action collections
5
    COMPREPLY=()
6
 
7
    cur="${COMP_WORDS[COMP_CWORD]}"
8
    actions="enable run load unload list-collections list-packages man register deregister --help"
9
 
10
    collections=`scl list-collections`
11
 
12
    # Complete action names
13
    if ((COMP_CWORD == 1)); then
14
        COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
15
        return 0;
16
    fi
17
 
18
    # If there is command or separator in arguments then stop completition
19
    if ((COMP_CWORD > 3)); then
20
        for word in "${COMP_WORDS[@]}"; do
21
            if [[ ${word} == \'* || ${word} == \"* || ${word} == "--" ]] ; then
22
                return 0
23
            fi
24
        done
25
    fi
26
 
27
    # Complete one or none action argument
28
    if ((COMP_CWORD >= 2)); then
29
        cur_action="${COMP_WORDS[1]}"
30
 
31
        case "$cur_action" in
32
            # No argument
33
            list-collections|list-enabled|--help)
34
                return 0
35
            ;;
36
 
37
            # Argument is collection name
38
            list-packages|man)
39
                if ((COMP_CWORD == 2)); then
40
                    COMPREPLY=( $(compgen -W  "$collections" -- ${cur}) )
41
                fi
42
                return 0
43
            ;;
44
 
45
            # Argument is collection name or "-f" or "--force"
46
            deregister)
47
                if ((COMP_CWORD == 2)); then
48
                    COMPREPLY=( $(compgen -W  "$collections --force -f" -- ${cur}))
49
                fi
50
                if [ "$COMP_CWORD" -eq 3 -a  "(" "${COMP_WORDS[2]}" == "--force" -o "${COMP_WORDS[2]}" == "-f" ")" ]; then
51
                    COMPREPLY=( $(compgen -W  "$collections" -- ${cur}))
52
                fi
53
                return 0
54
            ;;
55
 
56
            # Argument is directory
57
            register)
58
                compopt -o plusdirs
59
                if ((COMP_CWORD == 2)); then
60
                    COMPREPLY=( $(compgen -A  directory -- ${cur}) )
61
                fi
62
                return 0
63
            ;;
64
 
65
            # Arguments are collections or "-x" or "--exec"
66
            run|enable)
67
                if ((COMP_CWORD == 2)); then
68
                    COMPREPLY=( $(compgen -W  "$collections -x --exec" -- ${cur}) )
69
                else
70
                    COMPREPLY=( $(compgen -W  "$collections" -- ${cur}) )
71
                fi
72
                return 0
73
            ;;
74
 
75
            # Arguments are collections
76
            load|unload)
77
                COMPREPLY=( $(compgen -W  "$collections" -- ${cur}) )
78
                return 0
79
            ;;
80
            *)
81
            ;;
82
        esac
83
    fi
84
 
85
}
86
 
87
# bind the scl command to the _scl function for completion
88
complete -F _scl scl