From cdd9258d5c08cdc77ba61a2ddf7ac4e0211852cc Mon Sep 17 00:00:00 2001 From: Eric Nielsen <4120606+ericbn@users.noreply.github.com> Date: Thu, 30 May 2024 09:15:05 -0500 Subject: [PATCH] Don't expose the zmodule function outside zimfw Don't want to maintain extra code to allow zmodule to run outside zimfw. This has no added benefit and might confuse users. If you were calling zmodule in the shell just to get the help message, hopefully you can look that up in the documentation instead. --- CHANGELOG.md | 7 ++- src/{stage2 => functions}/30_zmodule.zsh.erb | 0 src/stage2/29_zimfw_build_init.zsh.erb | 1 - src/stage2/31_zimfw_source_zimrc.zsh.erb | 41 +++++++++------- src/zimfw.zsh.erb | 6 +-- zimfw.zsh | 51 ++++++++++---------- 6 files changed, 54 insertions(+), 52 deletions(-) rename src/{stage2 => functions}/30_zmodule.zsh.erb (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e639c2..1d65003 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -_No unreleased changes._ +### Changed + +- Don't allow calling `zmodule` from the command line. Let it fail with "command + not found" instead. It's inteded to be used only in the .zimrc script. ## [1.13.1] - 2024-04-28 @@ -19,7 +22,7 @@ _No unreleased changes._ ### Added -- `--if-command` option to zmodule. This option is equivalent to +- `--if-command` option to `zmodule`. This option is equivalent to `--if "(( \${+commands[${1}]} ))"`. - `mkdir` tool option in `zmodule` that creates an empty directory. This allows creating modules that contain only externally generated files. diff --git a/src/stage2/30_zmodule.zsh.erb b/src/functions/30_zmodule.zsh.erb similarity index 100% rename from src/stage2/30_zmodule.zsh.erb rename to src/functions/30_zmodule.zsh.erb diff --git a/src/stage2/29_zimfw_build_init.zsh.erb b/src/stage2/29_zimfw_build_init.zsh.erb index f515717..ce1ef28 100644 --- a/src/stage2/29_zimfw_build_init.zsh.erb +++ b/src/stage2/29_zimfw_build_init.zsh.erb @@ -6,7 +6,6 @@ _zimfw_build_init() { fi _zimfw_mv =( print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" - print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" local zroot_dir zpre local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) diff --git a/src/stage2/31_zimfw_source_zimrc.zsh.erb b/src/stage2/31_zimfw_source_zimrc.zsh.erb index 3d11b61..e22b49d 100644 --- a/src/stage2/31_zimfw_source_zimrc.zsh.erb +++ b/src/stage2/31_zimfw_source_zimrc.zsh.erb @@ -1,20 +1,25 @@ _zimfw_source_zimrc() { - local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1} - local -i _zfailed=0 - if ! source ${ztarget} || (( _zfailed )); then - print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>' - return 1 - fi - if (( _zflags & 1 && ${#_znames} == 0 )); then - print -u2 -R $'<%= red %>No modules defined in <%= bold %>'${ztarget}$'<%= normal %>' - return 1 - fi - # Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes - local zroot_dir zpre - for zroot_dir in ${_zdisabled_root_dirs}; do - zpre=${zroot_dir}$'\0' - _zfpaths=(${_zfpaths:#${zpre}*}) - _zfunctions=(${_zfunctions:#${zpre}*}) - _zcmds=(${_zcmds:#${zpre}*}) - done +<%= render_all("src/functions/*.erb") %> + { + local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1} + local -i _zfailed=0 + if ! source ${ztarget} || (( _zfailed )); then + print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>' + return 1 + fi + if (( _zflags & 1 && ${#_znames} == 0 )); then + print -u2 -R $'<%= red %>No modules defined in <%= bold %>'${ztarget}$'<%= normal %>' + return 1 + fi + # Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes + local zroot_dir zpre + for zroot_dir in ${_zdisabled_root_dirs}; do + zpre=${zroot_dir}$'\0' + _zfpaths=(${_zfpaths:#${zpre}*}) + _zfunctions=(${_zfunctions:#${zpre}*}) + _zcmds=(${_zcmds:#${zpre}*}) + done + } always { + unfunction zmodule + } } diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index 6f5a974..9ca9633 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -42,8 +42,4 @@ zim = Zim.new <%= zim.render_commented("LICENSE") %> <%= zim.render_all("src/stage2/*.erb") %> -if [[ ${functrace[1]} == zmodule:* ]]; then - zmodule "${@}" -else - zimfw "${@}" -fi +zimfw "${@}" diff --git a/zimfw.zsh b/zimfw.zsh index 9918fc4..0600077 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -58,7 +58,6 @@ _zimfw_build_init() { fi _zimfw_mv =( print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" - print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" local zroot_dir zpre local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) @@ -110,6 +109,7 @@ _zimfw_build() { _zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.' } +_zimfw_source_zimrc() { zmodule() { local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} local -r zusage=$'Usage: \E[1m'${0}$'\E[0m [\E[1m-n\E[0m|\E[1m--name\E[0m ] [\E[1m-r\E[0m|\E[1m--root\E[0m ] [options] @@ -351,25 +351,28 @@ Per-call initialization options: fi } -_zimfw_source_zimrc() { - local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1} - local -i _zfailed=0 - if ! source ${ztarget} || (( _zfailed )); then - print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m' - return 1 - fi - if (( _zflags & 1 && ${#_znames} == 0 )); then - print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m' - return 1 - fi - # Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes - local zroot_dir zpre - for zroot_dir in ${_zdisabled_root_dirs}; do - zpre=${zroot_dir}$'\0' - _zfpaths=(${_zfpaths:#${zpre}*}) - _zfunctions=(${_zfunctions:#${zpre}*}) - _zcmds=(${_zcmds:#${zpre}*}) - done + { + local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1} + local -i _zfailed=0 + if ! source ${ztarget} || (( _zfailed )); then + print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m' + return 1 + fi + if (( _zflags & 1 && ${#_znames} == 0 )); then + print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m' + return 1 + fi + # Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes + local zroot_dir zpre + for zroot_dir in ${_zdisabled_root_dirs}; do + zpre=${zroot_dir}$'\0' + _zfpaths=(${_zfpaths:#${zpre}*}) + _zfunctions=(${_zfunctions:#${zpre}*}) + _zcmds=(${_zcmds:#${zpre}*}) + done + } always { + unfunction zmodule + } } _zimfw_list_unuseds() { @@ -454,7 +457,7 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (built at 2024-04-28 19:07:19 UTC, previous commit is c86223f)' + print -R 'zimfw version: '${_zversion}' (built at 2024-05-30 14:18:19 UTC, previous commit is 6c4e1b0)' local zparam for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do print -R ${(r.22....:.)zparam}${(P)zparam} @@ -985,8 +988,4 @@ Options: esac } -if [[ ${functrace[1]} == zmodule:* ]]; then - zmodule "${@}" -else - zimfw "${@}" -fi +zimfw "${@}"