File: load.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 (241 lines) | stat: -rw-r--r-- 6,201 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
__zplug::core::load::prepare()
{
    setopt nomonitor
    zstyle ':zplug:core:load' 'verbose' no

    __zplug::io::file::rm_touch "$_zplug_load_log[success]"
    __zplug::io::file::rm_touch "$_zplug_load_log[failure]"
}

__zplug::core::load::from_cache()
{
    local is_verbose
    zstyle -s ':zplug:core:load' 'verbose' is_verbose

    # Default
    # setopt monitor

    __zplug::core::cache::update

    # Load the cache in order
    {
        fpath=(
        ${(@f)"$(<$_zplug_cache[fpath])"}
        "$fpath[@]"
        )

        source "$_zplug_cache[plugin]"
        source "$_zplug_cache[lazy_plugin]"
        source "$_zplug_cache[theme]"
        source "$_zplug_cache[command]"

        # Plugins with defer-level set
        source "$_zplug_cache[defer_1_plugin]"
        compinit -d "$ZPLUG_HOME/zcompdump"
        if (( $_zplug_boolean_true[(I)$is_verbose] )); then
            __zplug::io::print::f \
                --zplug "$fg[yellow]Run compinit$reset_color\n"
        fi
        source "$_zplug_cache[defer_2_plugin]"
        source "$_zplug_cache[defer_3_plugin]"
    }

    if [[ -s $_zplug_load_log[failure] ]]; then
        # If there are repos that failed to load,
        # show those repos and return false
        __zplug::io::print::f \
            --zplug \
            "These repos have failed to load:\n$fg_bold[red]"
        print -l -- "- $fg[red]"${^${(u@f)"$(<"$_zplug_load_log[failure]")":gs:@:}}"$reset_color"
        __zplug::io::print::f "$reset_color"
        return 1
    fi
}

__zplug::core::load::as_plugin()
{
    local    key value repo load_path hook is_lazy=false
    local    is_verbose msg
    local -i status_code=0
    zstyle -s ':zplug:core:load' 'verbose' is_verbose

    while (( $#argv > 0 ))
    do
        case "$argv[1]" in
            --repo)
                repo="$argv[2]"
                shift
                ;;
            --hook)
                hook="$argv[2]"
                shift
                ;;
            --lazy)
                is_lazy=true
                ;;
            *)
                load_path="$argv[1]"
                ;;
        esac
        shift
    done

    # Special measure
    if [[ $repo == 'zplug/zplug' ]]; then
        # In the case of zplug, don't load it exceptionally
        return 0
    fi

    if [[ $load_path =~ $_ZPLUG_OHMYZSH ]]; then
        # Check if omz is loaded and set some necessary settings
        if [[ -z $ZSH ]]; then
            export ZSH="$ZPLUG_REPOS/$_ZPLUG_OHMYZSH"
            export ZSH_CACHE_DIR="$ZSH/cache/"
        fi
    fi

    if $is_lazy; then
        msg="Lazy"
        autoload -Uz "${load_path:t}"
        status_code=$status
    else
        msg="Load"
        source "$load_path" 2> >(__zplug::log::capture::error)
        status_code=$status
    fi

    if (( $_zplug_boolean_true[(I)$is_verbose] )); then
        if (( $status_code == 0 )); then
            __zplug::io::print::f " $msg ${(qqq)load_path/$HOME/~} ($repo)\n"
        else
            __zplug::io::print::f --warn " Failed to load ${(qqq)load_path/$HOME/~} ($repo)\n"
        fi
    fi

    if (( $status_code == 0 )); then
        if [[ -n $hook ]]; then
            eval ${=hook}
        fi
        __zplug::job::handle::flock "$_zplug_load_log[success]" "$repo"
    else
        __zplug::job::handle::flock "$_zplug_load_log[failure]" "$repo"
    fi

    return $status_code
}

__zplug::core::load::as_command()
{
    local    key value repo load_path _path hook
    local    is_verbose
    local -i status_code=0
    zstyle -s ':zplug:core:load' 'verbose' is_verbose

    while (( $#argv > 0 ))
    do
        case "$argv[1]" in
            --repo)
                repo="$argv[2]"
                shift
                ;;
            --hook)
                hook="$argv[2]"
                shift
                ;;
            --path)
                _path="$argv[2]"
                shift
                ;;
            *)
                load_path="$argv[1]"
                ;;
        esac
        shift
    done

    {
        chmod 755 "$load_path"
        ln -snf "$load_path" "$_path"
    } &>/dev/null
    status_code=$status

    if (( $_zplug_boolean_true[(I)$is_verbose] )); then
        if (( $status_code == 0 )); then
            __zplug::io::print::f " Link ${(qqq)load_path/$HOME/~} ($repo)\n"
        else
            __zplug::io::print::f --warn " Failed to link ${(qqq)load_path/$HOME/~} ($repo)\n"
        fi
    fi

    if (( $status_code == 0 )); then
        if [[ -n $hook ]]; then
            eval ${=hook}
        fi
        __zplug::job::handle::flock "$_zplug_load_log[success]" "$repo"
    else
        __zplug::job::handle::flock "$_zplug_load_log[failure]" "$repo"
    fi

    return $status_code
}

__zplug::core::load::as_theme()
{
    local -i ret=0

    __zplug::core::load::as_plugin "$argv[@]"
    ret=$status

    if [[ ! -o prompt_subst ]]; then
        setopt prompt_subst
    fi

    return $ret
}

__zplug::core::load::skip_condition()
{
    # Returns true if there are conditions to skip,
    # returns false otherwise

    local    repo="${1:?}" is_verbose
    local -A tags

    zstyle -s ':zplug:core:load' 'verbose' is_verbose

    __zplug::core::tags::parse "$repo"
    tags=( "${reply[@]}" )

    if __zplug::core::sources::is_handler_defined check "$tags[from]"; then
        if ! __zplug::core::sources::use_handler check "$tags[from]" "$repo"; then
            return 0
        fi
    else
        if [[ ! -d $tags[dir] ]]; then
            return 0
        fi
    fi

    if [[ -n $tags[if] ]]; then
        if ! eval "$tags[if]" 2> >(__zplug::log::capture::error) >/dev/null; then
            if (( $_zplug_boolean_true[(I)$is_verbose] )); then
                __zplug::io::print::die "$tags[name]: (not loaded)\n"
            fi
            return 0
        fi
    fi

    if [[ -n $tags[on] ]]; then
        __zplug::core::core::run_interfaces \
            'check' \
            ${~tags[on]}
        if (( $status != 0 )); then
            if (( $_zplug_boolean_true[(I)$is_verbose] )); then
                __zplug::io::print::die "$tags[name]: (not loaded)\n"
            fi
            return 0
        fi
    fi

    return 1
}