1
0
Fork 0
mirror of synced 2024-11-26 17:25:35 -05:00

Further improve handling of external modules

Fix computing the list of unused modules by using the full `_zdirs`
instead of just the `_zmodules` names. The fixed code was even simpler
and cleaner, which makes it even more satisfying.  :- )

Show "not found" instead of "not installed" error when an external
module dir does not exist, since we don't install external modules.
This commit is contained in:
Eric Nielsen 2021-09-23 11:36:38 -05:00
parent 92e6d6b74b
commit 6ca4690edc
No known key found for this signature in database
GPG key ID: 47D1DBFA0765A1FB
5 changed files with 51 additions and 49 deletions

View file

@ -142,21 +142,24 @@ Initialization options:
fi fi
if (( _zflags & 2 )); then if (( _zflags & 2 )); then
if (( zdisabled )); then if (( zdisabled )); then
_zdisableds+=(${zmodule}) _zdisabled_dirs+=(${zdir})
else else
if [[ ! -d ${zdir} ]]; then if [[ ! -e ${zdir} ]]; then
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Not installed. Run %Bzimfw install%b to install.%f" if [[ -z ${zurl} ]]; then
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}: ${zdir}%b not found%f"
else
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Not installed. Run %Bzimfw install%b to install.%f"
fi
_zfailed=1 _zfailed=1
return 1 return 1
fi fi
local -ra prezto_fpaths=(${zdir}/functions(NF)) prezto_scripts=(${zdir}/init.zsh(N)) if (( ! ${#zfpaths} && ! ${#zcmds} )); then
if (( ! ${#zfpaths} && ! ${#zcmds} && ${#prezto_fpaths} && ${#prezto_scripts} )); then zfpaths=(${zdir}/functions(NF))
# this follows the prezto module format, no need to check for other scripts local -ra prezto_scripts=(${zdir}/init.zsh(N))
zfpaths=(${prezto_fpaths}) if (( ${#zfpaths} && ${#prezto_scripts} )); then
zcmds=("source ${^prezto_scripts[@]:A}") # this follows the prezto module format, no need to check for other scripts
else zcmds=("source ${^prezto_scripts[@]:A}")
if (( ! ${#zfpaths} )) zfpaths=(${prezto_fpaths}) else
if (( ! ${#zcmds} )); then
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) # get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first)
local -ra zscripts=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) local -ra zscripts=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds=("source ${^zscripts[@]:A}") zcmds=("source ${^zscripts[@]:A}")
@ -170,7 +173,6 @@ Initialization options:
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
_zimfw_print -u2 -PR "%F{yellow}<%= warn %>${funcfiletrace[1]}:%B${zmodule}:%b Nothing found to be initialized. Customize the module name or initialization with %Bzmodule%b options.%f"$'\n\n'${zusage} _zimfw_print -u2 -PR "%F{yellow}<%= warn %>${funcfiletrace[1]}:%B${zmodule}:%b Nothing found to be initialized. Customize the module name or initialization with %Bzmodule%b options.%f"$'\n\n'${zusage}
fi fi
_zmodules+=(${zmodule})
_zdirs+=(${zdir}) _zdirs+=(${zdir})
# Prefix is added to all _zfpaths, _zfunctions and _zcmds to distinguish the originating modules # Prefix is added to all _zfpaths, _zfunctions and _zcmds to distinguish the originating modules
local -r zpre=${zmodule}$'\0' local -r zpre=${zmodule}$'\0'

View file

@ -1,20 +1,19 @@
_zimfw_list_unuseds() { _zimfw_list_unuseds() {
local -i i=1 local -i i=1
local -a zinstalled=(${ZIM_HOME}/modules/*(N/:t)) subdirs local -a zinstalled=(${ZIM_HOME}/modules/*(N/))
# Search into subdirectories # Search into subdirectories
while (( i <= ${#zinstalled} )); do while (( i <= ${#zinstalled} )); do
if (( ${_zmodules[(I)${zinstalled[i]}/*]} || ${_zdisableds[(I)${zinstalled[i]}/*]} )); then if (( ${_zdirs[(I)${zinstalled[i]}/*]} || ${_zdisabled_dirs[(I)${zinstalled[i]}/*]} )); then
subdirs=(${ZIM_HOME}/modules/${zinstalled[i]}/*(N/:t)) zinstalled+=(${zinstalled[i]}/*(N/))
zinstalled+=(${zinstalled[i]}/${^subdirs})
zinstalled[i]=() zinstalled[i]=()
else else
(( i++ )) (( i++ ))
fi fi
done done
# Unused = all installed modules not in _zmodules and _zdisableds # Unused = all installed dirs not in _zdirs and _zdisabled_dirs
_zunuseds=(${${zinstalled:|_zmodules}:|_zdisableds}) _zunused_dirs=(${${zinstalled:|_zdirs}:|_zdisabled_dirs})
local zunused local zunused
for zunused in ${_zunuseds}; do for zunused in ${_zunused_dirs}; do
_zimfw_print -PR "%B${zunused}:%b ${ZIM_HOME}/modules/${zunused}${1}" _zimfw_print -PR "%B${zunused:t}:%b ${zunused}${1}"
done done
} }

View file

@ -1,10 +1,10 @@
_zimfw_uninstall() { _zimfw_uninstall() {
local zopt local zopt
if (( _zprintlevel > 0 )) zopt='-v' if (( _zprintlevel > 0 )) zopt='-v'
if (( ${#_zunuseds} )); then if (( ${#_zunused_dirs} )); then
if (( _zprintlevel <= 0 )) || read -q "?Uninstall ${#_zunuseds} module(s) listed above [y/N]? "; then if (( _zprintlevel <= 0 )) || read -q "?Uninstall ${#_zunused_dirs} module(s) listed above [y/N]? "; then
_zimfw_print _zimfw_print
command rm -rf ${zopt} ${ZIM_HOME}/modules/${^_zunuseds} || return 1 command rm -rf ${zopt} ${_zunused_dirs} || return 1
fi fi
fi fi
_zimfw_print -P '<%= done %>Done with uninstall.' _zimfw_print -P '<%= done %>Done with uninstall.'

View file

@ -20,7 +20,7 @@ Actions:
Options: Options:
%B-q%b Quiet (yes to prompts, and only outputs errors) %B-q%b Quiet (yes to prompts, and only outputs errors)
%B-v%b Verbose (outputs more details)" %B-v%b Verbose (outputs more details)"
local -a _zdisableds _zmodules _zdirs _zfpaths _zfunctions _zcmds _zmodules_zargs _zunuseds local -a _zdisabled_dirs _zdirs _zfpaths _zfunctions _zcmds _zmodules_zargs _zunused_dirs
local -i _zprintlevel=1 local -i _zprintlevel=1
if (( # > 2 )); then if (( # > 2 )); then
print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage} print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage}

View file

@ -252,21 +252,24 @@ Initialization options:
fi fi
if (( _zflags & 2 )); then if (( _zflags & 2 )); then
if (( zdisabled )); then if (( zdisabled )); then
_zdisableds+=(${zmodule}) _zdisabled_dirs+=(${zdir})
else else
if [[ ! -d ${zdir} ]]; then if [[ ! -e ${zdir} ]]; then
print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}:%b Not installed. Run %Bzimfw install%b to install.%f" if [[ -z ${zurl} ]]; then
print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}: ${zdir}%b not found%f"
else
print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}:%b Not installed. Run %Bzimfw install%b to install.%f"
fi
_zfailed=1 _zfailed=1
return 1 return 1
fi fi
local -ra prezto_fpaths=(${zdir}/functions(NF)) prezto_scripts=(${zdir}/init.zsh(N)) if (( ! ${#zfpaths} && ! ${#zcmds} )); then
if (( ! ${#zfpaths} && ! ${#zcmds} && ${#prezto_fpaths} && ${#prezto_scripts} )); then zfpaths=(${zdir}/functions(NF))
# this follows the prezto module format, no need to check for other scripts local -ra prezto_scripts=(${zdir}/init.zsh(N))
zfpaths=(${prezto_fpaths}) if (( ${#zfpaths} && ${#prezto_scripts} )); then
zcmds=("source ${^prezto_scripts[@]:A}") # this follows the prezto module format, no need to check for other scripts
else zcmds=("source ${^prezto_scripts[@]:A}")
if (( ! ${#zfpaths} )) zfpaths=(${prezto_fpaths}) else
if (( ! ${#zcmds} )); then
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) # get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first)
local -ra zscripts=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) local -ra zscripts=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds=("source ${^zscripts[@]:A}") zcmds=("source ${^zscripts[@]:A}")
@ -280,7 +283,6 @@ Initialization options:
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
_zimfw_print -u2 -PR "%F{yellow}! ${funcfiletrace[1]}:%B${zmodule}:%b Nothing found to be initialized. Customize the module name or initialization with %Bzmodule%b options.%f"$'\n\n'${zusage} _zimfw_print -u2 -PR "%F{yellow}! ${funcfiletrace[1]}:%B${zmodule}:%b Nothing found to be initialized. Customize the module name or initialization with %Bzmodule%b options.%f"$'\n\n'${zusage}
fi fi
_zmodules+=(${zmodule})
_zdirs+=(${zdir}) _zdirs+=(${zdir})
# Prefix is added to all _zfpaths, _zfunctions and _zcmds to distinguish the originating modules # Prefix is added to all _zfpaths, _zfunctions and _zcmds to distinguish the originating modules
local -r zpre=${zmodule}$'\0' local -r zpre=${zmodule}$'\0'
@ -306,22 +308,21 @@ _zimfw_source_zimrc() {
_zimfw_list_unuseds() { _zimfw_list_unuseds() {
local -i i=1 local -i i=1
local -a zinstalled=(${ZIM_HOME}/modules/*(N/:t)) subdirs local -a zinstalled=(${ZIM_HOME}/modules/*(N/))
# Search into subdirectories # Search into subdirectories
while (( i <= ${#zinstalled} )); do while (( i <= ${#zinstalled} )); do
if (( ${_zmodules[(I)${zinstalled[i]}/*]} || ${_zdisableds[(I)${zinstalled[i]}/*]} )); then if (( ${_zdirs[(I)${zinstalled[i]}/*]} || ${_zdisabled_dirs[(I)${zinstalled[i]}/*]} )); then
subdirs=(${ZIM_HOME}/modules/${zinstalled[i]}/*(N/:t)) zinstalled+=(${zinstalled[i]}/*(N/))
zinstalled+=(${zinstalled[i]}/${^subdirs})
zinstalled[i]=() zinstalled[i]=()
else else
(( i++ )) (( i++ ))
fi fi
done done
# Unused = all installed modules not in _zmodules and _zdisableds # Unused = all installed dirs not in _zdirs and _zdisabled_dirs
_zunuseds=(${${zinstalled:|_zmodules}:|_zdisableds}) _zunused_dirs=(${${zinstalled:|_zdirs}:|_zdisabled_dirs})
local zunused local zunused
for zunused in ${_zunuseds}; do for zunused in ${_zunused_dirs}; do
_zimfw_print -PR "%B${zunused}:%b ${ZIM_HOME}/modules/${zunused}${1}" _zimfw_print -PR "%B${zunused:t}:%b ${zunused}${1}"
done done
} }
@ -370,7 +371,7 @@ _zimfw_compile() {
} }
_zimfw_info() { _zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2021-09-21 21:19:43 UTC, previous commit is 9a67adf)' print -R 'zimfw version: '${_zversion}' (built at 2021-09-23 16:35:30 UTC, previous commit is 92e6d6b)'
print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'Zsh version: '${ZSH_VERSION} print -R 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a) print -R 'System info: '$(command uname -a)
@ -379,10 +380,10 @@ _zimfw_info() {
_zimfw_uninstall() { _zimfw_uninstall() {
local zopt local zopt
if (( _zprintlevel > 0 )) zopt='-v' if (( _zprintlevel > 0 )) zopt='-v'
if (( ${#_zunuseds} )); then if (( ${#_zunused_dirs} )); then
if (( _zprintlevel <= 0 )) || read -q "?Uninstall ${#_zunuseds} module(s) listed above [y/N]? "; then if (( _zprintlevel <= 0 )) || read -q "?Uninstall ${#_zunused_dirs} module(s) listed above [y/N]? "; then
_zimfw_print _zimfw_print
command rm -rf ${zopt} ${ZIM_HOME}/modules/${^_zunuseds} || return 1 command rm -rf ${zopt} ${_zunused_dirs} || return 1
fi fi
fi fi
_zimfw_print -P 'Done with uninstall.' _zimfw_print -P 'Done with uninstall.'
@ -724,7 +725,7 @@ Actions:
Options: Options:
%B-q%b Quiet (yes to prompts, and only outputs errors) %B-q%b Quiet (yes to prompts, and only outputs errors)
%B-v%b Verbose (outputs more details)" %B-v%b Verbose (outputs more details)"
local -a _zdisableds _zmodules _zdirs _zfpaths _zfunctions _zcmds _zmodules_zargs _zunuseds local -a _zdisabled_dirs _zdirs _zfpaths _zfunctions _zcmds _zmodules_zargs _zunused_dirs
local -i _zprintlevel=1 local -i _zprintlevel=1
if (( # > 2 )); then if (( # > 2 )); then
print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage} print -u2 -PR "%F{red}${0}: Too many options%f"$'\n\n'${zusage}