1
0
Fork 0
mirror of synced 2024-11-13 19:48:58 -05:00
zimfw/init.zsh
Eric Nielsen be58a63041 Compile functions.zwc for each functions directory
instead of a big single `functions.zwc` file containing functions from
all the `functions` subdirectories.

Having a big single digest file did reduce the number of OS file
descriptors to 1, instead of:
* as many functions as are declared in enabled modules, what we had
  before commit 55df5a4
* as many enabled modules, as we have implemented in this commit

but it also raised bigger and still unsolved issues as #231, #232, and
#234.

This solution here better suits the functions autoloading mechanism in
zsh, as documented in
http://zsh.sourceforge.net/Doc/Release/Functions.html#index-autoloading-functions

Given `~/.zim/modules/foo/functions` is in the `fpath`, autoload looks
for functions in the following files, picking the **newest one** in this
order:
* `~/.zim/modules/foo/functions.zwc`, which should contain all
  functions in the directory named `functions`
* `~/.zim/modules/foo/functions/function.zwc`
* `~/.zim/modules/foo/functions/function`

A relevant change in this approach is also having individual entries
back in `fpath` for the `functions` subdirectory of each enabled module
(as was the case before commit 55df5a4). With this back, we don't need
to worry anymore about being absolutely sure that all functions are
zcompiled, thanks to the autoloading mechanism described above.

Fixes #231. Fixes #232. Closes #234.
2018-01-03 17:34:55 -05:00

81 lines
2.4 KiB
Bash
Executable file

#
# Zim initializition
#
autoload -Uz is-at-least
if ! is-at-least 5.2; then
print "ERROR: Zim didn't start. You're using zsh version ${ZSH_VERSION}, and versions < 5.2 are not supported. Update your zsh." >&2
return 1
fi
# Define zim location
(( ! ${+ZIM_HOME} )) && export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
# Source user configuration
[[ -s ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc
# Autoload module functions
() {
local mod_function
setopt LOCAL_OPTIONS EXTENDED_GLOB
# autoload searches fpath for function locations; add enabled module function paths
[[ -n ${zmodules} ]] && fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath})
for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*|*.zwc|*.zwc.old)(-.N:t); do
autoload -Uz ${mod_function}
done
}
# Initialize modules
() {
local zmodule
for zmodule (${zmodules}); do
if [[ -s ${ZIM_HOME}/modules/${zmodule}/init.zsh ]]; then
source ${ZIM_HOME}/modules/${zmodule}/init.zsh
elif [[ ! -d ${ZIM_HOME}/modules/${zmodule} ]]; then
print "No such module \"${zmodule}\"." >&2
fi
done
}
zmanage() {
local usage="zmanage [action]
Actions:
update Fetch and merge upstream zim commits if possible
info Print zim and system info
issue Create a template for reporting an issue
clean-cache Clean the zim cache
build-cache Rebuild the zim cache
remove *experimental* Remove zim as best we can
reset Reset zim to the latest commit
debug Invoke the trace-zim script which produces logs
help Print this usage message"
if (( ${#} != 1 )); then
print ${usage}
return 1
fi
case ${1} in
update) zsh ${ZIM_HOME}/tools/zim_update
;;
info) zsh ${ZIM_HOME}/tools/zim_info
;;
issue) zsh ${ZIM_HOME}/tools/zim_issue
;;
clean-cache) source ${ZIM_HOME}/tools/zim_clean_cache && print 'Cache cleaned'
;;
build-cache) source ${ZIM_HOME}/tools/zim_build_cache && print 'Cache rebuilt'
;;
remove) zsh ${ZIM_HOME}/tools/zim_remove
;;
reset) zsh ${ZIM_HOME}/tools/zim_reset
;;
debug) zsh ${ZIM_HOME}/modules/debug/functions/trace-zim
;;
*) print ${usage}; return 1
;;
esac
}