summaryrefslogtreecommitdiffstats
path: root/etc/completion/completion.bash
blob: 9bb27207d6e38603bd6591dfe39dde2562b1c245 (plain)
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
#!/bin/bash

__delta_previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob

__delta_complete_commands() {
    COMPREPLY=( $(compgen -W "${commands[*]}" -- "$cur") )
}

_delta_delta() {
    __delta_complete_commands
}

_delta() {
    local previous_extglob_setting=$(shopt -p extglob)
    shopt -s extglob

    local commands=(
        --raw
        --commit-style
        --dark
        --file-style
        --help
        --highlight-removed
        --hunk-style
        --light
        --list-languages
        --list-themes
        --list-theme-names
        --minus-color
        --minus-emph-color
        --plus-color
        --plus-emph-color
        --keep-plus-minus-markers
        --show-background-colors
        --theme
        --version
        --width
    )

    COMPREPLY=()
    local cur prev words cword
    _get_comp_words_by_ref -n : cur prev words cword

    local command='delta' command_pos=0
    local counter=1
    while [ $counter -lt $cword ]; do
      case "${words[$counter]}" in
          *)
              command="${words[$counter]}"
              command_pos=$counter
              break
              ;;
      esac
      (( counter++ ))
    done

    local completions_func=_delta_${command}

    declare -F $completions_func >/dev/null && $completions_func

    eval "$previous_extglob_setting"
    return 0
}

eval "$__delta_previous_extglob_setting"
unset __delta_previous_extglob_setting

complete -F _delta delta