1
0
Fork 0
mirror of synced 2024-11-22 23:35:35 -05:00

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.
This commit is contained in:
Eric Nielsen 2024-05-30 09:15:05 -05:00
parent 4fcc85b2db
commit cdd9258d5c
No known key found for this signature in database
GPG key ID: 678AF5E338C87D99
6 changed files with 54 additions and 52 deletions

View file

@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [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 ## [1.13.1] - 2024-04-28
@ -19,7 +22,7 @@ _No unreleased changes._
### Added ### Added
- `--if-command` option to zmodule. This option is equivalent to - `--if-command` option to `zmodule`. This option is equivalent to
`--if "(( \${+commands[${1}]} ))"`. `--if "(( \${+commands[${1}]} ))"`.
- `mkdir` tool option in `zmodule` that creates an empty directory. This allows - `mkdir` tool option in `zmodule` that creates an empty directory. This allows
creating modules that contain only externally generated files. creating modules that contain only externally generated files.

View file

@ -6,7 +6,6 @@ _zimfw_build_init() {
fi fi
_zimfw_mv =( _zimfw_mv =(
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
local zroot_dir zpre local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})

View file

@ -1,20 +1,25 @@
_zimfw_source_zimrc() { _zimfw_source_zimrc() {
local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1} <%= render_all("src/functions/*.erb") %>
local -i _zfailed=0 {
if ! source ${ztarget} || (( _zfailed )); then local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1}
print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>' local -i _zfailed=0
return 1 if ! source ${ztarget} || (( _zfailed )); then
fi print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>'
if (( _zflags & 1 && ${#_znames} == 0 )); then return 1
print -u2 -R $'<%= red %>No modules defined in <%= bold %>'${ztarget}$'<%= normal %>' fi
return 1 if (( _zflags & 1 && ${#_znames} == 0 )); then
fi print -u2 -R $'<%= red %>No modules defined in <%= bold %>'${ztarget}$'<%= normal %>'
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes return 1
local zroot_dir zpre fi
for zroot_dir in ${_zdisabled_root_dirs}; do # Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
zpre=${zroot_dir}$'\0' local zroot_dir zpre
_zfpaths=(${_zfpaths:#${zpre}*}) for zroot_dir in ${_zdisabled_root_dirs}; do
_zfunctions=(${_zfunctions:#${zpre}*}) zpre=${zroot_dir}$'\0'
_zcmds=(${_zcmds:#${zpre}*}) _zfpaths=(${_zfpaths:#${zpre}*})
done _zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*})
done
} always {
unfunction zmodule
}
} }

View file

@ -42,8 +42,4 @@ zim = Zim.new
<%= zim.render_commented("LICENSE") %> <%= zim.render_commented("LICENSE") %>
<%= zim.render_all("src/stage2/*.erb") %> <%= zim.render_all("src/stage2/*.erb") %>
if [[ ${functrace[1]} == zmodule:* ]]; then zimfw "${@}"
zmodule "${@}"
else
zimfw "${@}"
fi

View file

@ -58,7 +58,6 @@ _zimfw_build_init() {
fi fi
_zimfw_mv =( _zimfw_mv =(
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
local zroot_dir zpre local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) 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_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
} }
_zimfw_source_zimrc() {
zmodule() { zmodule() {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc}
local -r zusage=$'Usage: \E[1m'${0}$'\E[0m <url> [\E[1m-n\E[0m|\E[1m--name\E[0m <module_name>] [\E[1m-r\E[0m|\E[1m--root\E[0m <path>] [options] local -r zusage=$'Usage: \E[1m'${0}$'\E[0m <url> [\E[1m-n\E[0m|\E[1m--name\E[0m <module_name>] [\E[1m-r\E[0m|\E[1m--root\E[0m <path>] [options]
@ -351,25 +351,28 @@ Per-call initialization options:
fi fi
} }
_zimfw_source_zimrc() { {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1} local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1}
local -i _zfailed=0 local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then if ! source ${ztarget} || (( _zfailed )); then
print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m' print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m'
return 1 return 1
fi fi
if (( _zflags & 1 && ${#_znames} == 0 )); then if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m' print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m'
return 1 return 1
fi fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes # Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre local zroot_dir zpre
for zroot_dir in ${_zdisabled_root_dirs}; do for zroot_dir in ${_zdisabled_root_dirs}; do
zpre=${zroot_dir}$'\0' zpre=${zroot_dir}$'\0'
_zfpaths=(${_zfpaths:#${zpre}*}) _zfpaths=(${_zfpaths:#${zpre}*})
_zfunctions=(${_zfunctions:#${zpre}*}) _zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*}) _zcmds=(${_zcmds:#${zpre}*})
done done
} always {
unfunction zmodule
}
} }
_zimfw_list_unuseds() { _zimfw_list_unuseds() {
@ -454,7 +457,7 @@ _zimfw_compile() {
} }
_zimfw_info() { _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 local zparam
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do 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} print -R ${(r.22....:.)zparam}${(P)zparam}
@ -985,8 +988,4 @@ Options:
esac esac
} }
if [[ ${functrace[1]} == zmodule:* ]]; then zimfw "${@}"
zmodule "${@}"
else
zimfw "${@}"
fi