Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
# This file is part of the Symfony package.
2
#
3
# (c) Fabien Potencier <fabien@symfony.com>
4
#
5
# For the full copyright and license information, please view
6
# https://symfony.com/doc/current/contributing/code/license.html
7
 
8
#
9
# zsh completions for {{ COMMAND_NAME }}
10
#
11
# References:
12
#   - https://github.com/spf13/cobra/blob/master/zsh_completions.go
13
#   - https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Console/Resources/completion.bash
14
#
15
_sf_{{ COMMAND_NAME }}() {
16
    local lastParam flagPrefix requestComp out comp
17
    local -a completions
18
 
19
    # The user could have moved the cursor backwards on the command-line.
20
    # We need to trigger completion from the $CURRENT location, so we need
21
    # to truncate the command-line ($words) up to the $CURRENT location.
22
    # (We cannot use $CURSOR as its value does not work when a command is an alias.)
23
    words=("${=words[1,CURRENT]}") lastParam=${words[-1]}
24
 
25
    # For zsh, when completing a flag with an = (e.g., {{ COMMAND_NAME }} -n=<TAB>)
26
    # completions must be prefixed with the flag
27
    setopt local_options BASH_REMATCH
28
    if [[ "${lastParam}" =~ '-.*=' ]]; then
29
        # We are dealing with a flag with an =
30
        flagPrefix="-P ${BASH_REMATCH}"
31
    fi
32
 
33
    # Prepare the command to obtain completions
34
    requestComp="${words[0]} ${words[1]} _complete --no-interaction -szsh -a{{ VERSION }} -c$((CURRENT-1))" i=""
35
    for w in ${words[@]}; do
36
        w=$(printf -- '%b' "$w")
37
        # remove quotes from typed values
38
        quote="${w:0:1}"
39
        if [ "$quote" = \' ]; then
40
            w="${w%\'}"
41
            w="${w#\'}"
42
        elif [ "$quote" = \" ]; then
43
            w="${w%\"}"
44
            w="${w#\"}"
45
        fi
46
        # empty values are ignored
47
        if [ ! -z "$w" ]; then
48
            i="${i}-i${w} "
49
        fi
50
    done
51
 
52
    # Ensure at least 1 input
53
    if [ "${i}" = "" ]; then
54
        requestComp="${requestComp} -i\" \""
55
    else
56
        requestComp="${requestComp} ${i}"
57
    fi
58
 
59
    # Use eval to handle any environment variables and such
60
    out=$(eval ${requestComp} 2>/dev/null)
61
 
62
    while IFS='\n' read -r comp; do
63
        if [ -n "$comp" ]; then
64
            # If requested, completions are returned with a description.
65
            # The description is preceded by a TAB character.
66
            # For zsh's _describe, we need to use a : instead of a TAB.
67
            # We first need to escape any : as part of the completion itself.
68
            comp=${comp//:/\\:}
69
            local tab=$(printf '\t')
70
            comp=${comp//$tab/:}
71
            completions+=${comp}
72
        fi
73
    done < <(printf "%s\n" "${out[@]}")
74
 
75
    # Let inbuilt _describe handle completions
76
    eval _describe "completions" completions $flagPrefix
77
    return $?
78
}
79
 
80
compdef _sf_{{ COMMAND_NAME }} {{ COMMAND_NAME }}