File: bash-completion.template

package info (click to toggle)
auxilium 0.0.26
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 56 kB
  • sloc: sh: 344; makefile: 10
file content (34 lines) | stat: -rw-r--r-- 879 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
#!/bin/bash completion for {scriptname}

_{scriptname}(){
    local cur prev
    local -A ARGS MAP FORCE OPTS OPTS_SUB MULTI

    COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"

    OPTS=({opts})
    ARGS=({args})
    MAP=({map})

    if [ ! -z "$prev" ]; then
        # if is an argument complete with list of choice if define
        prev_key=${MAP[$prev]}
        if [ ! -z "$prev_key" ] && [ -v "${ARGS[$prev_key]}" ]; then
            COMPREPLY=($(compgen -W "${ARGS[$prev_key]}" -- "${cur}"))
            return 0
        fi
    fi
    for in_use in ${COMP_WORDS[@]:1}; do
        key=${MAP[$in_use]}
        # Unset option that is already use
          unset OPTS[$key]
          unset ARGS[$key]
    done
    compl="${OPTS[@]}"
    COMPREPLY=($(compgen -W "${compl}" -- "${cur}"))
    return 0
}

complete -F _{scriptname} {scriptname}