File: arguments.zsh

package info (click to toggle)
zplug 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,068 kB
  • sloc: sh: 1,504; awk: 235; makefile: 26
file content (98 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (4)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
__zplug::core::arguments::exec()
{
    local arg="$1"
    shift

    reply=()
    __zplug::core::commands::user_defined

    # User-defined command
    if [[ -n ${(M)reply[@]:#$arg} ]]; then
        eval "$commands[zplug-$arg]" "$argv[@]"
        return $status
    fi

    # User-defined function
    if (( $+functions[zplug-$arg] )); then
        zplug-$arg "$argv[@]"
        return $status
    fi

    # Fuzzy match
    if ! __zplug::core::arguments::auto_correct "$arg"; then
        return 1
    fi

    zplug "$reply[1]" "$argv[@]"
}

__zplug::core::arguments::auto_correct()
{
    local    arg="$1"
    local -i ret=0
    local -a cmds reply_cmds

    reply_cmds=()

    # Add user-defined commands
    __zplug::core::commands::user_defined
    reply_cmds+=( "${reply[@]}" )

    # Add zplug subcommands
    __zplug::core::commands::get --key
    reply_cmds+=( "${reply[@]}" )

    cmds=(
    ${(@f)"$(awk \
        -f "$_ZPLUG_AWKPATH/fuzzy.awk" \
        -v search_string="$arg" \
        <<<"${(F)reply_cmds:gs:_:}"
    )":-}
    )

    case $#cmds in
        0)
            __zplug::io::print::f \
                --die \
                --zplug \
                "$arg: no such command\n"
            ret=1
            ;;
        1)
            __zplug::io::print::f \
                --die \
                --zplug \
                --warn \
                "You called a zplug command named '%s', which does not exist.\n" \
                "Continuing under the assumption that you meant '%s'.\n" \
                -- \
                "$arg" \
                "$fg[green]$cmds[1]$reset_color"

            reply=( "$cmds[1]" )
            ;;
        *)
            __zplug::io::print::f \
                --die \
                --zplug \
                --warn \
                "'%s' is not a zplug command. see 'zplug --help'.\n" \
                "Did you mean one of these?\n" \
                -- \
                "$arg"
            __zplug::io::print::die \
                "$fg[yellow]\t- $reset_color%s\n" \
                "${cmds[@]}"

            ret=1
            ;;
    esac

    return $ret
}

__zplug::core::arguments::none()
{
    # TODO
    :
}