From ffd4a3cf57c154f71efb1f72d142e28a47569465 Mon Sep 17 00:00:00 2001 From: tokiclover Date: Thu, 25 Sep 2014 20:48:58 +0200 Subject: [PATCH] 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). --- modules/precompile/README.md | 33 +++++++++++++ modules/precompile/functions/precompile | 64 +++++++++++++++++++++++++ modules/precompile/init.zsh | 19 ++++++++ 3 files changed, 116 insertions(+) create mode 100644 modules/precompile/README.md create mode 100644 modules/precompile/functions/precompile create mode 100644 modules/precompile/init.zsh diff --git a/modules/precompile/README.md b/modules/precompile/README.md new file mode 100644 index 00000000..1f14783e --- /dev/null +++ b/modules/precompile/README.md @@ -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) + diff --git a/modules/precompile/functions/precompile b/modules/precompile/functions/precompile new file mode 100644 index 00000000..924f43c7 --- /dev/null +++ b/modules/precompile/functions/precompile @@ -0,0 +1,64 @@ +# +# recompile zsh functions/scripts found in $fpath +# +# $Header: precompile/functions/precompile Exp $ +# $Aythor: (c) 2014 -tclover 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: +# diff --git a/modules/precompile/init.zsh b/modules/precompile/init.zsh new file mode 100644 index 00000000..337ecdde --- /dev/null +++ b/modules/precompile/init.zsh @@ -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 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: +#