|
5 | 5 | # usage: antidote load [-h|--help] [<bundlefile> [<staticfile>]] |
6 | 6 | # |
7 | 7 | #function antidote-load { |
8 | | - setopt extended_glob |
9 | | - |
10 | | - local o_help |
11 | | - zparseopts $_adote_zparopt_flags -- h=o_help -help=h || return 1 |
12 | | - |
13 | | - if (( $#o_help )); then |
| 8 | + if [[ "$1" == (-h|--help) ]]; then |
14 | 9 | antidote-help load |
15 | 10 | return |
16 | 11 | fi |
17 | 12 |
|
18 | | - # pass in bundle file, read from zstyle, or use default .zsh_plugins.txt |
19 | | - local bundlefile="$1" |
20 | | - if [[ -z "$bundlefile" ]]; then |
21 | | - zstyle -s ':antidote:bundle' file 'bundlefile' || |
22 | | - bundlefile=${ZDOTDIR:-$HOME}/.zsh_plugins.txt |
23 | | - fi |
24 | | - |
25 | | - # pass in static file, read from zstyle, change extension, or use default .zsh_plugins.zsh |
26 | | - local staticfile="$2" |
27 | | - if [[ -z "$staticfile" ]]; then |
28 | | - zstyle -s ':antidote:static' file 'staticfile' |
29 | | - if [[ -z "$staticfile" ]]; then |
30 | | - if [[ -z "$bundlefile:t:r" ]]; then |
31 | | - staticfile=${bundlefile}.zsh |
32 | | - else |
33 | | - staticfile=${bundlefile:r}.zsh |
34 | | - fi |
35 | | - fi |
36 | | - fi |
37 | | - |
38 | | - if [[ ! -e "$bundlefile" ]]; then |
39 | | - # the files can't have the same name |
40 | | - print -ru2 -- "antidote: bundle file not found '$bundlefile'." |
41 | | - return 1 |
42 | | - elif [[ "$bundlefile" == "$staticfile" ]]; then |
43 | | - # the files can't have the same name |
44 | | - print -ru2 -- "antidote: bundle file and static file are the same '$bundlefile'." |
45 | | - return 1 |
46 | | - fi |
47 | | - |
48 | | - # regenerate the static file based on whether the bundle file is newer and whether |
49 | | - # antidote home exists and is ready to be loaded |
50 | | - local force_bundle=0 |
51 | | - if ! zstyle -t ':antidote:load:checkfile' disabled; then |
52 | | - local loadable_check_path="$(antidote-home)/.antidote.load" |
53 | | - if [[ ! -e $loadable_check_path ]]; then |
54 | | - force_bundle=1 |
55 | | - [[ -d $loadable_check_path:h ]] || mkdir -p $loadable_check_path:h |
56 | | - touch $loadable_check_path |
57 | | - fi |
58 | | - fi |
59 | | - |
60 | | - if [[ ! $staticfile -nt $bundlefile ]] || [[ $force_bundle -eq 1 ]]; then |
61 | | - antidote bundle <"$bundlefile" >|"$staticfile" |
62 | | - if [[ -r "${staticfile}.zwc" ]] && zstyle -T ':antidote:static' zcompile; then |
63 | | - command rm -f -- "${staticfile}.zwc" |
64 | | - fi |
65 | | - fi |
66 | | - source "$staticfile" |
| 13 | + # We can't use LOCAL_OPTIONS because sourcing plugins means we'd lose any Zsh options |
| 14 | + # set in those plugins, so we delegate all the work to __antidote_load_prep where |
| 15 | + # we can safely use LOCAL_OPTIONS. For this function, we should do the bare minimum |
| 16 | + # so the user can set whatever crazy Zsh options they want, and antidote doesn't need |
| 17 | + # to concern itself with that. |
| 18 | + # |
| 19 | + # "Is your house on fire, Clark? No, Aunt Bethany, those are the user's Zsh options." |
| 20 | + # |
| 21 | + typeset -g REPLY= |
| 22 | + __antidote_load_prep "$@" || return 1 |
| 23 | + [[ -f "$REPLY" ]] || return 2 |
| 24 | + source "$REPLY" |
| 25 | + unset REPLY |
67 | 26 | #} |
0 commit comments