From 106335e1d8e1f1a78d309c0c55adc6ea295beb15 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 7 Dec 2019 21:17:40 -0500 Subject: [PATCH] Add zimfw init action for a quick build Having to manually do `zimfw build` every time after you edit your .zimrc file is boring. So by having the following in .zshrc before sourcing init.zsh will do a quick build automatically when needed: if [[ ~/.zim/init.zsh -ot ~/.zimrc ]]; then source ~/.zim/zimfw.zsh init -q fi --- README.md | 63 ++++++++++++++++--------------- src/stage2/30_zimfw_build.zsh.erb | 2 +- src/stage2/30_zmodule.zsh.erb | 5 +++ src/stage2/80_zimfw.zsh.erb | 1 + zimfw.zsh | 10 ++++- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 8aa885f..9223bc7 100644 --- a/README.md +++ b/README.md @@ -55,73 +55,76 @@ If you have a different shell framework installed (like oh-my-zsh or prezto), ### Manual installation -1. Set Zsh as the default shell: - - chsh -s =zsh - -2. Start a Zsh shell +1. Start a Zsh shell zsh +2. Set Zsh as the default shell: + + chsh -s =zsh + 3. Copy https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh to - `${ZDOTDIR:-${HOME}}/.zim/zimfw.zsh`. + `~/.zim/zimfw.zsh`. -4. Add the lines in the following templates to the respective dot files in the - `${ZDOTDIR:-${HOME}}` directory: - * [.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) - * [.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) - * [.zshrc](https://github.com/zimfw/install/blob/develop/src/templates/zshrc) +4. Add the lines in the following templates to the respective dot files: + * [~/.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) + * [~/.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) + * [~/.zshrc](https://github.com/zimfw/install/blob/develop/src/templates/zshrc) -5. Install the modules defined in `.zimrc` and build the static `init.zsh` script: +5. Install the modules defined in `~/.zimrc` and build the static initialization script: - source ${ZDOTDIR:-${HOME}}/.zim/zimfw.zsh install + source ~/.zim/zimfw.zsh install Usage ----- ### zmodule -Add `zmodule` calls to your `.zimrc` file to define the modules to be loaded. -The modules are loaded in the same order they are defined. Add: +Add `zmodule` calls to your `~/.zimrc` file to define the modules to be initialized. +The modules are initialized in the same order they are defined. Add: zmodule [-n|--name ] [options] -where <url> is the required repository URL or path. The following formats +where `` is the required repository URL or path. The following formats are equivalent: `name`, `zimfw/name`, `https://github.com/zimfw/name.git`. -By default, the module name is the last component in the <url>. Use the -`-n`|`--name` <module_name> option to set a custom module name. +By default, the module name is the last component in the ``. Use the +`-n|--name ` option to set a custom module name. #### Repository options -* `-b`|`--branch` <branch_name>: Use specified branch when installing and +* `-b|--branch `: Use specified branch when installing and updating the module. Overrides the tag option. Default: `master`. -* `-t`|`--tag` <tag_name>: Use specified tag when installing and updating the +* `-t|--tag `: Use specified tag when installing and updating the module. Overrides the branch option. -* `-z`|`--frozen`: Don't install or update the module. +* `-z|--frozen`: Don't install or update the module. -#### Startup options +#### Initialization options -* `-f`|`--fpath` <path>: Add specified path to `fpath`. The path is relative to +* `-f|--fpath `: Add specified path to `fpath`. The path is relative to the module root directory. Default: `functions`, if the subdirectory exists. -* `-a`|`--autoload` <function_name>: Autoload specified function. Default: all - valid names inside all the module specified `fpath` paths. -* `-s`|`--source` <file_path>: Source specified file. The file path is relative +* `-a|--autoload `: Autoload specified function. Default: all + valid names inside the module's specified `fpath` paths. +* `-s|--source `: Source specified file. The file path is relative to the module root directory. Default: the file with largest size matching `{init.zsh|module_name.{zsh|plugin.zsh|zsh-theme|sh}}`, if any exists. -* `-d`|`--disabled`: Don't use or clean the module. +* `-d|--disabled`: Don't use or clean the module. ### zimfw -To install new defined modules, run: +Added new modules to `~/.zimrc`? Run: zimfw install -To update your modules, run: +Removed modules from `~/.zimrc`? Run: + + zimfw clean-modules + +Want to update your modules to their latest revisions? Run: zimfw update -To upgrade Zim, run: +Want to upgrade `~/.zim/zimfw.zsh` to the latest version? zimfw upgrade diff --git a/src/stage2/30_zimfw_build.zsh.erb b/src/stage2/30_zimfw_build.zsh.erb index 0b93951..14f7dd2 100644 --- a/src/stage2/30_zimfw_build.zsh.erb +++ b/src/stage2/30_zimfw_build.zsh.erb @@ -1,7 +1,7 @@ _zimfw_build() { () { local -r ztarget=${ZIM_HOME}/init.zsh - if command cmp -s ${ztarget} ${1}; then + if [[ ${ztarget} -nt <%= home %>/.zimrc ]] && command cmp -s ${ztarget} ${1}; then if (( ! _zquiet )); then print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" fi diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 190786b..682519b 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -104,6 +104,11 @@ Startup options: if (( zdisabled )); then _zdisableds+=(${zmodule}) else + if [[ ! -d ${zdir} ]]; then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" + _zfailed=1 + return 1 + fi (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index e00bdde..9eec1cc 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -44,6 +44,7 @@ Options: case ${1} in build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_source_zimrc && \ _zimfw_clean_modules && \ diff --git a/zimfw.zsh b/zimfw.zsh index c16c9e2..ad701e8 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -49,7 +49,7 @@ fi _zimfw_build() { () { local -r ztarget=${ZIM_HOME}/init.zsh - if command cmp -s ${ztarget} ${1}; then + if [[ ${ztarget} -nt ${ZDOTDIR:-${HOME}}/.zimrc ]] && command cmp -s ${ztarget} ${1}; then if (( ! _zquiet )); then print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" fi @@ -179,6 +179,11 @@ Startup options: if (( zdisabled )); then _zdisableds+=(${zmodule}) else + if [[ ! -d ${zdir} ]]; then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" + _zfailed=1 + return 1 + fi (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit @@ -250,7 +255,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is bccb1fc)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is c330f61)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -409,6 +414,7 @@ fi case ${1} in build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_source_zimrc && \ _zimfw_clean_modules && \