diff --git a/CHANGELOG.md b/CHANGELOG.md index da8c6d7..b535a3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -_No unreleased changes._ +### Fixed +- Prefer the prezto module format when using defaults to initialize a module. + This is the format we use in our Zim framework modules. It's is not well + documented anywhere officially, but in short words a prezto module has: + * a `functions` subdirectory that is added to the fpath by the framework, + * files inside the `functions` subdirectory that are autoloaded by the + framework (except for file names that match `_*` or `prompt_*_setup`), + * an `init.zsh` file that is sourced by the framework. ## [1.4.2] - 2021-02-19 diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 29dced0..c793a51 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -132,15 +132,24 @@ Initialization options: _zfailed=1 return 1 fi - if (( ! ${#zfpaths} )) zfpaths+=(${zdir}/functions(NF)) + local -ra prezto_fpaths=(${zdir}/functions(NF)) + local -ra prezto_scripts=(${zdir}/init.zsh(N)) + if (( ! ${#zfpaths} && ! ${#zcmds} && ${#prezto_fpaths} && ${#prezto_scripts} )); then + # this follows the prezto module format, no need to check for other scripts + zfpaths=(${prezto_fpaths}) + zcmds=("source ${^prezto_scripts[@]:A}") + else + if (( ! ${#zfpaths} )) zfpaths=(${prezto_fpaths}) + if (( ! ${#zcmds} )); then + # get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) + local -r zscript=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) + zcmds=("source ${^zscript[@]:A}") + fi + fi if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit # prompt_*_setup functions are autoloaded by promptinit - zfunctions+=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t)) - fi - if (( ! ${#zcmds} )); then - local -r zscript=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) - zcmds+=("source ${^zscript[@]:A}") + zfunctions=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t)) fi if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then print -u2 -PR "%F{yellow}<%= warn %>${funcfiletrace[1]}:%B${zmodule}:%b Nothing found to be initialized. Customize the module name or initialization with %Bzmodule%b options.%f"$'\n\n'${zusage} diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index fa65f0d..8c24f1b 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -6,7 +6,7 @@ class Zim @home = "${ZDOTDIR:-${HOME}}" @min_zsh_version = "5.2" @startup_files_glob = ".z(shenv|profile|shrc|login|logout)" - @version = "1.4.2" + @version = "1.4.3-SNAPSHOT" @ellipsis = " ..." @okay = "%F{green})%f " @warn = "! " diff --git a/zimfw.zsh b/zimfw.zsh index e68b606..f753ef3 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -239,15 +239,24 @@ Initialization options: _zfailed=1 return 1 fi - if (( ! ${#zfpaths} )) zfpaths+=(${zdir}/functions(NF)) + local -ra prezto_fpaths=(${zdir}/functions(NF)) + local -ra prezto_scripts=(${zdir}/init.zsh(N)) + if (( ! ${#zfpaths} && ! ${#zcmds} && ${#prezto_fpaths} && ${#prezto_scripts} )); then + # this follows the prezto module format, no need to check for other scripts + zfpaths=(${prezto_fpaths}) + zcmds=("source ${^prezto_scripts[@]:A}") + else + if (( ! ${#zfpaths} )) zfpaths=(${prezto_fpaths}) + if (( ! ${#zcmds} )); then + # get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) + local -r zscript=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) + zcmds=("source ${^zscript[@]:A}") + fi + fi if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit # prompt_*_setup functions are autoloaded by promptinit - zfunctions+=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t)) - fi - if (( ! ${#zcmds} )); then - local -r zscript=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) - zcmds+=("source ${^zscript[@]:A}") + zfunctions=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t)) fi if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then print -u2 -PR "%F{yellow}! ${funcfiletrace[1]}:%B${zmodule}:%b Nothing found to be initialized. Customize the module name or initialization with %Bzmodule%b options.%f"$'\n\n'${zusage} @@ -319,7 +328,7 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (built at 2021-02-19 20:25:37 UTC, previous commit is 8afb0b9)' + print -R 'zimfw version: '${_zversion}' (built at 2021-03-16 22:02:26 UTC, previous commit is 1df02c5)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -366,7 +375,7 @@ _zimfw_upgrade() { } zimfw() { - local -r _zversion='1.4.2' + local -r _zversion='1.4.3-SNAPSHOT' local -r zusage="Usage: %B${0}%b [%B-q%b|%B-v%b] Actions: