1
0
Fork 0

modules: added precompile-a zrecompile like func

a litte helper/module to (re)compile zsh functions/scripts found in fpath
to speed loading and execution (p-as-personal-recompile).
pull/679/head
tokiclover 10 years ago
parent fbb9924600
commit ffd4a3cf57

@ -0,0 +1,33 @@
Precompile - prezto zrecompile
======
This module compile all the parrent directories found in $fpath if writable.
Or else, a '-s|--system-fpath' switch is available for priviledged users to
(re)compile system wide functions/scripts to improve loading and execution.
Settings
--------
This module support a single setting at the moment, a string that hold
*precompile* command line options.
zstyle ':prezto:module:precompile' options '-f -s'
'-f|--fpath-append' enable appending/replacing *element* parent directory with
*element.zwc* to get another loading/execution speed improvement.
zrecompile extra options (like *-M* option handy for scripts compilation) can be
appended to that string as well.
Runtime (re)compilation
-------
Of course, *precompile* function is available at runtime, so it is available to
inspect and reompile directory if necessary. Unchanged directory will not be
recompiled. Just expect a little delay the first time the module is enabled.
Authors
-------
- [tokiclover](https://github.com/tokiclover)

@ -0,0 +1,64 @@
#
# recompile zsh functions/scripts found in $fpath
#
# $Header: precompile/functions/precompile Exp $
# $Aythor: (c) 2014 -tclover <tokiclover@gmail.com> Exp $
# $License: MIT (or 2-clause/new/simplified BSD) Exp $
# $Version: 0.2 2014/09/25 11:09:26 Exp $
#
function usage {
cat <<-EOH
usage: precompile [options]
-f, --fpath-append replace/append compiled file
-s, --system-fpath compile sytem wide fpath(s)
-h, --help print this help message
EOH
return
}
setopt LOCAL_OPTIONS EXTENDED_GLOB NULL_GLOB
for (( ; $# > 0; ))
case $1 {
(-f|--fpath-append)
local fpath_append=true
shift;;
(-s|--system-fpath)
local system_fpath=true
shift;;
(-h|--help)
usage
return;;
(*)
break;;
}
(( $+functions[zrecompile] )) || autoload -Uz zrecompile || return
for (( i=1; i <= $#fpath; ++i )) {
local dir=$fpath[i]
local zwc=${dir:t}.zwc
[[ $dir == (.|..) || $dir == (.|..)/* ]] && continue
if [[ ${dir#$HOME} == $dir ]] {
if (( ! $+system_fpath )) {
if (( $+fpath_append )) && [[ -e $fpath[i].zwc ]] {
zrecompile -q -t $fpath[i].zwc || fpath[i]=$fpath[i].zwc
}
continue
}
}
[[ -w $dir:h ]] && pushd -q $dir:h || continue
typeset -a files
files=(${zwc%.zwc}/^([.]*|README*)*(N-.))
[[ -n $files ]] && zrecompile -p -U -z $=argv $zwc $files &&
(( $+fpath_append )) && fpath[i]=$fpath[i].zwc
popd -q
}
#
# vim:fenc=utf-8:ft=zsh:ci:pi:sts=2:sw=2:ts=2:
#

@ -0,0 +1,19 @@
#
# p-as-prezto-recompile-as-zreompile module to re-compile
# functions/scripts on the fly to loading and execution
#
# $Header: precompile/init.zsh Exp $
# $Aythor: (c) 2014 -tclover <tokiclover@gmail.com> Exp $
# $License: MIT (or 2-clause/new/simplified BSD) Exp $
# $Version: 0.1 2014/09/24 21:09:26 Exp $
#
zstyle -a ':prezto:module:precompile' options 'args'
(( $+functions[precompile] )) || autoload -Uz precompile && precompile $args[@]
unset args
#
# vim:fenc=utf-8:ft=zsh:ci:pi:sts=2:sw=2:ts=2:
#
Loading…
Cancel
Save