2019-01-22 19:40:43 -05:00
zimfw() {
2022-01-10 20:41:50 -05:00
builtin emulate -L zsh -o EXTENDED_GLOB
2023-09-16 14:16:19 -04:00
local -r _zversion='<%= version %>' _zversion_target=${ZIM_HOME}/.latest_version zusage=$'Usage: <%= bold %>'${0}$'<%= normal %> <action> [<%= bold %>-q<%= normal %>|<%= bold %>-v<%= normal %>]
2019-01-22 19:40:43 -05:00
2019-12-01 16:00:47 -05:00
Actions:
2023-09-16 14:16:19 -04:00
<%= bold %>build<%= normal %> Build <%= bold %>'${ZIM_HOME}$'/init.zsh<%= normal %> and <%= bold %>'${ZIM_HOME}$'/login_init.zsh<%= normal %>.
Also does <%= bold %>compile<%= normal %>. Use <%= bold %>-v<%= normal %> to also see its output.
<%= bold %>clean<%= normal %> Clean all. Does both <%= bold %>clean-compiled<%= normal %> and <%= bold %>clean-dumpfile<%= normal %>.
<%= bold %>clean-compiled<%= normal %> Clean Zsh compiled files.
<%= bold %>clean-dumpfile<%= normal %> Clean completion dumpfile.
<%= bold %>compile<%= normal %> Compile Zsh files.
<%= bold %>help<%= normal %> Print this help.
<%= bold %>info<%= normal %> Print zimfw and system info.
<%= bold %>list<%= normal %> List all modules currently defined in <%= bold %>'${ZIM_CONFIG_FILE:-<%= home %>/.zimrc}$'<%= normal %>.
Use <%= bold %>-v<%= normal %> to also see the modules details.
<%= bold %>init<%= normal %> Same as <%= bold %>install<%= normal %>, but with output tailored to be used at terminal startup.
<%= bold %>install<%= normal %> Install new modules. Also does <%= bold %>build<%= normal %>, <%= bold %>compile<%= normal %>. Use <%= bold %>-v<%= normal %> to also see their
2023-02-25 19:03:37 -05:00
output, any on-pull output and skipped modules.
2023-09-16 14:16:19 -04:00
<%= bold %>uninstall<%= normal %> Delete unused modules. Prompts for confirmation. Use <%= bold %>-q<%= normal %> for quiet uninstall.
<%= bold %>check<%= normal %> Check if updates for current modules are available. Use <%= bold %>-v<%= normal %> to also see
2023-03-26 10:34:07 -04:00
skipped and up to date modules.
2023-09-16 14:16:19 -04:00
<%= bold %>update<%= normal %> Update current modules. Also does <%= bold %>build<%= normal %>, <%= bold %>compile<%= normal %>. Use <%= bold %>-v<%= normal %> to also see their
2023-02-25 19:03:37 -05:00
output, any on-pull output and skipped modules.
2023-09-16 14:16:19 -04:00
<%= bold %>check-version<%= normal %> Check if a new version of zimfw is available.
<%= bold %>upgrade<%= normal %> Upgrade zimfw. Also does <%= bold %>compile<%= normal %>. Use <%= bold %>-v<%= normal %> to also see its output.
<%= bold %>version<%= normal %> Print zimfw version.
2019-12-01 16:00:47 -05:00
Options:
2023-09-16 14:16:19 -04:00
<%= bold %>-q<%= normal %> Quiet (yes to prompts and only outputs errors)
<%= bold %>-v<%= normal %> Verbose (outputs more details)'
2022-09-26 21:33:49 -04:00
local -Ua _znames _zroot_dirs _zdisabled_root_dirs
2022-10-06 20:52:57 -04:00
local -A _zfrozens _ztools _zdirs _zurls _ztypes _zrevs _zsubmodules _zonpulls _zifs
2022-05-17 19:43:59 -04:00
local -a _zfpaths _zfunctions _zcmds _zunused_dirs
2020-01-11 16:23:11 -05:00
local -i _zprintlevel=1
2019-12-01 16:00:47 -05:00
if (( # > 2 )); then
2023-09-16 14:16:19 -04:00
print -u2 -lR $'<%= red %>'${0}$': Too many options<%= normal %>' '' ${zusage}
2021-03-19 18:13:21 -04:00
return 2
2019-12-01 16:00:47 -05:00
elif (( # > 1 )); then
case ${2} in
2020-01-11 16:23:11 -05:00
-q) _zprintlevel=0 ;;
-v) _zprintlevel=2 ;;
2019-12-01 16:00:47 -05:00
*)
2023-09-16 14:16:19 -04:00
print -u2 -lR $'<%= red %>'${0}': Unknown option '${2}$'<%= normal %>' '' ${zusage}
2021-03-19 18:13:21 -04:00
return 2
2019-12-01 16:00:47 -05:00
;;
esac
2019-01-22 19:40:43 -05:00
fi
2023-03-26 10:34:07 -04:00
if ! zstyle -t ':zim' disable-version-check && [[ ${1} != check-version ]]; then
2023-03-24 09:40:55 -04:00
# 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=${?}
2023-06-16 21:24:33 -04:00
_zimfw_check_version ${zversion_check_force} 1
2020-01-13 13:14:31 -05:00
fi
2022-01-10 09:29:32 -05:00
local _zrestartmsg=' Restart your terminal for changes to take effect.'
2019-01-22 19:40:43 -05:00
case ${1} in
2020-01-11 16:23:11 -05:00
build)
2021-09-19 14:37:13 -04:00
_zimfw_source_zimrc 2 && _zimfw_build || return 1
2020-01-11 16:23:11 -05:00
(( _zprintlevel-- ))
2023-02-25 19:03:37 -05:00
_zimfw_compile
2020-01-11 16:23:11 -05:00
;;
2023-02-25 19:03:37 -05:00
check-dumpfile) _zimfw_check_dumpfile ;;
2021-09-19 14:37:13 -04:00
clean) _zimfw_source_zimrc 2 && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
clean-compiled) _zimfw_source_zimrc 2 && _zimfw_clean_compiled ;;
2019-12-01 16:00:47 -05:00
clean-dumpfile) _zimfw_clean_dumpfile ;;
2022-05-17 19:43:59 -04:00
compile) _zimfw_source_zimrc 2 && _zimfw_compile ;;
2023-09-16 14:16:19 -04:00
help) print -R ${zusage} ;;
2019-12-01 16:00:47 -05:00
info) _zimfw_info ;;
2021-09-19 14:37:13 -04:00
list)
2022-05-17 19:43:59 -04:00
_zimfw_source_zimrc 3 && zargs -n 1 -- "${_znames[@]}" -- _zimfw_run_list && \
2021-09-29 22:22:28 -04:00
_zimfw_list_unuseds ' (unused)'
2021-09-19 14:37:13 -04:00
;;
2023-03-26 10:34:07 -04:00
check)
_zrestartmsg=
2023-03-28 08:56:37 -04:00
_zimfw_run_tool_action ${1} || return 1
2023-03-26 10:34:07 -04:00
(( _zprintlevel-- ))
2023-09-16 14:16:19 -04:00
_zimfw_print -R "Done with ${1}." # Only printed in verbose mode
2023-03-26 10:34:07 -04:00
;;
2022-01-10 09:29:32 -05:00
init)
_zrestartmsg=
2023-03-28 08:56:37 -04:00
_zimfw_run_tool_action install || return 1
2022-01-10 09:29:32 -05:00
(( _zprintlevel-- ))
2023-09-16 14:16:19 -04:00
_zimfw_print 'Done with install.' # Only printed in verbose mode
2023-03-28 08:56:37 -04:00
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
2022-01-10 09:29:32 -05:00
;;
2019-01-22 19:40:43 -05:00
install|update)
2023-03-28 08:56:37 -04:00
_zimfw_run_tool_action ${1} || return 1
2023-09-16 14:16:19 -04:00
_zimfw_print -R "Done with ${1}.${_zrestartmsg}"
2020-01-11 16:23:11 -05:00
(( _zprintlevel-- ))
2023-03-28 08:56:37 -04:00
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
2019-01-22 19:40:43 -05:00
;;
2021-09-19 14:37:13 -04:00
uninstall) _zimfw_source_zimrc 2 && _zimfw_list_unuseds && _zimfw_uninstall ;;
2023-03-26 10:34:07 -04:00
check-version) _zimfw_check_version 1 ;;
2020-01-11 16:23:11 -05:00
upgrade)
_zimfw_upgrade || return 1
(( _zprintlevel-- ))
2022-05-17 19:43:59 -04:00
_zimfw_source_zimrc 2 && _zimfw_compile
2020-01-11 16:23:11 -05:00
;;
2023-09-16 14:16:19 -04:00
version) print -R ${_zversion} ;;
2019-01-22 19:40:43 -05:00
*)
2023-09-16 14:16:19 -04:00
print -u2 -lR $'<%= red %>'${0}': Unknown action '${1}$'<%= normal %>' '' ${zusage}
2021-03-19 18:13:21 -04:00
return 2
2019-01-22 19:40:43 -05:00
;;
esac
}