File: casync

package info (click to toggle)
casync 2%2B20201210-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,948 kB
  • sloc: ansic: 31,284; sh: 423; python: 69; makefile: 6
file content (55 lines) | stat: -rw-r--r-- 1,301 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
# casync(1) completion                               -*- shell-script -*-
# vim: et sts=4 sw=4

# SPDX-License-Identifier: LGPL-2.1+

in_array() {
    local i
    for i in "${@:2}"; do
        [[ $1 = "$i" ]] && return
    done
}

_casync() {
    # Assigned variable by _init_completion:
    #   cur    Current argument.
    #   prev   Previous argument.
    #   words  Argument array.
    #   cword  Argument array size.
    local cur prev words cword
    _init_completion -n = || return

    # Commands and options
    local cmds=(digest extract gc list make mkdev mount mtree stat)
    local opts=(--help --version)

    # Check if a command was entered already
    local command i
    for (( i=0; i < ${#words[@]}-1; i++ )); do
        if in_array "${words[i]}" "${cmds[@]}"; then
            command=${words[i]}
            break
        fi
    done

    # Completion per command (TODO)
    if [[ -n $command ]]; then
        compopt -o default
        COMPREPLY=()
        return 0
    fi

    # Initial completion
    case "$cur" in
        -*)
            COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur"))
            return 0
            ;;
        *)
            COMPREPLY=($(compgen -W "${cmds[*]}" -- "$cur"))
            return 0
            ;;
    esac

} && \
complete -F _casync casync