Skip to content

Commit

Permalink
Compile files when zgen save is called
Browse files Browse the repository at this point in the history
It compiles *.zsh, *.sh and zcomdump*, as well as all files with zsh
shebang (`#!...zsh`).
In these paths:
- zgen source files
- plugin files
- zcompdump (if custom path or ~/.zcompdump*)

This also adds `zgen compile <path>` to the api.

Closes tarjoilija/zgen#92
  • Loading branch information
jandamm committed Sep 21, 2020
1 parent 234514a commit 863fad0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions _zgen
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
local -a _zgen_commands
_zgen_commands=(
"clone:clone plugin from repository"
"compile:compile files the given path"
"completions:deprecated, please use load instead"
"list:print init.zsh"
"load:clone and load plugin"
Expand Down
55 changes: 54 additions & 1 deletion zgen.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,23 @@ zgen-save() {
-zginit "# }}}"

zgen-apply

-zgpute "Compiling files ..."
zgen-compile $ZGEN_DIR
if [[ $ZGEN_DIR != $ZGEN_SOURCE ]]; then
zgen-compile $ZGEN_SOURCE
fi
if [[ -n $ZGEN_CUSTOM_COMPDUMP ]]; then
-zgen-compile $ZGEN_CUSTOM_COMPDUMP
else
set -o nullglob
for compdump in $HOME/.zcompdump*; do
if [ $compdump = *.zwc ]; then
continue
fi
-zgen-compile $compdump
done
fi
}

zgen-apply() {
Expand All @@ -311,6 +328,42 @@ zgen-apply() {
-zgputs "$(-zgen-get-clone-dir "$ZGEN_OH_MY_ZSH_REPO" "$ZGEN_OH_MY_ZSH_BRANCH")"
}

-zgen-compile() {
local file=$1
[ ! $file.zwc -nt $file ] && zcompile $file
}

zgen-compile() {
local inp=$1
if [ -z $inp ]; then
-zgpute '`compile` requires one parameter:'
-zgpute '`zgen compile <location>`'
elif [ -f $inp ]; then
-zgen-compile $inp
else
set -o nullglob
for file in $inp/**/*
do
# only files and ignore compiled files
if [ ! -f $file ] || [[ $file = *.zwc ]]; then
continue

# Check for shebang if not:
# - *.zsh
# - *.sh
# - zcompdump*
elif [[ $file != *.zsh ]] && [[ $file != *.sh ]] && [[ $file != *zcompdump* ]]; then
read -r firstline < $file
if [[ ! $firstline =~ '^#!.*zsh' ]] 2>/dev/null; then
continue
fi
fi

-zgen-compile $file
done
fi
}

zgen-load() {
if [[ "$#" == 0 ]]; then
-zgpute '`load` requires at least one parameter:'
Expand Down Expand Up @@ -465,7 +518,7 @@ zgen() {
local cmd="${1}"
if [[ -z "${cmd}" ]]; then
-zgputs 'usage: `zgen [command | instruction] [options]`'
-zgputs " commands: list, saved, reset, clone, update, selfupdate"
-zgputs " commands: list, saved, reset, clone, update, selfupdate, compile"
-zgputs " instructions: load, oh-my-zsh, pmodule, prezto, save, apply"
return 1
fi
Expand Down

0 comments on commit 863fad0

Please sign in to comment.