2019-01-22 19:40:43 -05:00
# AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE.
# DO NOT DIRECTLY EDIT THIS FILE!
2019-12-08 20:03:45 -05:00
# MIT License
#
# Copyright (c) 2015-2016 Matt Hamilton and contributors
2024-02-16 21:04:21 -05:00
# Copyright (c) 2016-2024 Eric Nielsen, Matt Hamilton and contributors
2019-12-08 20:03:45 -05:00
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
2019-01-22 19:40:43 -05:00
autoload -Uz is-at-least && if ! is-at-least 5.2; then
2023-09-16 14:16:19 -04:00
print -u2 -R $'\E[31m' ${ 0 } $': Error starting zimfw. You\'re using Zsh version \E[1m' ${ ZSH_VERSION } $'\E[0;31m and versions < \E[1m5.2\E[0;31m are not supported. Upgrade your Zsh.\E[0m'
2019-01-22 19:40:43 -05:00
return 1
fi
2021-09-19 14:37:13 -04:00
autoload -Uz zargs
2019-01-22 19:40:43 -05:00
2024-06-14 21:17:07 -04:00
if ( ( ! ${ +ZIM_HOME } ) ) ; then
2024-06-21 16:43:48 -04:00
print -u2 -R $'\E[31m' ${ 0 } $': \E[1mZIM_HOME\E[0;31m not defined\E[0m'
2024-06-14 21:17:07 -04:00
return 1
fi
2023-09-16 14:16:19 -04:00
# Define zimfw location
2024-06-25 10:08:10 -04:00
typeset -g __ZIMFW_FILE = ${ 0 }
2019-01-22 19:40:43 -05:00
2020-01-09 07:13:31 -05:00
_zimfw_print( ) {
2020-02-03 20:43:36 -05:00
if ( ( _zprintlevel > 0 ) ) print " ${ @ } "
2020-01-09 07:13:31 -05:00
}
2019-12-14 22:21:34 -05:00
_zimfw_mv( ) {
2020-05-25 14:40:34 -04:00
local -a cklines
if cklines = ( ${ (f) " $( command cksum ${ 1 } ${ 2 } 2>/dev/null) " } ) && \
[ [ ${ ${ (z)cklines[1] } [1,2] } = = ${ ${ (z)cklines[2] } [1,2] } ] ] ; then
2023-09-16 14:16:19 -04:00
_zimfw_print -R $'\E[32m)\E[0m \E[1m' ${ 2 } $':\E[0m Already up to date'
2019-12-14 22:21:34 -05:00
else
if [ [ -e ${ 2 } ] ] ; then
command mv -f ${ 2 } { ,.old} || return 1
fi
2024-06-03 09:51:20 -04:00
command mv -f ${ 1 } ${ 2 } && command chmod a+r ${ 2 } && _zimfw_print -R $'\E[32m)\E[0m \E[1m' ${ 2 } $':\E[0m Updated.' ${ _zrestartmsg }
2019-12-14 22:21:34 -05:00
fi
}
_zimfw_build_init( ) {
local -r ztarget = ${ ZIM_HOME } /init.zsh
# Force update of init.zsh if it's older than .zimrc
2022-10-23 20:34:14 -04:00
if [ [ ${ ztarget } -ot ${ ZIM_CONFIG_FILE :- ${ ZDOTDIR :- ${ HOME } } /.zimrc } ] ] ; then
2019-12-14 22:21:34 -05:00
command mv -f ${ ztarget } { ,.old} || return 1
fi
_zimfw_mv = (
2024-06-25 10:08:10 -04:00
print -R 'if (( ${+ZIM_HOME} )) zimfw() { source ' ${ ${ (qqq)__ZIMFW_FILE } / ${ HOME } / \$ {HOME } } ' "${@}" }'
2022-10-06 20:52:57 -04:00
local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions = ( ${ _zfunctions } ) zcmds = ( ${ _zcmds } )
# Keep fpath constant regardless of "if" root dirs, to avoid confusing compinit.
# Move all from zfunctions and zcmds with "if" root dirs prefixes.
for zroot_dir in ${ _zroot_dirs } ; do
if ( ( ${ +_zifs[ ${ zroot_dir } ] } ) ) ; then
zpre = ${ zroot_dir } $'\0'
zif_functions += ( ${ (M)zfunctions : # ${ zpre } * } )
zif_cmds += ( ${ (M)zcmds : # ${ zpre } * } )
zfunctions = ( ${ zfunctions : # ${ zpre } * } )
zcmds = ( ${ zcmds : # ${ zpre } * } )
fi
done
zpre = $'*\0'
2024-06-17 08:22:18 -04:00
if ( ( ${# _zfpaths } ) ) print -R 'fpath=(' ${ ${ (qqq) ${ _zfpaths # ${ ~zpre } } : a } / ${ HOME } / \$ {HOME } } ' ${fpath})'
2022-10-06 20:52:57 -04:00
if ( ( ${# zfunctions } ) ) print -R 'autoload -Uz -- ' ${ zfunctions # ${ ~zpre } }
for zroot_dir in ${ _zroot_dirs } ; do
zpre = ${ zroot_dir } $'\0'
if ( ( ${ +_zifs[ ${ zroot_dir } ] } ) ) ; then
zroot_functions = ( ${ ${ (M)zif_functions : # ${ zpre } * } # ${ zpre } } )
zroot_cmds = ( ${ ${ (M)zif_cmds : # ${ zpre } * } # ${ zpre } } )
if ( ( ${# zroot_functions } || ${# zroot_cmds } ) ) ; then
print -R 'if ' ${ _zifs [ ${ zroot_dir } ] } '; then'
if ( ( ${# zroot_functions } ) ) print -R ' autoload -Uz -- ' ${ zroot_functions }
if ( ( ${# zroot_cmds } ) ) print -R ${ (F) :- ${ ^zroot_cmds } }
print fi
fi
else
zroot_cmds = ( ${ ${ (M)zcmds : # ${ zpre } * } # ${ zpre } } )
if ( ( ${# zroot_cmds } ) ) print -R ${ (F)zroot_cmds }
fi
done
2019-12-14 22:21:34 -05:00
) ${ ztarget }
}
_zimfw_build_login_init( ) {
2022-01-10 20:41:50 -05:00
local -r ztarget = ${ ZIM_HOME } /login_init.zsh
2020-11-23 09:38:08 -05:00
# Force update of login_init.zsh if it's older than .zimrc
2022-10-23 20:34:14 -04:00
if [ [ ${ ztarget } -ot ${ ZIM_CONFIG_FILE :- ${ ZDOTDIR :- ${ HOME } } /.zimrc } ] ] ; then
2020-11-23 09:38:08 -05:00
command mv -f ${ ztarget } { ,.old} || return 1
fi
2019-12-14 22:21:34 -05:00
_zimfw_mv = (
2023-03-28 08:56:37 -04:00
print '# Do nothing. This file is deprecated.'
2019-12-14 22:21:34 -05:00
) ${ ztarget }
2019-01-22 19:40:43 -05:00
}
2019-12-01 16:00:47 -05:00
_zimfw_build( ) {
2023-09-16 14:16:19 -04:00
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
2019-01-22 19:40:43 -05:00
}
2024-05-30 10:15:05 -04:00
_zimfw_source_zimrc( ) {
2019-12-01 16:00:47 -05:00
zmodule( ) {
2022-10-23 20:34:14 -04:00
local -r ztarget = ${ ZIM_CONFIG_FILE :- ${ ZDOTDIR :- ${ HOME } } /.zimrc }
2023-09-16 14:16:19 -04:00
local -r zusage = $'Usage: \E[1m' ${ 0 } $' \E [ 0m <url> [ \E [ 1m-n\E [ 0m| \E [ 1m--name\E [ 0m <module_name>] [ \E [ 1m-r\E [ 0m| \E [ 1m--root\E [ 0m <path>] [ options]
2019-01-22 19:40:43 -05:00
2023-09-16 14:16:19 -04:00
Add \E [ 1mzmodule\E [ 0m calls to your \E [ 1m'${ztarget}$' \E [ 0m file to define the modules to be initialized.
The initialization will be done in the same order it\' s defined.
2020-05-02 19:47:38 -04:00
2020-10-11 13:24:01 -04:00
<url> Module absolute path or repository URL. The following URL formats
2023-09-16 14:16:19 -04:00
are equivalent: \E [ 1mfoo\E [ 0m, \E [ 1mzimfw/foo\E [ 0m, \E [ 1mhttps://github.com/zimfw/foo.git\E [ 0m.
2022-09-26 21:33:49 -04:00
If an absolute path is given, the module is considered externally
2024-02-16 20:41:29 -05:00
installed and won\' t be installed or updated by zimfw.
2023-09-16 14:16:19 -04:00
\E [ 1m-n\E [ 0m| \E [ 1m--name\E [ 0m <module_name> Set a custom module name. Default: the last component in <url>.
2022-10-06 20:52:57 -04:00
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
2023-09-16 14:16:19 -04:00
\E [ 1m'${ZIM_HOME}$' /\E [ 0m<module_name>.
\E [ 1m-r\E [ 0m| \E [ 1m--root\E [ 0m <path> Relative path to the module root.
2022-09-26 21:33:49 -04:00
Per-module options:
2023-09-16 14:16:19 -04:00
\E [ 1m-b\E [ 0m| \E [ 1m--branch\E [ 0m <branch_name> Use specified branch when installing and updating the module.
2021-11-08 20:05:32 -05:00
Overrides the tag option. Default: the repository default branch.
2023-09-16 14:16:19 -04:00
\E [ 1m-t\E [ 0m| \E [ 1m--tag\E [ 0m <tag_name> Use specified tag when installing and updating the module. Over-
2021-11-08 20:05:32 -05:00
rides the branch option.
2024-02-16 20:41:29 -05:00
\E [ 1m-u\E [ 0m| \E [ 1m--use\E [ 0m <tool_name> Install and update the module using the defined tool. Default is
either defined by \E [ 1mzstyle \' :zim:zmodule\' use \' \E [ 0m<tool_name>\E [ 1m\' \E [ 0m, or \E [ 1mgit\E [ 0m
if none is provided. The tools available are:
\E [ 1mgit\E [ 0m uses the git command. Local changes are preserved on updates.
\E [ 1mdegit\E [ 0m uses curl or wget, and currently only works with GitHub
2021-11-08 20:05:32 -05:00
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
2024-02-16 20:41:29 -05:00
\E [ 1mmkdir\E [ 0m creates an empty directory. The <url> is only used to set
the module name. Use the \E [ 1m-c\E [ 0m| \E [ 1m--cmd\E [ 0m or \E [ 1m--on-pull\E [ 0m options to execute
the desired command to generate the module files.
2023-09-16 14:16:19 -04:00
\E [ 1m--no-submodules\E [ 0m Don\' t install or update git submodules.
\E [ 1m-z\E [ 0m| \E [ 1m--frozen\E [ 0m Don\' t install or update the module.
2022-09-26 21:33:49 -04:00
The per-module options above are carried over multiple zmodule calls for the same module.
Modules are uniquely identified by their name.
Per-module-root options:
2023-09-16 14:16:19 -04:00
\E [ 1m--if\E [ 0m <test> Will only initialize module root if specified test returns a zero
2022-12-18 15:58:30 -05:00
exit status. The test is evaluated at every new terminal startup.
2024-02-16 20:41:29 -05:00
\E [ 1m--if-command\E [ 0m <cmd_name> Will only initialize module root if specified external command is
2024-01-22 21:36:17 -05:00
available. This is evaluated at every new terminal startup.
2024-02-16 20:41:29 -05:00
Equivalent to \E [ 1m--if \' ( ( \$ { +commands[ \E [ 0m<cmd_name>\E [ 1m] } ) ) \' \E [ 0m.
2023-09-16 14:16:19 -04:00
\E [ 1m--on-pull\E [ 0m <command> Execute command after installing or updating the module. The com-
2022-05-07 17:31:08 -04:00
mand is executed in the module root directory.
2023-09-16 14:16:19 -04:00
\E [ 1m-d\E [ 0m| \E [ 1m--disabled\E [ 0m Don\' t initialize the module root or uninstall the module.
2022-09-26 21:33:49 -04:00
The per-module-root options above are carried over multiple zmodule calls for the same mod-
ule root.
Per-call initialization options:
2023-09-16 14:16:19 -04:00
\E [ 1m-f\E [ 0m| \E [ 1m--fpath\E [ 0m <path> Will add specified path to fpath. The path is relative to the
module root directory. Default: \E [ 1mfunctions\E [ 0m, if the subdirectory
2022-09-26 21:33:49 -04:00
exists and is non-empty.
2023-09-16 14:16:19 -04:00
\E [ 1m-a\E [ 0m| \E [ 1m--autoload\E [ 0m <func_name> Will autoload specified function . Default: all valid names inside
the \E [ 1mfunctions\E [ 0m subdirectory, if any.
\E [ 1m-s\E [ 0m| \E [ 1m--source\E [ 0m <file_path> Will source specified file. The path is relative to the module
root directory. Default: \E [ 1minit.zsh\E [ 0m, if a non-empty \E [ 1mfunctions\E [ 0m sub-
2022-09-26 21:33:49 -04:00
directory exists, else the largest of the files matching the glob
2023-09-16 14:16:19 -04:00
\E [ 1m( init.zsh| \E [ 0m<name>\E [ 1m.( zsh| plugin.zsh| zsh-theme| sh) ) \E [ 0m, if any.
2022-10-06 20:52:57 -04:00
<name> in the glob is resolved to the last component of the mod-
ule name, or the last component of the path to the module root.
2023-09-16 14:16:19 -04:00
\E [ 1m-c\E [ 0m| \E [ 1m--cmd\E [ 0m <command> Will execute specified command. Occurrences of the \E [ 1m{ } \E [ 0m placeholder
2022-09-26 21:33:49 -04:00
in the command are substituted by the module root directory path.
2023-09-16 14:16:19 -04:00
I.e., \E [ 1m-s \' foo.zsh\' \E [ 0m and \E [ 1m-c \' source { } /foo.zsh\' \E [ 0m are equivalent.
2021-09-26 20:47:44 -04:00
2022-09-26 21:33:49 -04:00
Setting any per-call initialization option above will disable the default values from the
other per-call initialization options, so only your provided values will be used. I.e. these
values are either all automatic, or all manual in each zmodule call. To use default values
2023-09-16 14:16:19 -04:00
and also provided values, use separate zmodule calls.'
2022-10-23 20:34:14 -04:00
if [ [ ${ ${ funcfiletrace [1]% : * } : A } != ${ ztarget : A } ] ] ; then
2023-09-16 14:16:19 -04:00
print -u2 -lR $'\E[31m' ${ 0 } $': Must be called from \E[1m' ${ ztarget } $'\E[0m' '' ${ zusage }
2021-03-19 18:13:21 -04:00
return 2
2019-12-01 16:00:47 -05:00
fi
if ( ( ! # )); then
2023-09-16 14:16:19 -04:00
print -u2 -lR $'\E[31mx ' ${ funcfiletrace [1] } $': Missing zmodule url\E[0m' '' ${ zusage }
2019-12-01 16:00:47 -05:00
_zfailed = 1
2021-03-19 18:13:21 -04:00
return 2
2019-12-01 16:00:47 -05:00
fi
2022-09-26 21:33:49 -04:00
local zurl = ${ 1 } zname = ${ 1 : t } zroot zarg
2022-05-17 19:43:59 -04:00
local -a zfpaths zfunctions zcmds
2019-12-01 16:00:47 -05:00
if [ [ ${ zurl } = ~ ^[ ^:/] +: ] ] ; then
2022-05-17 19:43:59 -04:00
zname = ${ zname %.git }
2019-12-01 16:00:47 -05:00
elif [ [ ${ zurl } != /* ] ] ; then
# Count number of slashes
case ${# zurl //[^ \/ ]/ } in
2021-09-23 15:29:40 -04:00
0) zurl = https://github.com/zimfw/${ zurl } .git ; ;
1) zurl = https://github.com/${ zurl } .git ; ;
2019-12-01 16:00:47 -05:00
esac
fi
shift
2022-09-26 21:33:49 -04:00
while [ [ ${ 1 } = = ( -n| --name| -r| --root) ] ] ; do
2019-12-01 16:00:47 -05:00
if ( ( # < 2 )); then
2023-09-16 14:16:19 -04:00
print -u2 -lR $'\E[31mx ' ${ funcfiletrace [1] } $':\E[1m' ${ zname } $':\E[0;31m Missing argument for zmodule option \E[1m' ${ 1 } $'\E[0m' '' ${ zusage }
2019-12-01 16:00:47 -05:00
_zfailed = 1
2021-03-19 18:13:21 -04:00
return 2
2019-01-22 19:40:43 -05:00
fi
2022-09-26 21:33:49 -04:00
case ${ 1 } in
-n| --name)
shift
zname = ${ ${ 1 %%/## } ##/## }
; ;
-r| --root)
shift
zroot = ${ ${ 1 %%/## } ##/## }
; ;
esac
2019-12-01 16:00:47 -05:00
shift
2022-05-17 19:43:59 -04:00
done
2020-06-05 23:09:23 -04:00
if [ [ ${ zurl } = = /* ] ] ; then
2022-05-17 19:43:59 -04:00
_zdirs[ ${ zname } ] = ${ zurl %%/## }
2021-09-23 15:29:40 -04:00
zurl =
2020-06-05 23:09:23 -04:00
else
2022-05-17 19:43:59 -04:00
_zdirs[ ${ zname } ] = ${ ZIM_HOME } /modules/${ zname }
fi
2022-09-26 21:33:49 -04:00
if [ [ ${ +_zurls[ ${ zname } ] } -ne 0 && ${ _zurls [ ${ zname } ] } != ${ zurl } ] ] ; then
2023-09-16 14:16:19 -04:00
print -u2 -lR $'\E[31mx ' ${ funcfiletrace [1] } $':\E[1m' ${ zname } $':\E[0;31m Module already defined with a different URL. Expected \E[1m' ${ _zurls [ ${ zname } ] } $'\E[0m' '' ${ zusage }
2022-09-26 21:33:49 -04:00
_zfailed = 1
return 2
fi
2022-05-17 19:43:59 -04:00
_zurls[ ${ zname } ] = ${ zurl }
2022-09-26 21:33:49 -04:00
local -r zroot_dir = ${ _zdirs [ ${ zname } ] } ${ zroot : +/ ${ zroot } }
_zroot_dirs += ( ${ zroot_dir } )
2022-05-17 19:43:59 -04:00
# Set default values
if ( ( ! ${ +_ztools[ ${ zname } ] } ) ) ; then
zstyle -s ':zim:zmodule' use " _ztools[ ${ zname } ] " || _ztools[ ${ zname } ] = git
2020-06-05 23:09:23 -04:00
fi
2022-05-17 19:43:59 -04:00
if ( ( ! ${ +_ztypes[ ${ zname } ] } ) ) _ztypes[ ${ zname } ] = branch
if ( ( ! ${ +_zsubmodules[ ${ zname } ] } ) ) _zsubmodules[ ${ zname } ] = 1
# Set values from options
2019-12-01 16:00:47 -05:00
while ( ( # > 0 )); do
case ${ 1 } in
2024-01-22 21:36:17 -05:00
-b| --branch| -t| --tag| -u| --use| --on-pull| --if| --if-command| -f| --fpath| -a| --autoload| -s| --source| -c| --cmd)
2019-12-01 16:00:47 -05:00
if ( ( # < 2 )); then
2023-09-16 14:16:19 -04:00
print -u2 -lR $'\E[31mx ' ${ funcfiletrace [1] } $':\E[1m' ${ zname } $':\E[0;31m Missing argument for zmodule option \E[1m' ${ 1 } $'\E[0m' '' ${ zusage }
2019-12-01 16:00:47 -05:00
_zfailed = 1
2021-03-19 18:13:21 -04:00
return 2
2019-12-01 16:00:47 -05:00
fi
; ;
esac
2021-09-19 14:37:13 -04:00
case ${ 1 } in
2022-01-25 09:32:50 -05:00
-b| --branch| -t| --tag| -u| --use| --no-submodules)
2023-09-16 14:16:19 -04:00
if [ [ -z ${ zurl } ] ] _zimfw_print -u2 -R $'\E[33m! ' ${ funcfiletrace [1] } $':\E[1m' ${ zname } $':\E[0;33m The zmodule option \E[1m' ${ 1 } $'\E[0;33m has no effect for external modules\E[0m'
2021-09-19 14:37:13 -04:00
; ;
esac
2019-12-01 16:00:47 -05:00
case ${ 1 } in
-b| --branch)
shift
2022-05-17 19:43:59 -04:00
_ztypes[ ${ zname } ] = branch
_zrevs[ ${ zname } ] = ${ 1 }
2019-12-01 16:00:47 -05:00
; ;
-t| --tag)
shift
2022-05-17 19:43:59 -04:00
_ztypes[ ${ zname } ] = tag
_zrevs[ ${ zname } ] = ${ 1 }
2019-12-01 16:00:47 -05:00
; ;
2021-04-03 10:35:28 -04:00
-u| --use)
shift
2022-05-17 19:43:59 -04:00
_ztools[ ${ zname } ] = ${ 1 }
2021-04-03 10:35:28 -04:00
; ;
2022-05-17 19:43:59 -04:00
--no-submodules) _zsubmodules[ ${ zname } ] = 0 ; ;
-z| --frozen) _zfrozens[ ${ zname } ] = 1 ; ;
2022-05-07 17:31:08 -04:00
--on-pull)
shift
2022-09-26 21:33:49 -04:00
zarg = ${ 1 }
if [ [ -n ${ zroot } ] ] zarg = " (builtin cd -q ${ zroot } ; ${ zarg } ) "
_zonpulls[ ${ zname } ] = " ${ _zonpulls [ ${ zname } ]+ ${ _zonpulls [ ${ zname } ] } ; } ${ zarg } "
2022-05-07 17:31:08 -04:00
; ;
2022-10-06 20:52:57 -04:00
--if)
shift
_zifs[ ${ zroot_dir } ] = ${ 1 }
; ;
2024-01-22 21:36:17 -05:00
--if-command)
shift
_zifs[ ${ zroot_dir } ] = " (( \${+commands[ ${ 1 } ]} )) "
; ;
2019-12-01 16:00:47 -05:00
-f| --fpath)
shift
zarg = ${ 1 }
2022-09-26 21:33:49 -04:00
if [ [ ${ zarg } != /* ] ] zarg = ${ zroot_dir } /${ zarg }
2019-12-01 16:00:47 -05:00
zfpaths += ( ${ zarg } )
; ;
-a| --autoload)
shift
zfunctions += ( ${ 1 } )
; ;
-s| --source)
shift
zarg = ${ 1 }
2022-09-26 21:33:49 -04:00
if [ [ ${ zarg } != /* ] ] zarg = ${ zroot_dir } /${ zarg }
2024-06-17 08:22:18 -04:00
zcmds += ( 'source ' ${ (qqq)zarg : a } )
2020-07-02 18:16:44 -04:00
; ;
-c| --cmd)
shift
2024-06-17 08:22:18 -04:00
zcmds += ( ${ 1 //{ } /${ (qqq)zroot_dir : a } } )
2019-12-01 16:00:47 -05:00
; ;
2022-09-26 21:33:49 -04:00
-d| --disabled) _zdisabled_root_dirs += ( ${ zroot_dir } ) ; ;
2019-12-01 16:00:47 -05:00
*)
2023-09-16 14:16:19 -04:00
print -u2 -lR $'\E[31mx ' ${ funcfiletrace [1] } $':\E[1m' ${ zname } $':\E[0;31m Unknown zmodule option \E[1m' ${ 1 } $'\E[0m' '' ${ zusage }
2019-12-01 16:00:47 -05:00
_zfailed = 1
2021-03-19 18:13:21 -04:00
return 2
2019-12-01 16:00:47 -05:00
; ;
esac
shift
2019-01-22 19:40:43 -05:00
done
2021-09-19 14:37:13 -04:00
if ( ( _zflags & 1 ) ) ; then
2022-05-17 19:43:59 -04:00
_znames += ( ${ zname } )
2021-09-19 14:37:13 -04:00
fi
if ( ( _zflags & 2 ) ) ; then
2022-09-26 21:33:49 -04:00
if [ [ ! -e ${ zroot_dir } ] ] ; then
2023-09-16 14:16:19 -04:00
print -u2 -R $'\E[31mx ' ${ funcfiletrace [1] } $':\E[1m' ${ zname } ': ' ${ zroot_dir } $'\E[0;31m not found\E[0m'
2022-09-26 21:33:49 -04:00
_zfailed = 1
return 1
fi
if ( ( ! ${# zfpaths } && ! ${# zfunctions } && ! ${# zcmds } ) ) ; then
zfpaths = ( ${ zroot_dir } /functions( NF) )
# _* functions are autoloaded by compinit
# prompt_*_setup functions are autoloaded by promptinit
zfunctions = ( ${ ^zfpaths } /^( *~| *.zwc( | .old) | _*| prompt_*_setup) ( N-.:t) )
local -ra prezto_scripts = ( ${ zroot_dir } /init.zsh( N) )
if ( ( ${# zfpaths } && ${# prezto_scripts } ) ) ; then
# this follows the prezto module format, no need to check for other scripts
2024-06-17 08:22:18 -04:00
zcmds = ( 'source ' ${ (qqq)^prezto_scripts : a } )
2022-09-26 21:33:49 -04:00
else
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first)
2022-10-06 20:52:57 -04:00
local -ra zscripts = ( ${ zroot_dir } /( init.zsh| ( ${ zname : t } | ${ zroot_dir : t } ) .( zsh| plugin.zsh| zsh-theme| sh) ) ( NOL[ 1] ) )
2024-06-17 08:22:18 -04:00
zcmds = ( 'source ' ${ (qqq)^zscripts : a } )
2020-05-25 15:01:00 -04:00
fi
2019-12-01 16:00:47 -05:00
fi
2022-09-26 21:33:49 -04:00
if ( ( ! ${# zfpaths } && ! ${# zfunctions } && ! ${# zcmds } ) ) ; then
2023-09-16 14:16:19 -04:00
_zimfw_print -u2 -lR $'\E[33m! ' ${ funcfiletrace [1] } $':\E[1m' ${ zname } $':\E[0;33m Nothing found to be initialized. Customize the module name, root or initialization with \E[1mzmodule\E[0;33m options.\E[0m' '' ${ zusage }
2022-09-26 21:33:49 -04:00
fi
# Prefix is added to all _zfpaths, _zfunctions and _zcmds to distinguish the originating root dir
local -r zpre = ${ zroot_dir } $'\0'
_zfpaths += ( ${ zpre } ${ ^zfpaths } )
_zfunctions += ( ${ zpre } ${ ^zfunctions } )
2024-06-17 08:22:18 -04:00
zcmds = ( ${ zcmds // ${ HOME } / \$ {HOME } } )
2022-09-26 21:33:49 -04:00
_zcmds += ( ${ zpre } ${ ^zcmds } )
2019-12-01 16:00:47 -05:00
fi
}
2024-05-30 10:15:05 -04:00
{
local -r ztarget = ${ ZIM_CONFIG_FILE :- ${ ZDOTDIR :- ${ HOME } } /.zimrc } _zflags = ${ 1 }
local -i _zfailed = 0
if ! source ${ ztarget } || ( ( _zfailed ) ) ; then
print -u2 -R $'\E[31mFailed to source \E[1m' ${ ztarget } $'\E[0m'
return 1
fi
if ( ( _zflags & 1 && ${# _znames } = = 0 ) ) ; then
print -u2 -R $'\E[31mNo modules defined in \E[1m' ${ ztarget } $'\E[0m'
return 1
fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre
for zroot_dir in ${ _zdisabled_root_dirs } ; do
zpre = ${ zroot_dir } $'\0'
_zfpaths = ( ${ _zfpaths : # ${ zpre } * } )
_zfunctions = ( ${ _zfunctions : # ${ zpre } * } )
_zcmds = ( ${ _zcmds : # ${ zpre } * } )
done
} always {
unfunction zmodule
}
2019-01-22 19:40:43 -05:00
}
2021-09-19 14:37:13 -04:00
_zimfw_list_unuseds( ) {
local -i i = 1
2022-09-26 21:33:49 -04:00
local zinstalled = ( ${ ZIM_HOME } /modules/*( N/) )
local -r zdirs = ( ${ (v)_zdirs } )
2021-09-19 14:37:13 -04:00
# Search into subdirectories
while ( ( i <= ${# zinstalled } ) ) ; do
2022-09-26 21:33:49 -04:00
if ( ( ${ zdirs [(I) ${ zinstalled [i] } /*] } ) ) ; then
2021-09-23 12:36:38 -04:00
zinstalled += ( ${ zinstalled [i] } /*( N/) )
2021-09-19 14:37:13 -04:00
zinstalled[ i] = ( )
else
( ( i++ ) )
fi
done
2022-09-26 21:33:49 -04:00
# Unused = all installed dirs not in zdirs
_zunused_dirs = ( ${ zinstalled : |zdirs } )
2021-09-19 14:37:13 -04:00
local zunused
2023-09-16 14:16:19 -04:00
for zunused ( ${ _zunused_dirs } ) _zimfw_print -R $'\E[1m' ${ zunused : t } $':\E[0m ' ${ zunused } ${ 1 }
2021-09-19 14:37:13 -04:00
}
2023-03-26 10:34:07 -04:00
_zimfw_check_dumpfile( ) {
2023-09-16 14:16:19 -04:00
_zimfw_print -u2 $'\E[33m! Deprecated action. This is now handled by the completion module alone.\E[0m'
2023-03-26 10:34:07 -04:00
}
_zimfw_check_version( ) {
2023-06-16 21:24:33 -04:00
if ( ( ${ 1 } ) ) ; then
if ( ( ${ 2 } ) ) ; then
# background check
if [ [ -w ${ _zversion_target : h } ] ] ; then
2023-09-15 20:55:43 -04:00
print -R ${ ${ ${ (f) " $( GIT_HTTP_LOW_SPEED_LIMIT = 1000 GIT_HTTP_LOW_SPEED_TIME = 30 command git ls-remote --tags --refs --sort= -v:refname \
2023-06-16 21:24:33 -04:00
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null) " }##*v}[1]} >! ${ _zversion_target } &!
fi
else
# foreground check
local tags
2023-09-15 20:55:43 -04:00
tags = $( command git ls-remote --tags --refs --sort= -v:refname https://github.com/zimfw/zimfw.git 'v*' ) || return 1
>! ${ _zversion_target } <<< ${ ${ ${ (f)tags } ##*v } [1] } || return 1
2023-06-16 21:24:33 -04:00
fi
2023-03-24 09:40:55 -04:00
fi
2023-06-16 21:24:33 -04:00
if [ [ -f ${ _zversion_target } ] ] ; then
local -r zlatest_version = $( <${ _zversion_target } )
if [ [ -n ${ zlatest_version } && ${ _zversion } != ${ zlatest_version } ] ] ; then
2023-09-16 14:16:19 -04:00
_zimfw_print -u2 -R $'\E[33mLatest zimfw version is \E[1m' ${ zlatest_version } $'\E[0;33m. You\'re using version \E[1m' ${ _zversion } $'\E[0;33m. Run \E[1mzimfw upgrade\E[0;33m to upgrade.\E[0m'
2023-06-16 21:24:33 -04:00
return 4
fi
2020-01-15 12:35:30 -05:00
fi
}
2019-01-22 19:40:43 -05:00
_zimfw_clean_compiled( ) {
2020-07-31 22:03:47 -04:00
# Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once.
2023-03-30 09:38:12 -04:00
local -Ur zscriptdirs = ( ${ ZIM_HOME : A } ${ ${ (v)_zdirs## ${ ZIM_HOME : A } /* } : A } )
2019-12-27 09:51:02 -05:00
local zopt
2021-09-23 15:29:40 -04:00
if ( ( _zprintlevel > 0 ) ) zopt = -v
2022-01-18 20:34:36 -05:00
command rm -f ${ zopt } ${ ^zscriptdirs } /**/*.zwc( | .old) ( N) && \
2023-09-16 14:16:19 -04:00
_zimfw_print $'Done with clean-compiled. Restart your terminal or run \E[1mzimfw compile\E[0m to re-compile.'
2019-01-22 19:40:43 -05:00
}
_zimfw_clean_dumpfile( ) {
2019-12-01 16:00:47 -05:00
local zdumpfile zopt
2019-12-14 22:21:34 -05:00
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile = ${ ZDOTDIR :- ${ HOME } } /.zcompdump
2021-09-23 15:29:40 -04:00
if ( ( _zprintlevel > 0 ) ) zopt = -v
2023-02-25 19:03:37 -05:00
command rm -f ${ zopt } ${ zdumpfile } ( | .dat| .zwc( | .old) ) ( N) && \
2023-09-16 14:16:19 -04:00
_zimfw_print -R " Done with clean-dumpfile. ${ _zrestartmsg } "
2019-01-22 19:40:43 -05:00
}
2019-12-14 22:21:34 -05:00
_zimfw_compile( ) {
2023-09-16 14:16:19 -04:00
# Compile zimfw scripts
2022-09-26 21:33:49 -04:00
local zroot_dir zfile
for zroot_dir in ${ _zroot_dirs : |_zdisabled_root_dirs } ; do
2023-06-15 10:26:37 -04:00
if [ [ ! -w ${ zroot_dir } ] ] ; then
2023-09-16 14:16:19 -04:00
_zimfw_print -R $'\E[33m! \E[1m' ${ zroot_dir } $':\E[0;33m No write permission, unable to compile.\E[0m'
2023-06-15 10:26:37 -04:00
continue
fi
2022-09-26 21:33:49 -04:00
for zfile in ${ zroot_dir } /( ^*test*/) #*.zsh(|-theme)(N-.); do
if [ [ ! ${ zfile } .zwc -nt ${ zfile } ] ] ; then
2023-09-16 14:16:19 -04:00
zcompile -UR ${ zfile } && _zimfw_print -R $'\E[32m)\E[0m \E[1m' ${ zfile } $'.zwc:\E[0m Compiled'
2022-09-26 21:33:49 -04:00
fi
done
2022-01-10 09:29:32 -05:00
done
2023-09-16 14:16:19 -04:00
_zimfw_print 'Done with compile.'
2019-12-14 22:21:34 -05:00
}
2019-01-22 19:40:43 -05:00
_zimfw_info( ) {
2024-06-25 10:08:10 -04:00
print -R 'zimfw version: ' ${ _zversion } ' (built at 2024-06-25 14:06:08 UTC, previous commit is 0785d87)'
2023-03-24 10:46:44 -04:00
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 }
done
2019-01-22 19:40:43 -05:00
}
2019-12-10 18:19:01 -05:00
_zimfw_uninstall( ) {
2021-09-19 14:37:13 -04:00
local zopt
2021-09-23 15:29:40 -04:00
if ( ( _zprintlevel > 0 ) ) zopt = -v
2021-09-23 12:36:38 -04:00
if ( ( ${# _zunused_dirs } ) ) ; then
if ( ( _zprintlevel <= 0 ) ) || read -q " ?Uninstall ${# _zunused_dirs } module(s) listed above [y/N]? " ; then
2020-10-26 20:32:25 -04:00
_zimfw_print
2021-09-23 12:36:38 -04:00
command rm -rf ${ zopt } ${ _zunused_dirs } || return 1
2019-12-10 18:19:01 -05:00
fi
2020-10-26 20:32:25 -04:00
fi
2023-09-16 14:16:19 -04:00
_zimfw_print 'Done with uninstall.'
2019-12-10 18:19:01 -05:00
}
2019-01-22 19:40:43 -05:00
_zimfw_upgrade( ) {
2024-06-25 10:08:10 -04:00
local -r ztarget = ${ __ZIMFW_FILE : A } zurl = https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
if [ [ ! -w ${ ztarget : h } ] ] ; then
print -u2 -R $'\E[31mNo write permission to \E[1m' ${ ztarget : h } $'\E[0;31m. Will not try to upgrade.\E[0m'
2024-06-18 18:13:53 -04:00
return 1
fi
2019-12-01 16:00:47 -05:00
{
2020-01-11 16:35:59 -05:00
if ( ( ${ +commands[curl] } ) ) ; then
2020-07-23 22:49:39 -04:00
command curl -fsSL -o ${ ztarget } .new.gz ${ zurl } || return 1
2020-01-11 16:35:59 -05:00
else
2020-01-11 16:23:11 -05:00
local zopt
2021-09-23 15:29:40 -04:00
if ( ( _zprintlevel <= 1 ) ) zopt = -q
2020-07-23 22:49:39 -04:00
if ! command wget -nv ${ zopt } -O ${ ztarget } .new.gz ${ zurl } ; then
2021-04-03 10:35:28 -04:00
if ( ( _zprintlevel <= 1 ) ) ; then
2023-09-16 14:16:19 -04:00
print -u2 -R $'\E[31mFailed to download \E[1m' ${ zurl } $'\E[0;31m. Use \E[1m-v\E[0;31m option to see details.\E[0m'
2021-04-03 10:35:28 -04:00
fi
2020-01-11 16:23:11 -05:00
return 1
fi
2019-12-01 16:00:47 -05:00
fi
2020-07-23 22:49:39 -04:00
command gunzip -f ${ ztarget } .new.gz || return 1
2020-01-20 07:03:20 -05:00
# .latest_version can be outdated and will yield a false warning if zimfw is
# upgraded before .latest_version is refreshed. Bad thing about having a cache.
_zimfw_mv ${ ztarget } { .new,} && command rm -f ${ ZIM_HOME } /.latest_version && \
2023-09-16 14:16:19 -04:00
_zimfw_print 'Done with upgrade.'
2019-12-01 16:00:47 -05:00
} always {
2020-07-23 22:49:39 -04:00
command rm -f ${ ztarget } .new{ ,.gz}
2019-12-01 16:00:47 -05:00
}
2019-01-22 19:40:43 -05:00
}
2021-09-19 14:37:13 -04:00
_zimfw_run_list( ) {
2022-05-17 19:43:59 -04:00
local -r zname = ${ 1 }
2022-09-26 21:33:49 -04:00
local -r zdir = ${ _zdirs [ ${ zname } ] }
2023-09-16 14:16:19 -04:00
print -nR $'\E[1m' ${ zname } $':\E[0m ' ${ zdir }
2022-09-26 21:33:49 -04:00
if [ [ -z ${ _zurls [ ${ zname } ] } ] ] print -n ' (external)'
if ( ( ${ _zfrozens [ ${ zname } ] } ) ) print -n ' (frozen)'
if ( ( ${ _zdisabled_root_dirs [(I) ${ zdir } ] } ) ) print -n ' (disabled)'
2021-09-29 22:22:28 -04:00
print
2021-09-19 14:37:13 -04:00
if ( ( _zprintlevel > 1 ) ) ; then
2022-05-17 19:43:59 -04:00
if [ [ ${ _zfrozens [ ${ zname } ] } -eq 0 && -n ${ _zurls [ ${ zname } ] } ] ] ; then
print -nR " From: ${ _zurls [ ${ zname } ] } , "
if [ [ -z ${ _zrevs [ ${ zname } ] } ] ] ; then
2021-09-19 14:37:13 -04:00
print -n 'default branch'
else
2022-05-17 19:43:59 -04:00
print -nR " ${ _ztypes [ ${ zname } ] } ${ _zrevs [ ${ zname } ] } "
2021-09-19 14:37:13 -04:00
fi
2022-05-17 19:43:59 -04:00
print -nR " , using ${ _ztools [ ${ zname } ] } "
2022-09-26 21:33:49 -04:00
if ( ( ! _zsubmodules[ ${ zname } ] ) ) print -n ', no git submodules'
2022-01-25 09:32:50 -05:00
print
2022-05-17 19:43:59 -04:00
if [ [ -n ${ _zonpulls [ ${ zname } ] } ] ] print -R " On-pull: ${ _zonpulls [ ${ zname } ] } "
2021-09-19 14:37:13 -04:00
fi
2022-09-26 21:33:49 -04:00
# Match the current module dir prefix from _zroot_dirs
local -r zroot_dirs = ( ${ (M)_zroot_dirs : # ${ zdir } /* } )
if ( ( ${# zroot_dirs } ) ) ; then
print ' Additional root:'
local zroot_dir
for zroot_dir in ${ zroot_dirs } ; do
print -nR " ${ zroot_dir } "
if ( ( ${ _zdisabled_root_dirs [(I) ${ zroot_dir } ] } ) ) print -n ' (disabled)'
print
done
fi
# Match and remove the prefix from _zfpaths, _zfunctions and _zcmds
2022-09-28 20:42:05 -04:00
local -r zpre = " ${ (q)zdir } (|/*) " $'\0'
2022-09-26 21:33:49 -04:00
local -r zfpaths = ( ${ ${ (M)_zfpaths : # ${ ~zpre } * } # ${ ~zpre } } ) zfunctions = ( ${ ${ (M)_zfunctions : # ${ ~zpre } * } # ${ ~zpre } } ) zcmds = ( ${ ${ (M)_zcmds : # ${ ~zpre } * } # ${ ~zpre } } )
2022-01-11 11:29:47 -05:00
if ( ( ${# zfpaths } ) ) print -R ' fpath: ' ${ zfpaths }
if ( ( ${# zfunctions } ) ) print -R ' autoload: ' ${ zfunctions }
if ( ( ${# zcmds } ) ) print -R ' cmd: ' ${ (j : ; : )zcmds }
2021-09-19 14:37:13 -04:00
fi
}
2024-02-16 20:41:29 -05:00
_zimfw_create_dir( ) {
if ! ERR = $( command mkdir -p ${ 1 } 2>& 1) ; then
_zimfw_print_error " Error creating ${ 1 } " ${ ERR }
return 1
fi
}
2023-03-28 08:56:37 -04:00
_zimfw_print_error( ) {
2023-09-16 14:16:19 -04:00
print -u2 -lR $'\E[2K\r\E[31mx \E[1m' ${ _zname } $':\E[0;31m ' ${ 1 } $'\E[0m' ${ 2 : + ${ (F) :- ${ (f)^2 } } }
2021-04-03 10:35:28 -04:00
}
2023-03-28 08:56:37 -04:00
_zimfw_print_okay( ) {
2023-09-16 14:16:19 -04:00
if ( ( _zprintlevel > ${ 2 :- 0 } ) ) print -lR $'\E[2K\r\E[32m)\E[0m \E[1m' ${ _zname } $':\E[0m ' ${ 1 } ${ 3 : + ${ (F) :- ${ (f)^3 } } }
2022-05-07 17:31:08 -04:00
}
2024-02-16 20:41:29 -05:00
_zimfw_print_warn( ) {
_zimfw_print -u2 -R $'\E[2K\r\E[33m! \E[1m' ${ _zname } $':\E[0;33m ' ${ 1 } $'\E[0m'
}
2023-03-28 08:56:37 -04:00
_zimfw_pull_print_okay( ) {
2023-03-31 21:23:01 -04:00
# Useb by tools, which run in a subshell
if [ [ -n ${ ONPULL } ] ] ; then
if ! ERR = $( builtin cd -q ${ DIR } 2>& 1 && builtin eval ${ ONPULL } 2>& 1) ; then
_zimfw_print_error 'Error during on-pull' ${ ERR }
2022-05-07 17:31:08 -04:00
return 1
2023-03-31 21:23:01 -04:00
elif [ [ ${ _zprintlevel } -gt 1 && -n ${ ERR } ] ] ; then
2023-03-28 08:56:37 -04:00
# Overrides ${3} to include the on-pull output, to be used by _zimfw_print_okay below.
2023-03-31 21:23:01 -04:00
builtin set ${ 1 } ${ 2 :- 0 } ${ 3 : + ${ 3 } $'\n' } 'On-pull output:' $'\n' ${ ERR }
2021-04-03 10:35:28 -04:00
fi
fi
2023-03-28 08:56:37 -04:00
_zimfw_print_okay " ${ @ } "
2021-04-03 10:35:28 -04:00
}
2023-03-28 08:56:37 -04:00
_zimfw_download_tarball( ) {
2023-03-31 21:23:01 -04:00
if [ [ ${ URL } = ~ ^( [ ^:@/] +://) ?( [ ^@] +@) ?( [ ^:/] +) [ :/] ( [ ^/] +/[ ^/] +) /?$ ] ] ; then
readonly HOST = ${ match [3] }
readonly REPO = ${ match [4]%.git }
2021-04-03 10:35:28 -04:00
fi
2023-03-31 21:23:01 -04:00
if [ [ ${ HOST } != github.com || -z ${ REPO } ] ] ; then
2024-05-30 10:34:43 -04:00
_zimfw_print_error ${ URL } $' is not a valid URL. Will not try to ' ${ _zaction } $'. The zimfw degit tool only supports GitHub URLs. Use zmodule option \E[1m--use git\E[0;31m to use git instead.'
2021-04-03 10:35:28 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
readonly HEADERS_TARGET = ${ DIR } /${ TEMP } _headers
2021-04-03 10:35:28 -04:00
{
2023-03-31 21:23:01 -04:00
if [ [ -r ${ INFO_TARGET } ] ] ; then
readonly INFO = ( " ${ (@f) " $( <${ INFO_TARGET } ) " } " )
if [ [ ${ URL } != ${ INFO [1] } ] ] ; then
2024-05-30 10:34:43 -04:00
_zimfw_print_error " The zimfw degit URL does not match. Expected ${ URL } . Will not try to ${ _zaction } . "
2021-04-03 10:35:28 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
# Previous REV is in line 2, reserved for future use.
readonly INFO_HEADER = ${ INFO [3] }
2021-04-03 10:35:28 -04:00
fi
2023-03-31 21:23:01 -04:00
readonly TARBALL_URL = https://api.github.com/repos/${ REPO } /tarball/${ REV }
2023-03-28 08:56:37 -04:00
if [ [ ${ _zaction } = = check ] ] ; then
2023-03-31 21:23:01 -04:00
if [ [ -z ${ INFO_HEADER } ] ] return 0
2023-03-28 08:56:37 -04:00
if ( ( ${ +commands[curl] } ) ) ; then
2023-03-31 21:23:01 -04:00
command curl -IfsL -H ${ INFO_HEADER } ${ TARBALL_URL } >${ HEADERS_TARGET }
2023-03-26 10:34:07 -04:00
else
2023-03-31 21:23:01 -04:00
command wget --spider -qS --header= ${ INFO_HEADER } ${ TARBALL_URL } 2>${ HEADERS_TARGET }
2021-04-03 10:35:28 -04:00
fi
else
2023-03-28 08:56:37 -04:00
if ( ( ${ +commands[curl] } ) ) ; then
2023-03-31 21:23:01 -04:00
if ! ERR = $( command curl -fsSL ${ INFO_HEADER : +-H } ${ INFO_HEADER } -o ${ TARBALL_TARGET } -D ${ HEADERS_TARGET } ${ TARBALL_URL } 2>& 1) ; then
_zimfw_print_error " Error downloading ${ TARBALL_URL } with curl " ${ ERR }
2023-03-26 10:34:07 -04:00
return 1
fi
else
# wget returns 8 when 304 Not Modified, so we cannot use wget's error codes
2023-03-31 21:23:01 -04:00
command wget -qS ${ INFO_HEADER : +--header= ${ INFO_HEADER } } -O ${ TARBALL_TARGET } ${ TARBALL_URL } 2>${ HEADERS_TARGET }
2023-03-26 10:34:07 -04:00
fi
2021-04-03 10:35:28 -04:00
fi
2023-03-31 21:23:01 -04:00
while IFS = read -r HEADER; do
HEADER = ${ ${ HEADER ## ## } %% $'\r' ## }
if [ [ ${ HEADER } = = HTTP/* ] ] ; then
HTTP_CODE = ${ ${ (s : : )HEADER } [2] }
elif [ [ ${ ${ (L)HEADER%% : * } %% ## } = = etag ] ] ; then
ETAG = ${ ${ HEADER #* : } ## ## }
2021-04-03 10:35:28 -04:00
fi
2023-03-31 21:23:01 -04:00
done < ${ HEADERS_TARGET }
if ( ( HTTP_CODE = = 304 ) ) ; then
2021-04-03 10:35:28 -04:00
# Not Modified
2023-03-31 21:23:01 -04:00
command rm -f ${ TARBALL_TARGET } 2>/dev/null
2021-04-03 10:35:28 -04:00
return 0
2023-03-31 21:23:01 -04:00
elif ( ( HTTP_CODE != 200 ) ) ; then
_zimfw_print_error " Error downloading ${ TARBALL_URL } , HTTP code ${ HTTP_CODE } "
2021-04-03 10:35:28 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
if [ [ -z ${ ETAG } ] ] ; then
_zimfw_print_error " Error downloading ${ TARBALL_URL } , no ETag header found in response "
2021-04-03 10:35:28 -04:00
return 1
fi
2023-03-28 08:56:37 -04:00
if [ [ ${ _zaction } = = check ] ] ; then
2023-03-31 21:23:01 -04:00
command touch ${ TARBALL_TARGET } # Update available
2023-03-26 10:34:07 -04:00
else
2023-03-31 21:23:01 -04:00
if ! print -lR " ${ URL } " " ${ REV } " " If-None-Match: ${ ETAG } " >! ${ INFO_TARGET } 2>/dev/null; then
_zimfw_print_error " Error creating or updating ${ INFO_TARGET } "
2023-03-26 10:34:07 -04:00
return 1
fi
2021-04-03 10:35:28 -04:00
fi
} always {
2023-03-31 21:23:01 -04:00
command rm -f ${ HEADERS_TARGET } 2>/dev/null
2021-04-03 10:35:28 -04:00
}
}
2023-03-28 08:56:37 -04:00
_zimfw_untar_tarball( ) {
2024-04-28 15:05:03 -04:00
if ! ERR = $( command tar -C ${ 1 } -xzf ${ TARBALL_TARGET } 2>& 1) ; then
2023-03-31 21:23:01 -04:00
_zimfw_print_error " Error extracting ${ TARBALL_TARGET } " ${ ERR }
2021-04-03 10:35:28 -04:00
return 1
fi
2024-04-28 15:05:03 -04:00
local zsubdir
for zsubdir in ${ 1 } /*( /) ; do
if ! ERR = $( command mv -f ${ zsubdir } /*( DN) ${ 1 } 2>& 1 && command rmdir ${ zsubdir } 2>& 1) ; then
_zimfw_print_error " Error moving ${ zsubdir } " ${ ERR }
return 1
fi
done
2021-04-03 10:35:28 -04:00
}
2023-03-28 08:56:37 -04:00
_zimfw_tool_degit( ) {
2023-03-31 21:23:01 -04:00
# This runs in a subshell
readonly -i SUBMODULES = ${ 5 }
readonly DIR = ${ 1 } URL = ${ 2 } REV = ${ 4 } ONPULL = ${ 6 } TEMP = .zdegit_${ sysparams [pid] }
readonly TARBALL_TARGET = ${ DIR } /${ TEMP } _tarball.tar.gz INFO_TARGET = ${ DIR } /.zdegit
2023-03-28 08:56:37 -04:00
case ${ _zaction } in
install)
{
2023-03-31 21:23:01 -04:00
_zimfw_create_dir ${ DIR } && _zimfw_download_tarball && _zimfw_untar_tarball ${ DIR } && _zimfw_pull_print_okay Installed || return 1
2023-03-28 08:56:37 -04:00
} always {
# return 1 does not change ${TRY_BLOCK_ERROR}, only changes ${?}
( ( TRY_BLOCK_ERROR = ? ) )
2023-03-31 21:23:01 -04:00
command rm -f ${ TARBALL_TARGET } 2>/dev/null
if ( ( TRY_BLOCK_ERROR ) ) command rm -rf ${ DIR } 2>/dev/null
2023-03-28 08:56:37 -04:00
}
; ;
check| update)
2023-03-31 21:23:01 -04:00
if [ [ ! -r ${ INFO_TARGET } ] ] ; then
2024-02-16 20:41:29 -05:00
_zimfw_print_warn $'Module was not installed using zimfw\'s degit. Will not try to ' ${ _zaction } $'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.'
2023-03-28 08:56:37 -04:00
return 0
2021-10-19 09:36:51 -04:00
fi
2023-03-31 21:23:01 -04:00
readonly DIR_NEW = ${ DIR } ${ TEMP }
2023-03-28 08:56:37 -04:00
{
_zimfw_download_tarball || return 1
if [ [ ${ _zaction } = = check ] ] ; then
2023-03-31 21:23:01 -04:00
if [ [ -e ${ TARBALL_TARGET } ] ] ; then
2023-03-28 08:56:37 -04:00
_zimfw_print_okay 'Update available'
return 4
fi
_zimfw_print_okay 'Already up to date' 1
return 0
2023-03-26 10:34:07 -04:00
else
2023-03-31 21:23:01 -04:00
if [ [ -e ${ TARBALL_TARGET } ] ] ; then
_zimfw_create_dir ${ DIR_NEW } && _zimfw_untar_tarball ${ DIR_NEW } || return 1
2023-03-28 08:56:37 -04:00
if ( ( ${ +commands[diff] } ) ) ; then
2023-03-31 21:23:01 -04:00
LOG = $( command diff -x '.zdegit*' -x '*.zwc' -x '*.zwc.old' -qr ${ DIR } ${ DIR_NEW } 2>/dev/null)
LOG = ${ ${ LOG // ${ DIR_NEW } /new } // ${ DIR } /old }
2023-03-28 08:56:37 -04:00
fi
2023-03-31 21:23:01 -04:00
if ! ERR = $( { command cp -f ${ INFO_TARGET } ${ DIR_NEW } && \
command rm -rf ${ DIR } && command mv -f ${ DIR_NEW } ${ DIR } } 2>& 1) ; then
_zimfw_print_error " Error updating ${ DIR } " ${ ERR }
2023-03-28 08:56:37 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
_zimfw_pull_print_okay Updated 0 ${ LOG } || return 1
2023-03-28 08:56:37 -04:00
else
_zimfw_pull_print_okay 'Already up to date' || return 1
fi
2023-03-26 10:34:07 -04:00
fi
2023-03-28 08:56:37 -04:00
} always {
2023-03-31 21:23:01 -04:00
command rm -f ${ TARBALL_TARGET } 2>/dev/null
command rm -rf ${ DIR_NEW } 2>/dev/null
2023-03-28 08:56:37 -04:00
}
; ;
esac
# Check after successful install or update
2024-02-16 20:41:29 -05:00
if [ [ ${ SUBMODULES } -ne 0 && -e ${ DIR } /.gitmodules ] ] ; then
_zimfw_print_warn $'Module contains git submodules, which are not supported by zimfw\'s degit. Use zmodule option \E[1m--no-submodules\E[0;33m to disable this warning.'
2022-05-07 17:31:08 -04:00
fi
}
2023-03-28 08:56:37 -04:00
_zimfw_tool_git( ) {
2023-03-31 21:23:01 -04:00
# This runs in a subshell
readonly -i SUBMODULES = ${ 5 }
readonly DIR = ${ 1 } URL = ${ 2 } TYPE = ${ 3 } ONPULL = ${ 6 }
REV = ${ 4 }
2023-03-28 08:56:37 -04:00
case ${ _zaction } in
install)
2023-03-31 21:23:01 -04:00
if ERR = $( command git clone ${ REV : +-b } ${ REV } -q --config core.autocrlf= false ${ ${ SUBMODULES : #0 } : +--recursive } -- ${ URL } ${ DIR } 2>& 1) ; then
2023-03-28 08:56:37 -04:00
_zimfw_pull_print_okay Installed
else
2023-03-31 21:23:01 -04:00
_zimfw_print_error 'Error during git clone' ${ ERR }
2023-03-28 08:56:37 -04:00
return 1
2021-10-19 09:36:51 -04:00
fi
2023-03-28 08:56:37 -04:00
; ;
check| update)
2023-03-31 21:23:01 -04:00
if [ [ ! -r ${ DIR } /.git ] ] ; then
2024-02-16 20:41:29 -05:00
_zimfw_print_warn 'Module was not installed using git. Will not try to ' ${ _zaction } $'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.'
2023-03-28 08:56:37 -04:00
return 0
fi
2023-03-31 21:23:01 -04:00
if [ [ ${ URL } != $( command git -C ${ DIR } config --get remote.origin.url) ] ] ; then
2024-05-30 10:34:43 -04:00
_zimfw_print_error " The git URL does not match. Expected ${ URL } . Will not try to ${ _zaction } . "
2023-03-28 08:56:37 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
if ! ERR = $( command git -C ${ DIR } fetch -pqt origin 2>& 1) ; then
_zimfw_print_error 'Error during git fetch' ${ ERR }
2023-03-28 08:56:37 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
if [ [ ${ TYPE } = = branch ] ] ; then
if [ [ -z ${ REV } ] ] ; then
2023-03-28 08:56:37 -04:00
# Get HEAD remote branch
2023-03-31 21:23:01 -04:00
if ! ERR = $( command git -C ${ DIR } remote set-head origin -a 2>& 1) ; then
_zimfw_print_error 'Error during git remote set-head' ${ ERR }
2023-03-28 08:56:37 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
if REV = $( command git -C ${ DIR } symbolic-ref --short refs/remotes/origin/HEAD 2>& 1) ; then
REV = ${ REV #origin/ }
2023-03-28 08:56:37 -04:00
else
2023-03-31 21:23:01 -04:00
_zimfw_print_error 'Error during git symbolic-ref' ${ REV }
2023-03-28 08:56:37 -04:00
return 1
fi
2023-03-26 10:34:07 -04:00
fi
2023-03-31 21:23:01 -04:00
TO_REV = ${ REV } @{ u}
2023-03-28 08:56:37 -04:00
if [ [ ${ _zaction } = = check ] ] ; then
2023-03-31 21:23:01 -04:00
readonly -i BEHIND = $( command git -C ${ DIR } rev-list --count ${ REV } ..${ TO_REV } -- 2>/dev/null)
if ( ( BEHIND ) ) ; then
_zimfw_print_okay " Update available [behind ${ BEHIND } ] "
2023-03-28 08:56:37 -04:00
return 4
else
_zimfw_print_okay 'Already up to date' 1
return 0
fi
fi
else
2023-03-31 21:23:01 -04:00
if [ [ ${ REV } = = $( command git -C ${ DIR } describe --tags --exact-match 2>/dev/null) ] ] ; then
2023-03-28 08:56:37 -04:00
if [ [ ${ _zaction } = = check ] ] ; then
_zimfw_print_okay 'Already up to date' 1
return 0
else
_zimfw_pull_print_okay 'Already up to date'
return ${ ? }
fi
fi
if [ [ ${ _zaction } = = check ] ] ; then
_zimfw_print_okay 'Update available'
return 4
fi
2023-03-31 21:23:01 -04:00
TO_REV = ${ REV }
2021-04-03 10:35:28 -04:00
fi
2023-03-31 21:23:01 -04:00
LOG = $( command git -C ${ DIR } log --graph --color --format= '%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${ TO_REV } -- 2>/dev/null)
if ! ERR = $( command git -C ${ DIR } checkout -q ${ REV } -- 2>& 1) ; then
_zimfw_print_error 'Error during git checkout' ${ ERR }
2023-03-28 08:56:37 -04:00
return 1
fi
2023-03-31 21:23:01 -04:00
if [ [ ${ TYPE } = = branch ] ] ; then
if ! OUT = $( command git -C ${ DIR } merge --ff-only --no-progress -n 2>& 1) ; then
_zimfw_print_error 'Error during git merge' ${ OUT }
2023-03-28 08:56:37 -04:00
return 1
2023-03-26 10:34:07 -04:00
fi
2023-03-31 21:23:01 -04:00
# keep just first line of OUT
OUT = ${ OUT %%( $'\n' | $'\r' )* }
2023-03-28 08:56:37 -04:00
else
2023-03-31 21:23:01 -04:00
OUT = " Updating to ${ TYPE } ${ REV } "
2021-11-15 19:37:40 -05:00
fi
2023-03-31 21:23:01 -04:00
if ( ( SUBMODULES ) ) ; then
if ! ERR = $( command git -C ${ DIR } submodule update --init --recursive -q -- 2>& 1) ; then
_zimfw_print_error 'Error during git submodule update' ${ ERR }
2023-03-28 08:56:37 -04:00
return 1
2023-03-26 10:34:07 -04:00
fi
fi
2023-03-31 21:23:01 -04:00
_zimfw_pull_print_okay ${ OUT } 0 ${ LOG }
2023-03-28 08:56:37 -04:00
; ;
esac
}
2024-02-16 20:41:29 -05:00
_zimfw_tool_mkdir( ) {
# This runs in a subshell
readonly -i SUBMODULES = ${ 5 }
readonly DIR = ${ 1 } TYPE = ${ 3 } REV = ${ 4 } ONPULL = ${ 6 }
if [ [ -n ${ REV } ] ] ; then
_zimfw_print_warn $'The zmodule option \E[1m-' ${ TYPE [1] } $'\E[0;33m|\E[1m--' ${ TYPE } $'\E[0;33m has no effect when using the mkdir tool'
fi
if ( ( ! SUBMODULES ) ) ; then
_zimfw_print_warn $'The zmodule option \E[1m--no-submodules\E[0;33m has no effect when using the mkdir tool'
fi
if [ [ ! -d ${ DIR } || -n ${ ONPULL } ] ] ; then
_zimfw_create_dir ${ DIR } && _zimfw_pull_print_okay Created || return 1
fi
}
2023-03-28 08:56:37 -04:00
_zimfw_run_tool( ) {
local -r _zname = ${ 1 }
if [ [ -z ${ _zurls [ ${ _zname } ] } ] ] ; then
_zimfw_print_okay 'Skipping external module' 1
return 0
fi
if ( ( _zfrozens[ ${ _zname } ] ) ) ; then
_zimfw_print_okay 'Skipping frozen module' 1
return 0
fi
case ${ _zaction } in
install)
if [ [ -e ${ _zdirs [ ${ _zname } ] } ] ] ; then
_zimfw_print_okay 'Skipping already installed module' 1
2023-03-26 10:34:07 -04:00
return 0
fi
2023-09-16 14:16:19 -04:00
_zimfw_print -nR $'\E[2K\rInstalling ' ${ _zname } ' ...'
2023-03-28 08:56:37 -04:00
; ;
check| update)
if [ [ ! -d ${ _zdirs [ ${ _zname } ] } ] ] ; then
2023-09-16 14:16:19 -04:00
_zimfw_print_error $'Not installed. Run \E[1mzimfw install\E[0;31m to install.'
2021-04-03 10:35:28 -04:00
return 1
fi
2023-03-28 08:56:37 -04:00
if [ [ ${ _zaction } = = check ] ] ; then
2023-09-16 14:16:19 -04:00
if ( ( _zprintlevel > 1 ) ) print -nR $'\E[2K\rChecking ' ${ _zname } ' ...'
2023-03-28 08:56:37 -04:00
else
2023-09-16 14:16:19 -04:00
_zimfw_print -nR $'\E[2K\rUpdating ' ${ _zname } ' ...'
2021-11-10 22:50:17 -05:00
fi
2023-03-28 08:56:37 -04:00
; ;
*)
_zimfw_print_error " Unknown action ${ _zaction } "
return 1
; ;
esac
local -r ztool = ${ _ztools [ ${ _zname } ] }
case ${ ztool } in
2024-02-16 20:41:29 -05:00
degit| git| mkdir)
2023-03-28 08:56:37 -04:00
_zimfw_tool_${ ztool } " ${ _zdirs [ ${ _zname } ] } " " ${ _zurls [ ${ _zname } ] } " " ${ _ztypes [ ${ _zname } ] } " " ${ _zrevs [ ${ _zname } ] } " " ${ _zsubmodules [ ${ _zname } ] } " " ${ _zonpulls [ ${ _zname } ] } "
; ;
2021-04-03 10:35:28 -04:00
*)
2023-03-28 08:56:37 -04:00
_zimfw_print_error " Unknown tool ${ ztool } "
2021-04-03 10:35:28 -04:00
return 1
; ;
esac
}
2023-03-26 10:34:07 -04:00
_zimfw_run_tool_action( ) {
2023-03-28 08:56:37 -04:00
local -r _zaction = ${ 1 }
2024-06-21 16:43:48 -04:00
_zimfw_source_zimrc 1 || return 1
zargs -n 1 -P 0 -- " ${ _znames [@] } " -- _zimfw_run_tool
2023-03-26 10:34:07 -04:00
return 0
}
2019-01-22 19:40:43 -05:00
zimfw( ) {
2022-01-10 20:41:50 -05:00
builtin emulate -L zsh -o EXTENDED_GLOB
2024-06-21 16:43:48 -04:00
local -r _zversion = '1.14.0-SNAPSHOT' zusage = $'Usage: \E[1m' ${ 0 } $' \E [ 0m <action> [ \E [ 1m-q\E [ 0m| \E [ 1m-v\E [ 0m]
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
\E [ 1mbuild\E [ 0m Build \E [ 1m'${ZIM_HOME}$' /init.zsh\E [ 0m and \E [ 1m'${ZIM_HOME}$' /login_init.zsh\E [ 0m.
Also does \E [ 1mcompile\E [ 0m. Use \E [ 1m-v\E [ 0m to also see its output.
\E [ 1mclean\E [ 0m Clean all. Does both \E [ 1mclean-compiled\E [ 0m and \E [ 1mclean-dumpfile\E [ 0m.
\E [ 1mclean-compiled\E [ 0m Clean Zsh compiled files.
\E [ 1mclean-dumpfile\E [ 0m Clean completion dumpfile.
\E [ 1mcompile\E [ 0m Compile Zsh files.
\E [ 1mhelp\E [ 0m Print this help.
\E [ 1minfo\E [ 0m Print zimfw and system info.
\E [ 1mlist\E [ 0m List all modules currently defined in \E [ 1m'${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc}$' \E [ 0m.
Use \E [ 1m-v\E [ 0m to also see the modules details.
\E [ 1minit\E [ 0m Same as \E [ 1minstall\E [ 0m, but with output tailored to be used at terminal startup.
\E [ 1minstall\E [ 0m Install new modules. Also does \E [ 1mbuild\E [ 0m, \E [ 1mcompile\E [ 0m. Use \E [ 1m-v\E [ 0m 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
\E [ 1muninstall\E [ 0m Delete unused modules. Prompts for confirmation. Use \E [ 1m-q\E [ 0m for quiet uninstall.
\E [ 1mcheck\E [ 0m Check if updates for current modules are available. Use \E [ 1m-v\E [ 0m 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
\E [ 1mupdate\E [ 0m Update current modules. Also does \E [ 1mbuild\E [ 0m, \E [ 1mcompile\E [ 0m. Use \E [ 1m-v\E [ 0m 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
\E [ 1mcheck-version\E [ 0m Check if a new version of zimfw is available.
\E [ 1mupgrade\E [ 0m Upgrade zimfw. Also does \E [ 1mcompile\E [ 0m. Use \E [ 1m-v\E [ 0m to also see its output.
\E [ 1mversion\E [ 0m Print zimfw version.
2019-12-01 16:00:47 -05:00
Options:
2023-09-16 14:16:19 -04:00
\E [ 1m-q\E [ 0m Quiet ( yes to prompts and only outputs errors)
\E [ 1m-v\E [ 0m 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 $'\E[31m' ${ 0 } $': Too many options\E[0m' '' ${ 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 $'\E[31m' ${ 0 } ': Unknown option ' ${ 2 } $'\E[0m' '' ${ 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
2024-06-21 16:43:48 -04:00
local -r _zversion_target = ${ ZIM_HOME } /.latest_version
2024-06-18 18:40:12 -04:00
if ! zstyle -t ':zim' disable-version-check && \
2024-06-25 10:08:10 -04:00
[ [ ${ 1 } != check-version && -w ${ ZIM_HOME } && -w ${ __ZIMFW_FILE : A : h } ] ]
2024-06-18 18:40:12 -04:00
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
2024-06-21 16:43:48 -04:00
if [ [ ! -w ${ ZIM_HOME } && ${ 1 } = = ( build| check| init| install| update| check-version) ] ] ; then
print -u2 -R $'\E[31m' ${ 0 } $': No write permission to \E[1m' ${ ZIM_HOME } $'\E[0;31m. Will not try to ' ${ 1 } $'.\E[0m'
return 1
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 $'\E[31m' ${ 0 } ': Unknown action ' ${ 1 } $'\E[0m' '' ${ zusage }
2021-03-19 18:13:21 -04:00
return 2
2019-01-22 19:40:43 -05:00
; ;
esac
}
2024-05-30 10:15:05 -04:00
zimfw " ${ @ } "