From 76164d62179dc58a487e3e493d4167e80fa9795f Mon Sep 17 00:00:00 2001 From: Eric Nielsen <4120606+ericbn@users.noreply.github.com> Date: Fri, 14 Jun 2024 20:17:07 -0500 Subject: [PATCH] Allow zimfw.zsh to exist outside ZIM_HOME and change initialization so ZIM_HOME is required before sourcing the script. --- CHANGELOG.md | 4 +++- src/stage2/20_guard.zsh.erb | 6 +++++- src/stage2/29_zimfw_build_init.zsh.erb | 2 +- src/stage2/50_zimfw_upgrade.zsh.erb | 2 +- zimfw.zsh | 12 ++++++++---- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a6f108..a35b7b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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. + not found" instead, as it's intended to be used only in the .zimrc script. +- Allow zimfw.zsh to exist anywhere else, not only inside `ZIM_HOME`. This + enables installing the zimfw.zsh script independently with a package manager. ### Fixed diff --git a/src/stage2/20_guard.zsh.erb b/src/stage2/20_guard.zsh.erb index 291c636..9920918 100644 --- a/src/stage2/20_guard.zsh.erb +++ b/src/stage2/20_guard.zsh.erb @@ -4,5 +4,9 @@ autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then fi autoload -Uz zargs +if (( ! ${+ZIM_HOME} )); then + print -u2 -R $'<%= red %>'${0}$': ZIM_HOME not defined<%= normal %>' + return 1 +fi # Define zimfw location -if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:h} +typeset -g __ZIMFW_PATH=${0:h} diff --git a/src/stage2/29_zimfw_build_init.zsh.erb b/src/stage2/29_zimfw_build_init.zsh.erb index ce1ef28..db58bfd 100644 --- a/src/stage2/29_zimfw_build_init.zsh.erb +++ b/src/stage2/29_zimfw_build_init.zsh.erb @@ -5,7 +5,7 @@ _zimfw_build_init() { command mv -f ${ztarget}{,.old} || return 1 fi _zimfw_mv =( - print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" + print -R "zimfw() { source ${(q-)__ZIMFW_PATH}/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/50_zimfw_upgrade.zsh.erb b/src/stage2/50_zimfw_upgrade.zsh.erb index 93026f3..d7f8cbc 100644 --- a/src/stage2/50_zimfw_upgrade.zsh.erb +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -1,5 +1,5 @@ _zimfw_upgrade() { - local -r ztarget=${ZIM_HOME}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz + local -r ztarget=${__ZIMFW_PATH}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz { if (( ${+commands[curl]} )); then command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1 diff --git a/zimfw.zsh b/zimfw.zsh index 343caa0..eb73da8 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -30,8 +30,12 @@ autoload -Uz is-at-least && if ! is-at-least 5.2; then fi autoload -Uz zargs +if (( ! ${+ZIM_HOME} )); then + print -u2 -R $'\E[31m'${0}$': ZIM_HOME not defined\E[0m' + return 1 +fi # Define zimfw location -if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:h} +typeset -g __ZIMFW_PATH=${0:h} _zimfw_print() { if (( _zprintlevel > 0 )) print "${@}" @@ -57,7 +61,7 @@ _zimfw_build_init() { command mv -f ${ztarget}{,.old} || return 1 fi _zimfw_mv =( - print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" + print -R "zimfw() { source ${(q-)__ZIMFW_PATH}/zimfw.zsh \"\${@}\" }" local zroot_dir zpre local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) @@ -457,7 +461,7 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (built at 2024-06-03 13:45:11 UTC, previous commit is 96f60da)' + print -R 'zimfw version: '${_zversion}' (built at 2024-06-15 01:16:55 UTC, previous commit is 9a47fde)' 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} @@ -477,7 +481,7 @@ _zimfw_uninstall() { } _zimfw_upgrade() { - local -r ztarget=${ZIM_HOME}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz + local -r ztarget=${__ZIMFW_PATH}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz { if (( ${+commands[curl]} )); then command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1