aboutsummaryrefslogtreecommitdiffstats
path: root/etc/bash_completion
blob: 60762e3459aa9f40f414696db8e88c3b73f73f52 (plain) (blame)
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
70
71
72
73
74
#!/usr/bin/env bash
# Copyright (c) 2020, Eric Pailleau <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
# Date: April 12th 2020
# Bash completion for Erlang.mk

_erlang_mk()
{
    local cur prev words cword
    _init_completion || return

    T=$(make list-templates | cut -d ':' -f 2-)
    TP=$(echo -n $T | cut -d '_' -f 1 | tr ' ' '|')
    TPP=$(echo -n $T | tr ' ' '|')
    case $prev in
        make)
            COMPREPLY=( $(compgen -W "all app deps fetch-deps list-deps search rel docs install-docs check tests clean distclean help erlang-mk bootstrap bootstrap-lib bootstrap-rel new-app new-lib new new list-templates ct plt dialyze escript eunit shell sphinx xref cover-report all.coverdata" -- "$cur") )
            ;;
        search)
            COMPREPLY=( $(compgen -W 'q=' -- "$cur") ) && compopt -o nospace
            ;;
        new-app|new-lib)
            COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
            ;;
        new)
            COMPREPLY=( $(compgen -W 't=' -- "$cur") ) && compopt -o nospace
            ;;
        =)
            if [[ ${words[$cword - 2]} == "in" ]]; then
                COMPREPLY=( $(compgen -W "$(ls apps 2>/dev/null)" -- "$cur") ) && compopt -o nospace
            else
                if [[ ${words[$cword - 2]} == "t" ]]; then
                    COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
                fi
            fi
            ;;
        $TP)
            COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
            ;;
        $TPP)
            COMPREPLY=( $(compgen -W 'n=' -- "$cur") ) && compopt -o nospace
            ;;
        *)
        if [[ "$prev" == "in" && "$cur" == '=' ]]; then
            test -d apps && echo  1>&2
            test -d apps && echo $(ls apps 2>/dev/null)
                   COMPREPLY=( $(compgen -W "$(ls apps 2>/dev/null )" -- "$cur") ) && compopt -o nospace
        fi
        if [[ "$prev" == "t" && "$cur" == '=' ]]; then
            echo  1>&2
            echo $T 1>&2
                COMPREPLY=( $(compgen -W "$T" -- "$cur") ) && compopt -o nospace
        fi
            if [[ $(echo "$T" | tr ' ' "\n" | grep "$prev") ]]; then
                COMPREPLY=( $(compgen -W 'n=' -- "$cur") ) && compopt -o nospace
            fi
            if [[ ${words[$cword - 1]} == "n=" || ${words[$cword - 1]} == "n" ]]; then
                COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
            fi
            if [[ ${words[$cword - 3]} == "n" ]]; then
                COMPREPLY=( $(compgen -W 'in=' -- "$cur") ) && compopt -o nospace
            fi
            ;;
    esac

    case $cur in
        all|bootstrap|list|list-|new|new-)
            echo 1>&2
            make help | grep "^  $cur" 1>&2
            return
            ;;
    esac
} &&
complete -F _erlang_mk make