From 2491856a7b426a34b3765b905f30ee1ff9cd9c3b Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 10 Jan 2022 20:41:50 -0500 Subject: [PATCH] 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. --- README.md | 10 +++++----- src/stage2/29_zimfw_build_login_init.zsh.erb | 4 +--- src/stage2/50_zimfw_compile.zsh.erb | 5 ++--- src/stage2/80_zimfw.zsh.erb | 3 +-- src/tools/degit.zsh.erb | 3 +-- zimfw.zsh | 17 ++++++----------- 6 files changed, 16 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 61bc539..74944ca 100644 --- a/README.md +++ b/README.md @@ -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`
@@ -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 diff --git a/src/stage2/29_zimfw_build_login_init.zsh.erb b/src/stage2/29_zimfw_build_login_init.zsh.erb index 238652f..291fc40 100644 --- a/src/stage2/29_zimfw_build_login_init.zsh.erb +++ b/src/stage2/29_zimfw_build_login_init.zsh.erb @@ -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 diff --git a/src/stage2/50_zimfw_compile.zsh.erb b/src/stage2/50_zimfw_compile.zsh.erb index 6d5c357..2fca33f 100644 --- a/src/stage2/50_zimfw_compile.zsh.erb +++ b/src/stage2/50_zimfw_compile.zsh.erb @@ -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.' } diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 9f5bb9a..c15dd87 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -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 [%B-q%b|%B-v%b] Actions: diff --git a/src/tools/degit.zsh.erb b/src/tools/degit.zsh.erb index 1bc9537..771546f 100644 --- a/src/tools/degit.zsh.erb +++ b/src/tools/degit.zsh.erb @@ -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 diff --git a/zimfw.zsh b/zimfw.zsh index 102d798..fd976d7 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -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 [%B-q%b|%B-v%b] Actions: