Try to upgrade zimfw.zsh if it's a symlink
Initially the idea was to not allow this so upgrades are disabled when the script is installed using a package manager, but this is an unnecessary complexity. Making it less smart and more predictable.
This commit is contained in:
parent
0785d87ea4
commit
3b7908dca1
6 changed files with 14 additions and 23 deletions
|
@ -15,8 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
already doing so, hence not considering this is a breaking change.
|
already doing so, hence not considering this is a breaking change.
|
||||||
- Allow zimfw.zsh to exist anywhere else, not only inside `ZIM_HOME`. This
|
- Allow zimfw.zsh to exist anywhere else, not only inside `ZIM_HOME`. This
|
||||||
enables installing the zimfw.zsh script independently with a package manager.
|
enables installing the zimfw.zsh script independently with a package manager.
|
||||||
- Don't try to upgrade if sourced zimfw.zsh is not in a writable path or is a
|
- Don't try to upgrade if sourced zimfw.zsh is not in a writable path.
|
||||||
symlink.
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -9,4 +9,4 @@ if (( ! ${+ZIM_HOME} )); then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Define zimfw location
|
# Define zimfw location
|
||||||
typeset -g __ZIMFW_PATH=${0:h}
|
typeset -g __ZIMFW_FILE=${0}
|
||||||
|
|
|
@ -5,7 +5,7 @@ _zimfw_build_init() {
|
||||||
command mv -f ${ztarget}{,.old} || return 1
|
command mv -f ${ztarget}{,.old} || return 1
|
||||||
fi
|
fi
|
||||||
_zimfw_mv =(
|
_zimfw_mv =(
|
||||||
print -R 'if (( ${+ZIM_HOME} )) zimfw() { source '${${(qqq)__ZIMFW_PATH}/${HOME}/\${HOME}}'/zimfw.zsh "${@}" }'
|
print -R 'if (( ${+ZIM_HOME} )) zimfw() { source '${${(qqq)__ZIMFW_FILE}/${HOME}/\${HOME}}' "${@}" }'
|
||||||
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})
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
_zimfw_upgrade() {
|
_zimfw_upgrade() {
|
||||||
if [[ ! -w ${__ZIMFW_PATH} ]]; then
|
local -r ztarget=${__ZIMFW_FILE:A} zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
|
||||||
print -u2 -R $'<%= red %>No write permission to <%= bold %>'${__ZIMFW_PATH}$'<%= normalred %>. Will not try to upgrade.<%= normal %>'
|
if [[ ! -w ${ztarget:h} ]]; then
|
||||||
return 1
|
print -u2 -R $'<%= red %>No write permission to <%= bold %>'${ztarget:h}$'<%= normalred %>. Will not try to upgrade.<%= normal %>'
|
||||||
fi
|
|
||||||
local -r ztarget=${__ZIMFW_PATH}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
|
|
||||||
if [[ -L ${ztarget} || ! -f ${ztarget} ]]; then
|
|
||||||
print -u2 -R $'<%= red %><%= bold %>'${ztarget}$'<%= normalred %> is a symlink or not a regular file. Will not try to upgrade.<%= normal %>'
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,7 @@ Options:
|
||||||
|
|
||||||
local -r _zversion_target=${ZIM_HOME}/.latest_version
|
local -r _zversion_target=${ZIM_HOME}/.latest_version
|
||||||
if ! zstyle -t ':zim' disable-version-check && \
|
if ! zstyle -t ':zim' disable-version-check && \
|
||||||
[[ ${1} != check-version && -w ${ZIM_HOME} && -w ${__ZIMFW_PATH} && ! -L ${__ZIMFW_PATH}/zimfw.zsh && -f ${__ZIMFW_PATH}/zimfw.zsh ]]
|
[[ ${1} != check-version && -w ${ZIM_HOME} && -w ${__ZIMFW_FILE:A:h} ]]
|
||||||
then
|
then
|
||||||
# If .latest_version does not exist or was not modified in the last 30 days
|
# If .latest_version does not exist or was not modified in the last 30 days
|
||||||
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
|
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
|
||||||
|
|
18
zimfw.zsh
18
zimfw.zsh
|
@ -35,7 +35,7 @@ if (( ! ${+ZIM_HOME} )); then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Define zimfw location
|
# Define zimfw location
|
||||||
typeset -g __ZIMFW_PATH=${0:h}
|
typeset -g __ZIMFW_FILE=${0}
|
||||||
|
|
||||||
_zimfw_print() {
|
_zimfw_print() {
|
||||||
if (( _zprintlevel > 0 )) print "${@}"
|
if (( _zprintlevel > 0 )) print "${@}"
|
||||||
|
@ -61,7 +61,7 @@ _zimfw_build_init() {
|
||||||
command mv -f ${ztarget}{,.old} || return 1
|
command mv -f ${ztarget}{,.old} || return 1
|
||||||
fi
|
fi
|
||||||
_zimfw_mv =(
|
_zimfw_mv =(
|
||||||
print -R 'if (( ${+ZIM_HOME} )) zimfw() { source '${${(qqq)__ZIMFW_PATH}/${HOME}/\${HOME}}'/zimfw.zsh "${@}" }'
|
print -R 'if (( ${+ZIM_HOME} )) zimfw() { source '${${(qqq)__ZIMFW_FILE}/${HOME}/\${HOME}}' "${@}" }'
|
||||||
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})
|
||||||
|
@ -462,7 +462,7 @@ _zimfw_compile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_info() {
|
_zimfw_info() {
|
||||||
print -R 'zimfw version: '${_zversion}' (built at 2024-06-21 20:42:45 UTC, previous commit is eb37844)'
|
print -R 'zimfw version: '${_zversion}' (built at 2024-06-25 14:06:08 UTC, previous commit is 0785d87)'
|
||||||
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}
|
||||||
|
@ -482,13 +482,9 @@ _zimfw_uninstall() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_zimfw_upgrade() {
|
_zimfw_upgrade() {
|
||||||
if [[ ! -w ${__ZIMFW_PATH} ]]; then
|
local -r ztarget=${__ZIMFW_FILE:A} zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
|
||||||
print -u2 -R $'\E[31mNo write permission to \E[1m'${__ZIMFW_PATH}$'\E[0;31m. Will not try to upgrade.\E[0m'
|
if [[ ! -w ${ztarget:h} ]]; then
|
||||||
return 1
|
print -u2 -R $'\E[31mNo write permission to \E[1m'${ztarget:h}$'\E[0;31m. Will not try to upgrade.\E[0m'
|
||||||
fi
|
|
||||||
local -r ztarget=${__ZIMFW_PATH}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
|
|
||||||
if [[ -L ${ztarget} || ! -f ${ztarget} ]]; then
|
|
||||||
print -u2 -R $'\E[31m\E[1m'${ztarget}$'\E[0;31m is a symlink or not a regular file. Will not try to upgrade.\E[0m'
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
{
|
{
|
||||||
|
@ -946,7 +942,7 @@ Options:
|
||||||
|
|
||||||
local -r _zversion_target=${ZIM_HOME}/.latest_version
|
local -r _zversion_target=${ZIM_HOME}/.latest_version
|
||||||
if ! zstyle -t ':zim' disable-version-check && \
|
if ! zstyle -t ':zim' disable-version-check && \
|
||||||
[[ ${1} != check-version && -w ${ZIM_HOME} && -w ${__ZIMFW_PATH} && ! -L ${__ZIMFW_PATH}/zimfw.zsh && -f ${__ZIMFW_PATH}/zimfw.zsh ]]
|
[[ ${1} != check-version && -w ${ZIM_HOME} && -w ${__ZIMFW_FILE:A:h} ]]
|
||||||
then
|
then
|
||||||
# If .latest_version does not exist or was not modified in the last 30 days
|
# If .latest_version does not exist or was not modified in the last 30 days
|
||||||
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
|
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
|
||||||
|
|
Loading…
Reference in a new issue