File: incant_completion.sh

package info (click to toggle)
incant 0.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,996 kB
  • sloc: python: 1,482; sh: 35; makefile: 10; ruby: 1
file content (45 lines) | stat: -rw-r--r-- 1,581 bytes parent folder | download
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
# This is the Bash completion script for Incant

# _incant_completions: Provides autocompletion for Incant commands
_incant_completions() {
    local cur prev opts instance_names
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    
    # Commands like up, provision, destroy, list, dump
    opts="up provision destroy shell list dump init -f --config"


    # Handle auto-completion based on the previous command word
    case "${prev}" in
        -f|--config)
            COMPREPLY=( $(compgen -d -- "${cur}") $(compgen -f -X '!*.@(yaml|yaml.j2|yaml.mako)' -- "${cur}") )
            return 0
            ;;
        "up"|"provision"|"destroy"|"shell")
            # Fetch list of instances from the 'incant list' command
            instance_names=$(incant list --no-error)
            if [ $? -ne 0 ]; then
                COMPREPLY=( $(compgen -W "" -- ${cur}) )
                return 0
            fi
            instance_names=$(echo $instance_names | tr '\n' ' ')  # Convert the list to a space-separated string
            # Complete with instance names
            COMPREPLY=( $(compgen -W "${instance_names}" -- ${cur}) )
            return 0
            ;;
        "list"|"dump"|"init")
            # No further completion needed
            return 0
            ;;
        *)
            # Complete with the general commands (up, provision, etc.)
            COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
            return 0
            ;;
    esac
}

# Enable completion for incant
complete -F _incant_completions incant