Clean up and simplify code

No need to set zscriptglob in _zimfw_build_login_init anymore.
Use _zimfw_print in _zimfw_compile.
And other minor simplifications.
This commit is contained in:
Eric Nielsen 2022-01-10 20:41:50 -05:00
parent cfc955c9fd
commit 2491856a7b
No known key found for this signature in database
GPG Key ID: 47D1DBFA0765A1FB
6 changed files with 16 additions and 26 deletions

View File

@ -81,19 +81,19 @@ initialized, then run `zimfw install` to install them.
Below are some usage examples:
* A module from the [zimfw] organization: `zmodule archive`
* A module from the [@zimfw] organization: `zmodule archive`
* A module from another GitHub organization: `zmodule StackExchange/blackbox`
* A module with a custom URL: `zmodule https://gitlab.com/Spriithy/basher.git`
* A module at an absolute path, that is already installed:
`zmodule /usr/local/share/zsh-autosuggestions`
* A module with a custom fpath: `zmodule zsh-users/zsh-completions --fpath src`
* A module with a custom initialization file name:
* A module with a custom initialization file:
`zmodule spaceship-prompt/spaceship-prompt --source spaceship.zsh` or
`zmodule spaceship-prompt/spaceship-prompt --name spaceship`
* A module with two custom initialization files:
`zmodule sindresorhus/pure --source async.zsh --source pure.zsh`
* A module with custom initialization commands:
`zmodule skywind3000/z.lua --cmd 'export _ZL_HYPHEN=1' --cmd 'eval "$(lua {}/z.lua --init zsh enhanced once)"'`
* A module with a custom initialization command:
`zmodule skywind3000/z.lua --cmd 'eval "$(lua {}/z.lua --init zsh enhanced once)"'`
* A module with a big git repository: `zmodule romkatv/powerlevel10k --use degit`
<details id="zmodule-usage">
@ -178,4 +178,4 @@ remove the initialization lines from your `~/.zshenv`, `~/.zshrc` and `~/.zlogin
[blazing speed]: https://github.com/zimfw/zimfw/wiki/Speed
[modules]: https://zimfw.sh/docs/modules/
[themes]: https://zimfw.sh/docs/themes/
[zimfw]: https://github.com/zimfw
[@zimfw]: https://github.com/zimfw

View File

@ -1,7 +1,5 @@
_zimfw_build_login_init() {
# Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once.
local -Ur zscriptdirs=(${ZIM_HOME} ${${_zdirs##${ZIM_HOME}/*}:A})
local -r zscriptglob=("${^zscriptdirs[@]}/(^*test*/)#*.zsh(|-theme)(N-.)") ztarget=${ZIM_HOME}/login_init.zsh
local -r ztarget=${ZIM_HOME}/login_init.zsh
# Force update of login_init.zsh if it's older than .zimrc
if [[ ${ztarget} -ot <%= home %>/.zimrc ]]; then
command mv -f ${ztarget}{,.old} || return 1

View File

@ -5,9 +5,8 @@ _zimfw_compile() {
local zfile
for zfile in ${^zscriptdirs}/(^*test*/)#*.zsh(|-theme)(N-.); do
if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then
zcompile -R ${zfile} && \
if (( _zprintlevel > 0 )) print -PR "<%= okay %>%B${zfile}.zwc:%b Compiled"
zcompile -R ${zfile} && _zimfw_print -PR "<%= okay %>%B${zfile}.zwc:%b Compiled"
fi
done
if (( _zprintlevel > 0 )) print -P '<%= done %>Done with compile.'
_zimfw_print -P '<%= done %>Done with compile.'
}

View File

@ -1,6 +1,5 @@
zimfw() {
builtin emulate -L zsh
setopt EXTENDED_GLOB
builtin emulate -L zsh -o EXTENDED_GLOB
local -r _zversion='<%= version %>' zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
Actions:

View File

@ -1,6 +1,5 @@
# This runs in a new shell
builtin emulate -L zsh
setopt EXTENDED_GLOB
builtin emulate -L zsh -o EXTENDED_GLOB
readonly -i PRINTLEVEL=${1}
readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} TEMP=.zdegit_${RANDOM}
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit

View File

@ -68,9 +68,7 @@ _zimfw_build_init() {
}
_zimfw_build_login_init() {
# Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once.
local -Ur zscriptdirs=(${ZIM_HOME} ${${_zdirs##${ZIM_HOME}/*}:A})
local -r zscriptglob=("${^zscriptdirs[@]}/(^*test*/)#*.zsh(|-theme)(N-.)") ztarget=${ZIM_HOME}/login_init.zsh
local -r ztarget=${ZIM_HOME}/login_init.zsh
# Force update of login_init.zsh if it's older than .zimrc
if [[ ${ztarget} -ot ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
command mv -f ${ztarget}{,.old} || return 1
@ -347,15 +345,14 @@ _zimfw_compile() {
local zfile
for zfile in ${^zscriptdirs}/(^*test*/)#*.zsh(|-theme)(N-.); do
if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then
zcompile -R ${zfile} && \
if (( _zprintlevel > 0 )) print -PR "%F{green})%f %B${zfile}.zwc:%b Compiled"
zcompile -R ${zfile} && _zimfw_print -PR "%F{green})%f %B${zfile}.zwc:%b Compiled"
fi
done
if (( _zprintlevel > 0 )) print -P 'Done with compile.'
_zimfw_print -P 'Done with compile.'
}
_zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2022-01-07 21:17:47 UTC, previous commit is 90de91a)'
print -R 'zimfw version: '${_zversion}' (built at 2022-01-10 16:15:12 UTC, previous commit is cfc955c)'
print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a)
@ -463,8 +460,7 @@ _zimfw_run_tool() {
local zcmd
case ${ztool} in
degit) zcmd="# This runs in a new shell
builtin emulate -L zsh
setopt EXTENDED_GLOB
builtin emulate -L zsh -o EXTENDED_GLOB
readonly -i PRINTLEVEL=\${1}
readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} TEMP=.zdegit_\${RANDOM}
readonly TARBALL_TARGET=\${DIR}/\${TEMP}_tarball.tar.gz INFO_TARGET=\${DIR}/.zdegit
@ -700,8 +696,7 @@ esac
}
zimfw() {
builtin emulate -L zsh
setopt EXTENDED_GLOB
builtin emulate -L zsh -o EXTENDED_GLOB
local -r _zversion='1.7.0-SNAPSHOT' zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
Actions: