Compare commits

...

22 Commits

Author SHA1 Message Date
Eric Nielsen 4200e6cdb3
v1.13.1 2024-04-28 14:07:41 -05:00
Eric Nielsen c86223f473
Don't use tar --strip
as it's not compatible with BSD distributions.
Fixes #534
2024-04-28 14:06:24 -05:00
Eric Nielsen 39d2087ad4
v1.13.0 2024-02-16 21:06:36 -05:00
Eric Nielsen 2e9256a567
Add new mkdir tool to generate empty modules
This will allow creating modules that contain only externally generated
files. For example, this is how I currently use it to generate modules
for code that is supposed to be eval'ed:

    zmodule-eval() {
      local -r zcommand=${${=1}[1]} ztarget=${1//[^[:alnum:]]/-}.zsh
      zmodule custom-${zcommand} --use mkdir --if-command ${zcommand} \
          --cmd "if [[ ! {}/${ztarget} -nt \${commands[${zcommand}]} ]]; then ${1} >! {}/${ztarget}; zcompile -UR {}/${ztarget}; fi" \
          --source ${ztarget}
    }
    zmodule-eval 'starship init zsh'
    unfunction zmodule-eval
2024-02-16 20:41:29 -05:00
Eric Nielsen 8bec2f7549
Add `--if-command` option to `zmodule` 2024-01-22 21:36:17 -05:00
Eric Nielsen 5f649d3031
v1.12.1 2023-09-16 13:26:53 -05:00
Eric Nielsen 26151d2f54
Remove prompt expansion from print statements
and replace the foreground color and bold expansions by ANSI escape
codes. This should make the print calls now safe and no expansion at all
should happen as we're using `-R` -- unless the `-e` flag is given.
Fixes #521. Closes #522
2023-09-16 13:21:14 -05:00
Eric Nielsen d33d632ec1
Use `--sort=-v:refname` in _zimfw_check_version
to sort tags, instead of using Zsh's `(On)`. The tags will come sorted
already.
2023-09-15 19:55:43 -05:00
Eric Nielsen e0d067977c
v1.12.0 2023-07-17 18:55:26 -05:00
Eric Nielsen 49386cad6d
Make forced check-version asynchronous (again)
as it was before a34b8dab64.
Don't make zimfw hang in the foreground waiting for git to connect to
GitHub, mainly because the waiting can take too long in case of
connection issues or no network. Also set git timeout to 30 seconds so
background check also does hang for too long, just it case.

Fixes #514
2023-06-16 20:24:33 -05:00
Eric Nielsen 0566b9b8a3
Use _zimfw_print 2023-06-15 09:33:14 -05:00
alesandar f9648e07a9
Handle module root directories without write permission
Closes #513. Fixes #512
2023-06-15 09:26:37 -05:00
Eric Nielsen db96076cf0
fixup! Don't use a new shell to run tool anymore 2023-04-01 08:31:09 -05:00
Eric Nielsen f93e43e8a5
Tools run in a subshell 2023-03-31 20:34:26 -05:00
Eric Nielsen 67de6ec25b
Don't resolve symlinks when building init.zsh
So init.zsh is consistent after symlinks change to point to something
else. See zimfw/completion#15
2023-03-30 08:38:12 -05:00
Eric Nielsen ee93f7944f
Don't use a new shell to run tool anymore
This was needed when we were using xargs, but we're already using zargs
instead for quite some time. Pro is that now common functions are reused
instead of repeated. Con (or change) is that due to that reuse, and in
favor of simplification, the warning for a module with git submodules in
degit is in a separate line from a separate print call now.

Also fix regressions from recent commits:
- Need to call _zimfw_source_zimrc twice with 1 and 2 flags instead of
  with flag 3, since flag 2 must be used after module is installed or
  updated.
- Need to call _zimfw_print_okay from the function that handles on-pull,
  since we want to include the on-pull output in verbose mode. This
  function was called just `handle` before, now it's called
  _zimfw_pull_print_okay.

Still need to figure out how to return a final error code from
_zimfw_run_tool_action.
2023-03-28 07:56:37 -05:00
Eric Nielsen 312b08c20a
Fix missing -C in command git 2023-03-26 16:51:24 -05:00
Eric Nielsen 903e0e5249
Add check and rename version-check to check-version
actions. Return 4 if there's a zimfw update from check-version. Don't
return a specific error code if there are module updates from check, as
it uses zargs to check all and each check runs in a separate shell. Need
to figure out how to propagate all that to a final error code.

See #503
2023-03-26 09:34:07 -05:00
Eric Nielsen b7b33f3786
Also output LANG LC_* parameters in info action 2023-03-24 09:46:44 -05:00
Eric Nielsen a34b8dab64
Add version-check action
And don't run the dumping of the .latest_version file in
_zimfw_version_check in the background (with `&!`) anymore.

See #503
2023-03-24 08:44:52 -05:00
Eric Nielsen 222c971542
v1.11.3 2023-02-25 19:44:58 -05:00
Eric Nielsen 6a24459de9
Deprecate check-dumpfile action
The completion module alone will handle checking the dumpfile.
See https://github.com/zimfw/completion/pull/12
2023-02-25 19:03:37 -05:00
39 changed files with 1016 additions and 869 deletions

View File

@ -9,6 +9,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_No unreleased changes._
## [1.13.1] - 2024-04-28
### Fixed
- The `--strip` option in tar command is not BSD compatible.
## [1.13.0] - 2024-02-17
### Added
- `--if-command` option to zmodule. This option is equivalent to
`--if "(( \${+commands[${1}]} ))"`.
- `mkdir` tool option in `zmodule` that creates an empty directory. This allows
creating modules that contain only externally generated files.
## [1.12.1] - 2023-09-16
### Fixed
- Expansion of prompt sequences in print statements causing text between
backticks to be executed by the shell.
## [1.12.0] - 2023-07-17
### Added
- `check-version` action, that immediately checks if a new version of `zimfw` is
available and returns code 4 if there is one.
- `check` action, that checks if there are updates available for current modules.
- Output of `LANG` and `LC_*` parameters in `info` action.
### Changed
- Don't resolve symlinks when building init.zsh.
### Fixed
- Show warning when there's no write permission to compile Zsh scripts.
## [1.11.3] - 2023-02-26
### Deprecated
- `check-dumpfile` action. The [completion] module alone now handles
checking the dumpfile. (See
[zimfw/completion#12](https://github.com/zimfw/completion/pull/12))
## [1.11.2] - 2023-02-16
### Fixed
@ -321,6 +368,7 @@ Take your time to review the updated [README.md] and the changes listed below.
- `ZIM_HOME` is set in .zshenv instead of .zshrc. The issue was that the
variable was not available in .zlogin in non-interactive login shells.
[completion]: https://github.com/zimfw/completion
[README.md]: https://github.com/zimfw/zimfw/blob/master/README.md
[environment]: https://github.com/zimfw/environment
[input]: https://github.com/zimfw/input
@ -328,7 +376,11 @@ Take your time to review the updated [README.md] and the changes listed below.
[termtitle]: https://github.com/zimfw/termtitle
[s1ck94]: https://github.com/zimfw/s1ck94
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.11.2...HEAD
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.13.0...HEAD
[1.13.0]: https://github.com/zimfw/zimfw/compare/v1.12.1...v1.13.0
[1.12.1]: https://github.com/zimfw/zimfw/compare/v1.12.0...v1.12.1
[1.12.0]: https://github.com/zimfw/zimfw/compare/v1.11.3...v1.12.0
[1.11.3]: https://github.com/zimfw/zimfw/compare/v1.11.2...v1.11.3
[1.11.2]: https://github.com/zimfw/zimfw/compare/v1.11.1...v1.11.2
[1.11.1]: https://github.com/zimfw/zimfw/compare/v1.11.0...v1.11.1
[1.11.0]: https://github.com/zimfw/zimfw/compare/v1.10.0...v1.11.0

View File

@ -1,7 +1,7 @@
MIT License
Copyright (c) 2015-2016 Matt Hamilton and contributors
Copyright (c) 2016-2023 Eric Nielsen, Matt Hamilton and contributors
Copyright (c) 2016-2024 Eric Nielsen, Matt Hamilton and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -227,7 +227,7 @@ zation will be done in the same order it's defined.
<url> Module absolute path or repository URL. The following URL formats
are equivalent: <b>foo</b>, <b>zimfw/foo</b>, <b>https://github.com/zimfw/foo.git</b>.
If an absolute path is given, the module is considered externally
installed, and won&apos;t be installed or updated by zimfw.
installed and won&apos;t be installed or updated by zimfw.
<b>-n</b>|<b>--name</b> &lt;module_name&gt; Set a custom module name. Default: the last component in &lt;url&gt;.
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
@ -239,13 +239,16 @@ Per-module options:
Overrides the tag option. Default: the repository default branch.
<b>-t</b>|<b>--tag</b> &lt;tag_name&gt; Use specified tag when installing and updating the module. Over-
rides the branch option.
<b>-u</b>|<b>--use</b> &lt;<b>git</b>|<b>degit</b>&gt; Install and update the module using the defined tool. Default is
either defined by <b>zstyle &apos;:zim:zmodule&apos; use &apos;</b>&lt;<b>git</b>|<b>degit</b>&gt;<b>&apos;</b>, or <b>git</b>
if none is provided.
<b>git</b> requires git itself. Local changes are preserved on updates.
<b>degit</b> requires curl or wget, and currently only works with GitHub
<b>-u</b>|<b>--use</b> &lt;tool_name&gt; Install and update the module using the defined tool. Default is
either defined by <b>zstyle &apos;:zim:zmodule&apos; use &apos;</b>&lt;tool_name&gt;<b>&apos;</b>, or <b>git</b>
if none is provided. The tools available are:
<b>git</b> uses the git command. Local changes are preserved on updates.
<b>degit</b> uses curl or wget, and currently only works with GitHub
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
<b>mkdir</b> creates an empty directory. The &lt;url&gt; is only used to set
the module name. Use the <b>-c</b>|<b>--cmd</b> or <b>--on-pull</b> options to execute
the desired command to generate the module files.
<b>--no-submodules</b> Don&apos;t install or update git submodules.
<b>-z</b>|<b>--frozen</b> Don&apos;t install or update the module.
@ -255,6 +258,9 @@ Per-module options:
Per-module-root options:
<b>--if</b> &lt;test&gt; Will only initialize module root if specified test returns a zero
exit status. The test is evaluated at every new terminal startup.
<b>--if-command</b> &lt;cmd_name&gt; Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to <b>--if &apos;(( ${+commands[</b>&lt;cmd_name&gt;<b>]} ))&apos;</b>.
<b>--on-pull</b> &lt;command&gt; Execute command after installing or updating the module. The com-
mand is executed in the module root directory.
<b>-d</b>|<b>--disabled</b> Don&apos;t initialize the module root or uninstall the module.

View File

@ -1,8 +1,8 @@
autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then
print -u2 -PR "%F{red}${0}: Error starting Zim. You're using Zsh version %B${ZSH_VERSION}%b and versions < %B<%= min_zsh_version %>%b are not supported. Upgrade your Zsh.%f"
print -u2 -R $'<%= red %>'${0}$': Error starting zimfw. You\'re using Zsh version <%= bold %>'${ZSH_VERSION}$'<%= normalred %> and versions < <%= bold %><%= min_zsh_version %><%= normalred %> are not supported. Upgrade your Zsh.<%= normal %>'
return 1
fi
autoload -Uz zargs
# Define Zim location
if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:A:h}
# Define zimfw location
if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:h}

View File

@ -2,11 +2,11 @@ _zimfw_mv() {
local -a cklines
if cklines=(${(f)"$(command cksum ${1} ${2} 2>/dev/null)"}) && \
[[ ${${(z)cklines[1]}[1,2]} == ${${(z)cklines[2]}[1,2]} ]]; then
_zimfw_print -PR "<%= okay %>%B${2}:%b Already up to date"
_zimfw_print -R $'<%= okay %><%= bold %>'${2}$':<%= normal %> Already up to date'
else
if [[ -e ${2} ]]; then
command mv -f ${2}{,.old} || return 1
fi
command mv -f ${1} ${2} && _zimfw_print -PR "<%= okay %>%B${2}:%b Updated.${_zrestartmsg}"
command mv -f ${1} ${2} && _zimfw_print -R $'<%= okay %><%= bold %>'${2}$':<%= normal %> Updated.'${_zrestartmsg}
fi
}

View File

@ -22,7 +22,7 @@ _zimfw_build_init() {
fi
done
zpre=$'*\0'
if (( ${#_zfpaths} )) print 'fpath=('${(q-)${_zfpaths#${~zpre}}:A}' ${fpath})'
if (( ${#_zfpaths} )) print -R 'fpath=('${(q-)${_zfpaths#${~zpre}}:a}' ${fpath})'
if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}}
for zroot_dir in ${_zroot_dirs}; do
zpre=${zroot_dir}$'\0'

View File

@ -5,6 +5,6 @@ _zimfw_build_login_init() {
command mv -f ${ztarget}{,.old} || return 1
fi
_zimfw_mv =(
print -nR "<%= render_escaped("src/templates/login_init.zsh.erb") %>"
print '# Do nothing. This file is deprecated.'
) ${ztarget}
}

View File

@ -1,3 +1,3 @@
_zimfw_build() {
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P '<%= done %>Done with build.'
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
}

View File

@ -1,74 +1,80 @@
zmodule() {
local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc}
local -r zusage="Usage: %B${0}%b <url> [%B-n%b|%B--name%b <module_name>] [%B-r%b|%B--root%b <path>] [options]
local -r zusage=$'Usage: <%= bold %>'${0}$'<%= normal %> <url> [<%= bold %>-n<%= normal %>|<%= bold %>--name<%= normal %> <module_name>] [<%= bold %>-r<%= normal %>|<%= bold %>--root<%= normal %> <path>] [options]
Add %Bzmodule%b calls to your %B${ztarget}%b file to define the modules to be initialized.
The initialization will be done in the same order it's defined.
Add <%= bold %>zmodule<%= normal %> calls to your <%= bold %>'${ztarget}$'<%= normal %> file to define the modules to be initialized.
The initialization will be done in the same order it\'s defined.
<url> Module absolute path or repository URL. The following URL formats
are equivalent: %Bfoo%b, %Bzimfw/foo%b, %Bhttps://github.com/zimfw/foo.git%b.
are equivalent: <%= bold %>foo<%= normal %>, <%= bold %>zimfw/foo<%= normal %>, <%= bold %>https://github.com/zimfw/foo.git<%= normal %>.
If an absolute path is given, the module is considered externally
installed, and won't be installed or updated by zimfw.
%B-n%b|%B--name%b <module_name> Set a custom module name. Default: the last component in <url>.
installed and won\'t be installed or updated by zimfw.
<%= bold %>-n<%= normal %>|<%= bold %>--name<%= normal %> <module_name> Set a custom module name. Default: the last component in <url>.
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
%B${ZIM_HOME}/%b<module_name>.
%B-r%b|%B--root%b <path> Relative path to the module root.
<%= bold %>'${ZIM_HOME}$'/<%= normal %><module_name>.
<%= bold %>-r<%= normal %>|<%= bold %>--root<%= normal %> <path> Relative path to the module root.
Per-module options:
%B-b%b|%B--branch%b <branch_name> Use specified branch when installing and updating the module.
<%= bold %>-b<%= normal %>|<%= bold %>--branch<%= normal %> <branch_name> Use specified branch when installing and updating the module.
Overrides the tag option. Default: the repository default branch.
%B-t%b|%B--tag%b <tag_name> Use specified tag when installing and updating the module. Over-
<%= bold %>-t<%= normal %>|<%= bold %>--tag<%= normal %> <tag_name> Use specified tag when installing and updating the module. Over-
rides the branch option.
%B-u%b|%B--use%b <%%Bgit%b|%Bdegit%b> Install and update the module using the defined tool. Default is
either defined by %Bzstyle ':zim:zmodule' use '%b<%%Bgit%b|%Bdegit%b>%B'%b, or %Bgit%b
if none is provided.
%Bgit%b requires git itself. Local changes are preserved on updates.
%Bdegit%b requires curl or wget, and currently only works with GitHub
<%= bold %>-u<%= normal %>|<%= bold %>--use<%= normal %> <tool_name> Install and update the module using the defined tool. Default is
either defined by <%= bold %>zstyle \':zim:zmodule\' use \'<%= normal %><tool_name><%= bold %>\'<%= normal %>, or <%= bold %>git<%= normal %>
if none is provided. The tools available are:
<%= bold %>git<%= normal %> uses the git command. Local changes are preserved on updates.
<%= bold %>degit<%= normal %> uses curl or wget, and currently only works with GitHub
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
%B--no-submodules%b Don't install or update git submodules.
%B-z%b|%B--frozen%b Don't install or update the module.
<%= bold %>mkdir<%= normal %> creates an empty directory. The <url> is only used to set
the module name. Use the <%= bold %>-c<%= normal %>|<%= bold %>--cmd<%= normal %> or <%= bold %>--on-pull<%= normal %> options to execute
the desired command to generate the module files.
<%= bold %>--no-submodules<%= normal %> Don\'t install or update git submodules.
<%= bold %>-z<%= normal %>|<%= bold %>--frozen<%= normal %> Don\'t install or update the module.
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:
%B--if%b <test> Will only initialize module root if specified test returns a zero
<%= bold %>--if<%= normal %> <test> Will only initialize module root if specified test returns a zero
exit status. The test is evaluated at every new terminal startup.
%B--on-pull%b <command> Execute command after installing or updating the module. The com-
<%= bold %>--if-command<%= normal %> <cmd_name> Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to <%= bold %>--if \'(( \${+commands[<%= normal %><cmd_name><%= bold %>]} ))\'<%= normal %>.
<%= bold %>--on-pull<%= normal %> <command> Execute command after installing or updating the module. The com-
mand is executed in the module root directory.
%B-d%b|%B--disabled%b Don't initialize the module root or uninstall the module.
<%= bold %>-d<%= normal %>|<%= bold %>--disabled<%= normal %> Don\'t initialize the module root or uninstall the module.
The per-module-root options above are carried over multiple zmodule calls for the same mod-
ule root.
Per-call initialization options:
%B-f%b|%B--fpath%b <path> Will add specified path to fpath. The path is relative to the
module root directory. Default: %Bfunctions%b, if the subdirectory
<%= bold %>-f<%= normal %>|<%= bold %>--fpath<%= normal %> <path> Will add specified path to fpath. The path is relative to the
module root directory. Default: <%= bold %>functions<%= normal %>, if the subdirectory
exists and is non-empty.
%B-a%b|%B--autoload%b <func_name> Will autoload specified function. Default: all valid names inside
the %Bfunctions%b subdirectory, if any.
%B-s%b|%B--source%b <file_path> Will source specified file. The path is relative to the module
root directory. Default: %Binit.zsh%b, if a non-empty %Bfunctions%b sub-
<%= bold %>-a<%= normal %>|<%= bold %>--autoload<%= normal %> <func_name> Will autoload specified function. Default: all valid names inside
the <%= bold %>functions<%= normal %> subdirectory, if any.
<%= bold %>-s<%= normal %>|<%= bold %>--source<%= normal %> <file_path> Will source specified file. The path is relative to the module
root directory. Default: <%= bold %>init.zsh<%= normal %>, if a non-empty <%= bold %>functions<%= normal %> sub-
directory exists, else the largest of the files matching the glob
%B(init.zsh|%b<name>%B.(zsh|plugin.zsh|zsh-theme|sh))%b, if any.
<%= bold %>(init.zsh|<%= normal %><name><%= bold %>.(zsh|plugin.zsh|zsh-theme|sh))<%= normal %>, if any.
<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.
%B-c%b|%B--cmd%b <command> Will execute specified command. Occurrences of the %B{}%b placeholder
<%= bold %>-c<%= normal %>|<%= bold %>--cmd<%= normal %> <command> Will execute specified command. Occurrences of the <%= bold %>{}<%= normal %> placeholder
in the command are substituted by the module root directory path.
I.e., %B-s 'foo.zsh'%b and %B-c 'source {}/foo.zsh'%b are equivalent.
I.e., <%= bold %>-s \'foo.zsh\'<%= normal %> and <%= bold %>-c \'source {}/foo.zsh\'<%= normal %> are equivalent.
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
and also provided values, use separate zmodule calls."
and also provided values, use separate zmodule calls.'
if [[ ${${funcfiletrace[1]%:*}:A} != ${ztarget:A} ]]; then
print -u2 -PlR "%F{red}${0}: Must be called from %B${ztarget}%b%f" '' ${zusage}
print -u2 -lR $'<%= red %>'${0}$': Must be called from <%= bold %>'${ztarget}$'<%= normal %>' '' ${zusage}
return 2
fi
if (( ! # )); then
print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}: Missing zmodule url%f" '' ${zusage}
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$': Missing zmodule url<%= normal %>' '' ${zusage}
_zfailed=1
return 2
fi
@ -86,7 +92,7 @@ Per-call initialization options:
shift
while [[ ${1} == (-n|--name|-r|--root) ]]; do
if (( # < 2 )); then
print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zname}:%b Missing argument for zmodule option %B${1}%b%f" '' ${zusage}
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Missing argument for zmodule option <%= bold %>'${1}$'<%= normal %>' '' ${zusage}
_zfailed=1
return 2
fi
@ -109,7 +115,7 @@ Per-call initialization options:
_zdirs[${zname}]=${ZIM_HOME}/modules/${zname}
fi
if [[ ${+_zurls[${zname}]} -ne 0 && ${_zurls[${zname}]} != ${zurl} ]]; then
print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zname}:%b Module already defined with a different URL. Expected %B${_zurls[${zname}]}%b%f" '' ${zusage}
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Module already defined with a different URL. Expected <%= bold %>'${_zurls[${zname}]}$'<%= normal %>' '' ${zusage}
_zfailed=1
return 2
fi
@ -125,9 +131,9 @@ Per-call initialization options:
# Set values from options
while (( # > 0 )); do
case ${1} in
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|--if-command|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
if (( # < 2 )); then
print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zname}:%b Missing argument for zmodule option %B${1}%b%f" '' ${zusage}
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Missing argument for zmodule option <%= bold %>'${1}$'<%= normal %>' '' ${zusage}
_zfailed=1
return 2
fi
@ -135,7 +141,7 @@ Per-call initialization options:
esac
case ${1} in
-b|--branch|-t|--tag|-u|--use|--no-submodules)
if [[ -z ${zurl} ]] _zimfw_print -u2 -PR "%F{yellow}<%= warn %>${funcfiletrace[1]}:%B${zname}:%b The zmodule option %B${1}%b has no effect for external modules%f"
if [[ -z ${zurl} ]] _zimfw_print -u2 -R $'<%= yellow %><%= warn %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalyellow %> The zmodule option <%= bold %>'${1}$'<%= normalyellow %> has no effect for external modules<%= normal %>'
;;
esac
case ${1} in
@ -165,6 +171,10 @@ Per-call initialization options:
shift
_zifs[${zroot_dir}]=${1}
;;
--if-command)
shift
_zifs[${zroot_dir}]="(( \${+commands[${1}]} ))"
;;
-f|--fpath)
shift
zarg=${1}
@ -179,15 +189,15 @@ Per-call initialization options:
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zcmds+=("source ${(q-)zarg:A}")
zcmds+=("source ${(q-)zarg:a}")
;;
-c|--cmd)
shift
zcmds+=(${1//{}/${(q-)zroot_dir:A}})
zcmds+=(${1//{}/${(q-)zroot_dir:a}})
;;
-d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;;
*)
print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zname}:%b Unknown zmodule option %B${1}%b%f" '' ${zusage}
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Unknown zmodule option <%= bold %>'${1}$'<%= normal %>' '' ${zusage}
_zfailed=1
return 2
;;
@ -199,7 +209,7 @@ Per-call initialization options:
fi
if (( _zflags & 2 )); then
if [[ ! -e ${zroot_dir} ]]; then
print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zname}: ${zroot_dir}%b not found%f"
print -u2 -R $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}': '${zroot_dir}$'<%= normalred %> not found<%= normal %>'
_zfailed=1
return 1
fi
@ -211,15 +221,15 @@ Per-call initialization options:
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
zcmds=('source '${(q-)^prezto_scripts:A})
zcmds=('source '${(q-)^prezto_scripts:a})
else
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first)
local -ra zscripts=(${zroot_dir}/(init.zsh|(${zname:t}|${zroot_dir:t}).(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds=('source '${(q-)^zscripts:A})
zcmds=('source '${(q-)^zscripts:a})
fi
fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
_zimfw_print -u2 -PlR "%F{yellow}<%= warn %>${funcfiletrace[1]}:%B${zname}:%b Nothing found to be initialized. Customize the module name, root or initialization with %Bzmodule%b options.%f" '' ${zusage}
_zimfw_print -u2 -lR $'<%= yellow %><%= warn %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalyellow %> Nothing found to be initialized. Customize the module name, root or initialization with <%= bold %>zmodule<%= normalyellow %> options.<%= normal %>' '' ${zusage}
fi
# Prefix is added to all _zfpaths, _zfunctions and _zcmds to distinguish the originating root dir
local -r zpre=${zroot_dir}$'\0'

View File

@ -2,11 +2,11 @@ _zimfw_source_zimrc() {
local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -PR "%F{red}<%= failed %>Failed to source %B${ztarget}%b%f"
print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>'
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -PR "%F{red}<%= failed %>No modules defined in %B${ztarget}%b%f"
print -u2 -R $'<%= red %>No modules defined in <%= bold %>'${ztarget}$'<%= normal %>'
return 1
fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes

View File

@ -14,5 +14,5 @@ _zimfw_list_unuseds() {
# Unused = all installed dirs not in zdirs
_zunused_dirs=(${zinstalled:|zdirs})
local zunused
for zunused (${_zunused_dirs}) _zimfw_print -PR "%B${zunused:t}:%b ${zunused}${1}"
for zunused (${_zunused_dirs}) _zimfw_print -R $'<%= bold %>'${zunused:t}$':<%= normal %> '${zunused}${1}
}

View File

@ -1,18 +0,0 @@
_zimfw_version_check() {
if (( _zprintlevel > 0 )); then
local -r ztarget=${ZIM_HOME}/.latest_version
# If .latest_version does not exist or was not modified in the last 30 days
if [[ -w ${ztarget:h} && ! -f ${ztarget}(#qNm-30) ]]; then
# Get latest version (get all `v*` tags from repo, delete `*v` from beginning,
# sort in descending `O`rder `n`umerically, and get the `[1]` first)
print -R ${${(On)${(f)"$(command git ls-remote --tags --refs \
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${ztarget} &!
fi
if [[ -f ${ztarget} ]]; then
local -r zlatest_version=$(<${ztarget})
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
print -u2 -PlR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f" ''
fi
fi
fi
}

View File

@ -1,21 +1,3 @@
_zimfw_check_dumpfile() {
local zdumpfile zfpath zline
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
if [[ -e ${zdumpfile} ]]; then
if (( ${+_zim_dumpfile_fpath} )); then
local -r zcomps=(${^_zim_dumpfile_fpath}/^([^_]*|*~|*.zwc(|.old))(N:t))
IFS=$' \t' read -rA zline < ${zdumpfile} || return 1
if [[ ${zline[2]} -eq ${#zcomps} && ${zline[4]} == ${ZSH_VERSION} ]]; then
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b Already up to date"
else
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b New completion configuration needs to be dumped. Will do %Bclean-dumpfile%b."
_zimfw_clean_dumpfile
fi
else
_zimfw_print -u2 -PR "%F{yellow}<%= warn %>%B${zdumpfile}:%b Unable to check. This only works when the completion module is initialized."
fi
else
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b Not found"
fi
_zimfw_print 'Done with check-dumpfile.'
_zimfw_print -u2 $'<%= yellow %><%= warn %>Deprecated action. This is now handled by the completion module alone.<%= normal %>'
}

View File

@ -0,0 +1,23 @@
_zimfw_check_version() {
if (( ${1} )); then
if (( ${2} )); then
# background check
if [[ -w ${_zversion_target:h} ]]; then
print -R ${${${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs --sort=-v:refname \
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &!
fi
else
# foreground check
local tags
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
fi
fi
if [[ -f ${_zversion_target} ]]; then
local -r zlatest_version=$(<${_zversion_target})
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
_zimfw_print -u2 -R $'<%= yellow %>Latest zimfw version is <%= bold %>'${zlatest_version}$'<%= normalyellow %>. You\'re using version <%= bold %>'${_zversion}$'<%= normalyellow %>. Run <%= bold %>zimfw upgrade<%= normalyellow %> to upgrade.<%= normal %>'
return 4
fi
fi
}

View File

@ -1,8 +1,8 @@
_zimfw_clean_compiled() {
# Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once.
local -Ur zscriptdirs=(${ZIM_HOME} ${${(v)_zdirs##${ZIM_HOME}/*}:A})
local -Ur zscriptdirs=(${ZIM_HOME:A} ${${(v)_zdirs##${ZIM_HOME:A}/*}:A})
local zopt
if (( _zprintlevel > 0 )) zopt=-v
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) && \
_zimfw_print -P '<%= done %>Done with clean-compiled. Restart your terminal or run %Bzimfw compile%b to re-compile.'
_zimfw_print $'Done with clean-compiled. Restart your terminal or run <%= bold %>zimfw compile<%= normal %> to re-compile.'
}

View File

@ -2,6 +2,6 @@ _zimfw_clean_dumpfile() {
local zdumpfile zopt
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
if (( _zprintlevel > 0 )) zopt=-v
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) && \
_zimfw_print -P "<%= done %>Done with clean-dumpfile.${_zrestartmsg}"
command rm -f ${zopt} ${zdumpfile}(|.dat|.zwc(|.old))(N) && \
_zimfw_print -R "Done with clean-dumpfile.${_zrestartmsg}"
}

View File

@ -1,12 +1,16 @@
_zimfw_compile() {
# Compile Zim scripts
# Compile zimfw scripts
local zroot_dir zfile
for zroot_dir in ${_zroot_dirs:|_zdisabled_root_dirs}; do
if [[ ! -w ${zroot_dir} ]]; then
_zimfw_print -R $'<%= yellow %><%= warn %><%= bold %>'${zroot_dir}$':<%= normalyellow %> No write permission, unable to compile.<%= normal %>'
continue
fi
for zfile in ${zroot_dir}/(^*test*/)#*.zsh(|-theme)(N-.); do
if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then
zcompile -UR ${zfile} && _zimfw_print -PR "<%= okay %>%B${zfile}.zwc:%b Compiled"
zcompile -UR ${zfile} && _zimfw_print -R $'<%= okay %><%= bold %>'${zfile}$'.zwc:<%= normal %> Compiled'
fi
done
done
_zimfw_print -P '<%= done %>Done with compile.'
_zimfw_print 'Done with compile.'
}

View File

@ -1,9 +1,7 @@
_zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at <%= Time.now.utc %>, previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)'
print -R 'OSTYPE: '${OSTYPE}
print -R 'TERM: '${TERM}
print -R 'TERM_PROGRAM: '${TERM_PROGRAM}
print -R 'TERM_PROGRAM_VERSION: '${TERM_PROGRAM_VERSION}
print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'ZSH_VERSION: '${ZSH_VERSION}
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
}

View File

@ -1,7 +0,0 @@
_zimfw_install_update() {
local -r _zargs_action=${1}
_zimfw_source_zimrc 1 && zargs -n 1 -P 0 -- "${_znames[@]}" -- _zimfw_run_tool
# Ignore return from zargs with -P. Was missing values before zsh 5.9, and
# it's intermittently failing in zsh 5.9 and macOS. See https://www.zsh.org/mla/workers/2022/msg00611.html
return 0
}

View File

@ -7,5 +7,5 @@ _zimfw_uninstall() {
command rm -rf ${zopt} ${_zunused_dirs} || return 1
fi
fi
_zimfw_print -P '<%= done %>Done with uninstall.'
_zimfw_print 'Done with uninstall.'
}

View File

@ -8,7 +8,7 @@ _zimfw_upgrade() {
if (( _zprintlevel <= 1 )) zopt=-q
if ! command wget -nv ${zopt} -O ${ztarget}.new.gz ${zurl}; then
if (( _zprintlevel <= 1 )); then
print -u2 -PR "%F{red}<%= failed %>Failed to download %B${zurl}%b. Use %B-v%b option to see details.%f"
print -u2 -R $'<%= red %>Failed to download <%= bold %>'${zurl}$'<%= normalred %>. Use <%= bold %>-v<%= normalred %> option to see details.<%= normal %>'
fi
return 1
fi
@ -17,7 +17,7 @@ _zimfw_upgrade() {
# .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 && \
_zimfw_print -P '<%= done %>Done with upgrade.'
_zimfw_print 'Done with upgrade.'
} always {
command rm -f ${ztarget}.new{,.gz}
}

View File

@ -1,7 +1,7 @@
_zimfw_run_list() {
local -r zname=${1}
local -r zdir=${_zdirs[${zname}]}
print -PnR "%B${zname}:%b ${zdir}"
print -nR $'<%= bold %>'${zname}$':<%= normal %> '${zdir}
if [[ -z ${_zurls[${zname}]} ]] print -n ' (external)'
if (( ${_zfrozens[${zname}]} )) print -n ' (frozen)'
if (( ${_zdisabled_root_dirs[(I)${zdir}]} )) print -n ' (disabled)'

View File

@ -0,0 +1,6 @@
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${ERR}
return 1
fi
}

View File

@ -0,0 +1,3 @@
_zimfw_print_error() {
print -u2 -lR $'<%= clear_line %><%= red %><%= error %><%= bold %>'${_zname}$':<%= normalred %> '${1}$'<%= normal %>' ${2:+${(F):- ${(f)^2}}}
}

View File

@ -0,0 +1,3 @@
_zimfw_print_okay() {
if (( _zprintlevel > ${2:-0} )) print -lR $'<%= clear_line %><%= okay %><%= bold %>'${_zname}$':<%= normal %> '${1} ${3:+${(F):- ${(f)^3}}}
}

View File

@ -0,0 +1,3 @@
_zimfw_print_warn() {
_zimfw_print -u2 -R $'<%= clear_line %><%= yellow %><%= warn %><%= bold %>'${_zname}$':<%= normalyellow %> '${1}$'<%= normal %>'
}

View File

@ -1,40 +0,0 @@
_zimfw_run_tool() {
local -r zname=${1}
if [[ -z ${_zurls[${zname}]} ]]; then
if (( _zprintlevel > 1 )) print -PR <%= clear_line %>"<%= okay %>%B${zname}:%b Skipping external module"
return 0
fi
if (( _zfrozens[${zname}] )); then
if (( _zprintlevel > 1 )) print -PR <%= clear_line %>"<%= okay %>%B${zname}:%b Skipping frozen module"
return 0
fi
case ${_zargs_action} in
install)
if [[ -e ${_zdirs[${zname}]} ]]; then
if (( _zprintlevel > 1 )) print -PR <%= clear_line %>"<%= okay %>%B${zname}:%b Skipping already installed module"
return 0
fi
_zimfw_print -nR <%= clear_line %>"Installing ${zname}<%= ellipsis %>"
;;
update)
if [[ ! -d ${_zdirs[${zname}]} ]]; then
print -u2 -PR <%= clear_line %>"%F{red}<%= error %>%B${zname}:%b Not installed. Run %Bzimfw install%b to install.%f"
return 1
fi
_zimfw_print -nR <%= clear_line %>"Updating ${zname}<%= ellipsis %>"
;;
*)
print -u2 -PR <%= clear_line %>"%F{red}<%= error %>%B${zname}:%b Unknown action ${_zargs_action}%f"
return 1
;;
esac
local zcmd
case ${_ztools[${zname}]} in
<%= render_tools("src/tools/*", "zcmd") %>
*)
print -u2 -PR "<%= clear_line %>%F{red}<%= error %>%B${zname}:%b Unknown tool ${_ztools[${zname}]}%f"
return 1
;;
esac
zsh -c ${zcmd} ${_ztools[${zname}]} "${_zprintlevel}" "${_zargs_action}" "${zname}" "${_zdirs[${zname}]}" "${_zurls[${zname}]}" "${_ztypes[${zname}]}" "${_zrevs[${zname}]}" "${_zsubmodules[${zname}]}" "${_zonpulls[${zname}]}"
}

View File

@ -0,0 +1,13 @@
_zimfw_pull_print_okay() {
# 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}
return 1
elif [[ ${_zprintlevel} -gt 1 && -n ${ERR} ]]; then
# Overrides ${3} to include the on-pull output, to be used by _zimfw_print_okay below.
builtin set ${1} ${2:-0} ${3:+${3}$'\n'}'On-pull output:'$'\n'${ERR}
fi
fi
_zimfw_print_okay "${@}"
}

View File

@ -0,0 +1,145 @@
_zimfw_download_tarball() {
if [[ ${URL} =~ <%= url_regex %> ]]; then
readonly HOST=${match[3]}
readonly REPO=${match[4]%.git}
fi
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
_zimfw_print_error "${URL} is not a valid GitHub URL. Will not try to ${_zaction}."
return 1
fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
{
if [[ -r ${INFO_TARGET} ]]; then
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
if [[ ${URL} != ${INFO[1]} ]]; then
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
# Previous REV is in line 2, reserved for future use.
readonly INFO_HEADER=${INFO[3]}
fi
readonly TARBALL_URL=https://api.github.com/repos/${REPO}/tarball/${REV}
if [[ ${_zaction} == check ]]; then
if [[ -z ${INFO_HEADER} ]] return 0
if (( ${+commands[curl]} )); then
command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET}
else
command wget --spider -qS --header=${INFO_HEADER} ${TARBALL_URL} 2>${HEADERS_TARGET}
fi
else
if (( ${+commands[curl]} )); then
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}
return 1
fi
else
# wget returns 8 when 304 Not Modified, so we cannot use wget's error codes
command wget -qS ${INFO_HEADER:+--header=${INFO_HEADER}} -O ${TARBALL_TARGET} ${TARBALL_URL} 2>${HEADERS_TARGET}
fi
fi
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#*:}## ##}
fi
done < ${HEADERS_TARGET}
if (( HTTP_CODE == 304 )); then
# Not Modified
command rm -f ${TARBALL_TARGET} 2>/dev/null
return 0
elif (( HTTP_CODE != 200 )); then
_zimfw_print_error "Error downloading ${TARBALL_URL}, HTTP code ${HTTP_CODE}"
return 1
fi
if [[ -z ${ETAG} ]]; then
_zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response"
return 1
fi
if [[ ${_zaction} == check ]]; then
command touch ${TARBALL_TARGET} # Update available
else
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then
_zimfw_print_error "Error creating or updating ${INFO_TARGET}"
return 1
fi
fi
} always {
command rm -f ${HEADERS_TARGET} 2>/dev/null
}
}
_zimfw_untar_tarball() {
if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then
_zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1
fi
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
}
_zimfw_tool_degit() {
# 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
case ${_zaction} in
install)
{
_zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1
} always {
# return 1 does not change ${TRY_BLOCK_ERROR}, only changes ${?}
(( TRY_BLOCK_ERROR = ? ))
command rm -f ${TARBALL_TARGET} 2>/dev/null
if (( TRY_BLOCK_ERROR )) command rm -rf ${DIR} 2>/dev/null
}
;;
check|update)
if [[ ! -r ${INFO_TARGET} ]]; then
_zimfw_print_warn $'Module was not installed using zimfw\'s degit. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.'
return 0
fi
readonly DIR_NEW=${DIR}${TEMP}
{
_zimfw_download_tarball || return 1
if [[ ${_zaction} == check ]]; then
if [[ -e ${TARBALL_TARGET} ]]; then
_zimfw_print_okay 'Update available'
return 4
fi
_zimfw_print_okay 'Already up to date' 1
return 0
else
if [[ -e ${TARBALL_TARGET} ]]; then
_zimfw_create_dir ${DIR_NEW} && _zimfw_untar_tarball ${DIR_NEW} || return 1
if (( ${+commands[diff]} )); then
LOG=$(command diff -x '.zdegit*' -x '*.zwc' -x '*.zwc.old' -qr ${DIR} ${DIR_NEW} 2>/dev/null)
LOG=${${LOG//${DIR_NEW}/new}//${DIR}/old}
fi
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}
return 1
fi
_zimfw_pull_print_okay Updated 0 ${LOG} || return 1
else
_zimfw_pull_print_okay 'Already up to date' || return 1
fi
fi
} always {
command rm -f ${TARBALL_TARGET} 2>/dev/null
command rm -rf ${DIR_NEW} 2>/dev/null
}
;;
esac
# Check after successful install or update
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 <%= bold %>--no-submodules<%= normalyellow %> to disable this warning.'
fi
}

View File

@ -0,0 +1,93 @@
_zimfw_tool_git() {
# This runs in a subshell
readonly -i SUBMODULES=${5}
readonly DIR=${1} URL=${2} TYPE=${3} ONPULL=${6}
REV=${4}
case ${_zaction} in
install)
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
_zimfw_pull_print_okay Installed
else
_zimfw_print_error 'Error during git clone' ${ERR}
return 1
fi
;;
check|update)
if [[ ! -r ${DIR}/.git ]]; then
_zimfw_print_warn 'Module was not installed using git. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.'
return 0
fi
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
_zimfw_print_error 'Error during git fetch' ${ERR}
return 1
fi
if [[ ${TYPE} == branch ]]; then
if [[ -z ${REV} ]]; then
# Get HEAD remote branch
if ! ERR=$(command git -C ${DIR} remote set-head origin -a 2>&1); then
_zimfw_print_error 'Error during git remote set-head' ${ERR}
return 1
fi
if REV=$(command git -C ${DIR} symbolic-ref --short refs/remotes/origin/HEAD 2>&1); then
REV=${REV#origin/}
else
_zimfw_print_error 'Error during git symbolic-ref' ${REV}
return 1
fi
fi
TO_REV=${REV}@{u}
if [[ ${_zaction} == check ]]; then
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}]"
return 4
else
_zimfw_print_okay 'Already up to date' 1
return 0
fi
fi
else
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
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
TO_REV=${REV}
fi
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}
return 1
fi
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}
return 1
fi
# keep just first line of OUT
OUT=${OUT%%($'\n'|$'\r')*}
else
OUT="Updating to ${TYPE} ${REV}"
fi
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}
return 1
fi
fi
_zimfw_pull_print_okay ${OUT} 0 ${LOG}
;;
esac
}

View File

@ -0,0 +1,14 @@
_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 <%= bold %>-'${TYPE[1]}$'<%= normalyellow %>|<%= bold %>--'${TYPE}$'<%= normalyellow %> has no effect when using the mkdir tool'
fi
if (( ! SUBMODULES )); then
_zimfw_print_warn $'The zmodule option <%= bold %>--no-submodules<%= normalyellow %> 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
}

View File

@ -0,0 +1,45 @@
_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
return 0
fi
_zimfw_print -nR $'<%= clear_line %>Installing '${_zname}'<%= ellipsis %>'
;;
check|update)
if [[ ! -d ${_zdirs[${_zname}]} ]]; then
_zimfw_print_error $'Not installed. Run <%= bold %>zimfw install<%= normalred %> to install.'
return 1
fi
if [[ ${_zaction} == check ]]; then
if (( _zprintlevel > 1 )) print -nR $'<%= clear_line %>Checking '${_zname}'<%= ellipsis %>'
else
_zimfw_print -nR $'<%= clear_line %>Updating '${_zname}'<%= ellipsis %>'
fi
;;
*)
_zimfw_print_error "Unknown action ${_zaction}"
return 1
;;
esac
local -r ztool=${_ztools[${_zname}]}
case ${ztool} in
degit|git|mkdir)
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
;;
*)
_zimfw_print_error "Unknown tool ${ztool}"
return 1
;;
esac
}

View File

@ -0,0 +1,5 @@
_zimfw_run_tool_action() {
local -r _zaction=${1}
_zimfw_source_zimrc 1 && zargs -n 1 -P 0 -- "${_znames[@]}" -- _zimfw_run_tool
return 0
}

View File

@ -1,51 +1,55 @@
zimfw() {
builtin emulate -L zsh -o EXTENDED_GLOB
local -r _zversion='<%= version %>' zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
local -r _zversion='<%= version %>' _zversion_target=${ZIM_HOME}/.latest_version zusage=$'Usage: <%= bold %>'${0}$'<%= normal %> <action> [<%= bold %>-q<%= normal %>|<%= bold %>-v<%= normal %>]
Actions:
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
Also does %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to also see their output.
%Bcheck-dumpfile%b Does %Bclean-dumpfile%b if new completion configuration needs to be dumped.
%Bclean%b Clean all. Does both %Bclean-compiled%b and %Bclean-dumpfile%b.
%Bclean-compiled%b Clean Zsh compiled files.
%Bclean-dumpfile%b Clean completion dumpfile.
%Bcompile%b Compile Zsh files.
%Bhelp%b Print this help.
%Binfo%b Print Zim and system info.
%Blist%b List all modules currently defined in %B${ZIM_CONFIG_FILE:-<%= home %>/.zimrc}%b.
Use %B-v%b to also see the modules details.
%Binit%b Same as %Binstall%b, but with output tailored to be used at terminal startup.
%Binstall%b Install new modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to
also see their output, any on-pull output, and see skipped modules.
%Buninstall%b Delete unused modules. Prompts for confirmation. Use %B-q%b for quiet uninstall.
%Bupdate%b Update current modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b
to also see their output, any on-pull output, and see skipped modules.
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
%Bversion%b Print zimfw version.
<%= 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
output, any on-pull output and skipped modules.
<%= 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
skipped and up to date modules.
<%= bold %>update<%= normal %> Update current modules. Also does <%= bold %>build<%= normal %>, <%= bold %>compile<%= normal %>. Use <%= bold %>-v<%= normal %> to also see their
output, any on-pull output and skipped modules.
<%= 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.
Options:
%B-q%b Quiet (yes to prompts, and only outputs errors)
%B-v%b Verbose (outputs more details)"
<%= bold %>-q<%= normal %> Quiet (yes to prompts and only outputs errors)
<%= bold %>-v<%= normal %> Verbose (outputs more details)'
local -Ua _znames _zroot_dirs _zdisabled_root_dirs
local -A _zfrozens _ztools _zdirs _zurls _ztypes _zrevs _zsubmodules _zonpulls _zifs
local -a _zfpaths _zfunctions _zcmds _zunused_dirs
local -i _zprintlevel=1
if (( # > 2 )); then
print -u2 -PlR "%F{red}${0}: Too many options%f" '' ${zusage}
print -u2 -lR $'<%= red %>'${0}$': Too many options<%= normal %>' '' ${zusage}
return 2
elif (( # > 1 )); then
case ${2} in
-q) _zprintlevel=0 ;;
-v) _zprintlevel=2 ;;
*)
print -u2 -PlR "%F{red}${0}: Unknown option ${2}%f" '' ${zusage}
print -u2 -lR $'<%= red %>'${0}': Unknown option '${2}$'<%= normal %>' '' ${zusage}
return 2
;;
esac
fi
if ! zstyle -t ':zim' disable-version-check; then
_zimfw_version_check
if ! zstyle -t ':zim' disable-version-check && [[ ${1} != check-version ]]; then
# 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=${?}
_zimfw_check_version ${zversion_check_force} 1
fi
local _zrestartmsg=' Restart your terminal for changes to take effect.'
@ -53,41 +57,48 @@ Options:
build)
_zimfw_source_zimrc 2 && _zimfw_build || return 1
(( _zprintlevel-- ))
_zimfw_check_dumpfile && _zimfw_compile
_zimfw_compile
;;
check-dumpfile) _zimfw_source_zimrc 2 && _zimfw_check_dumpfile ;;
check-dumpfile) _zimfw_check_dumpfile ;;
clean) _zimfw_source_zimrc 2 && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
clean-compiled) _zimfw_source_zimrc 2 && _zimfw_clean_compiled ;;
clean-dumpfile) _zimfw_clean_dumpfile ;;
compile) _zimfw_source_zimrc 2 && _zimfw_compile ;;
help) print -PR ${zusage} ;;
help) print -R ${zusage} ;;
info) _zimfw_info ;;
list)
_zimfw_source_zimrc 3 && zargs -n 1 -- "${_znames[@]}" -- _zimfw_run_list && \
_zimfw_list_unuseds ' (unused)'
;;
check)
_zrestartmsg=
_zimfw_run_tool_action ${1} || return 1
(( _zprintlevel-- ))
_zimfw_print -R "Done with ${1}." # Only printed in verbose mode
;;
init)
_zrestartmsg=
_zimfw_install_update install || return 1
_zimfw_run_tool_action install || return 1
(( _zprintlevel-- ))
_zimfw_print -PR "<%= done %>Done with install.${_zrestartmsg}" # Only printed in verbose mode
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_check_dumpfile && _zimfw_compile
_zimfw_print 'Done with install.' # Only printed in verbose mode
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
install|update)
_zimfw_install_update ${1} || return 1
_zimfw_print -PR "<%= done %>Done with ${1}.${_zrestartmsg}"
_zimfw_run_tool_action ${1} || return 1
_zimfw_print -R "Done with ${1}.${_zrestartmsg}"
(( _zprintlevel-- ))
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_check_dumpfile && _zimfw_compile
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
uninstall) _zimfw_source_zimrc 2 && _zimfw_list_unuseds && _zimfw_uninstall ;;
check-version) _zimfw_check_version 1 ;;
upgrade)
_zimfw_upgrade || return 1
(( _zprintlevel-- ))
_zimfw_source_zimrc 2 && _zimfw_compile
;;
version) print -PR ${_zversion} ;;
version) print -R ${_zversion} ;;
*)
print -u2 -PlR "%F{red}${0}: Unknown action ${1}%f" '' ${zusage}
print -u2 -lR $'<%= red %>'${0}': Unknown action '${1}$'<%= normal %>' '' ${zusage}
return 2
;;
esac

View File

@ -1 +0,0 @@
# Do nothing. This file is deprecated.

View File

@ -1,151 +0,0 @@
# This runs in a new shell
builtin emulate -L zsh -o EXTENDED_GLOB
readonly -i PRINTLEVEL=${1} SUBMODULES=${8}
readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} ONPULL=${9} TEMP=.zdegit_${sysparams[pid]}
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
print_error() {
print -u2 -PlR <%= clear_line %>"%F{red}<%= error %>%B${MODULE}:%b ${1}%f" ${2:+${(F):- ${(f)^2}}}
}
print_okay() {
if (( PRINTLEVEL > 0 )); then
local -r log=${2:+${(F):- ${(f)^2}}}
if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
print -u2 -PlR <%= clear_line %>"%F{yellow}<%= warn %>%B${MODULE}:%b ${1}. Module contains git submodules, which are not supported by Zim's degit. Use zmodule option %B--no-submodules%b to disable this warning.%f" ${log}
else
print -PlR <%= clear_line %>"<%= okay %>%B${MODULE}:%b ${1}" ${log}
fi
fi
}
handle() {
if [[ -n ${ONPULL} ]]; then
if ! ERR=$(builtin cd -q ${DIR} 2>&1 && builtin eval ${ONPULL} 2>&1); then
print_error 'Error during on-pull' ${ERR}
return 1
elif [[ ${PRINTLEVEL} -gt 1 && -n ${ERR} ]]; then
builtin set ${1} ${2:+${2}$'\n'}"On-pull output:"$'\n'${ERR}
fi
fi
print_okay "${@}"
}
download_tarball() {
local host repo
if [[ ${URL} =~ <%= url_regex %> ]]; then
host=${match[3]}
repo=${match[4]%.git}
fi
if [[ ${host} != github.com || -z ${repo} ]]; then
print_error "${URL} is not a valid GitHub URL. Will not try to ${ACTION}."
return 1
fi
local -r headers_target=${DIR}/${TEMP}_headers
{
local info_header header etag
if [[ -r ${INFO_TARGET} ]]; then
local -r info=("${(@f)"$(<${INFO_TARGET})"}")
if [[ ${URL} != ${info[1]} ]]; then
print_error "URL does not match. Expected ${URL}. Will not try to ${ACTION}."
return 1
fi
# Previous REV is in line 2, reserved for future use.
info_header=${info[3]}
fi
local -r tarball_url=https://api.github.com/repos/${repo}/tarball/${REV}
if (( ${+commands[curl]} )); then
if ! ERR=$(command curl -fsSL ${info_header:+-H} ${info_header} -o ${TARBALL_TARGET} -D ${headers_target} ${tarball_url} 2>&1); then
print_error "Error downloading ${tarball_url} with curl" ${ERR}
return 1
fi
else
# wget returns 8 when 304 Not Modified, so we cannot use wget's error codes
command wget -q ${info_header:+--header=${info_header}} -O ${TARBALL_TARGET} -S ${tarball_url} 2>${headers_target}
fi
local -i http_code
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#*:}## ##}
fi
done < ${headers_target}
if (( http_code == 304 )); then
# Not Modified
command rm -f ${TARBALL_TARGET} 2>/dev/null
return 0
elif (( http_code != 200 )); then
print_error "Error downloading ${tarball_url}, HTTP code ${http_code}"
return 1
fi
if [[ -z ${etag} ]]; then
print_error "Error downloading ${tarball_url}, no ETag header found in response"
return 1
fi
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${etag}" >! ${INFO_TARGET} 2>/dev/null; then
print_error "Error creating or updating ${INFO_TARGET}"
return 1
fi
} always {
command rm -f ${headers_target} 2>/dev/null
}
}
untar_tarball() {
if ! ERR=$(command tar -C ${1} --strip=1 -xzf ${TARBALL_TARGET} 2>&1); then
print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1
fi
}
create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
print_error "Error creating ${1}" ${ERR}
return 1
fi
}
case ${ACTION} in
install)
{
create_dir ${DIR} && download_tarball && untar_tarball ${DIR} && handle Installed
} always {
# return 1 does not change ${TRY_BLOCK_ERROR}, only changes ${?}
(( TRY_BLOCK_ERROR = ? ))
command rm -f ${TARBALL_TARGET} 2>/dev/null
if (( TRY_BLOCK_ERROR )) command rm -rf ${DIR} 2>/dev/null
}
;;
update)
if [[ ! -r ${INFO_TARGET} ]]; then
if (( PRINTLEVEL > 0 )); then
print -u2 -PR <%= clear_line %>"%F{yellow}<%= warn %>%B${MODULE}:%b Module was not installed using Zim's degit. Will not try to update. Use zmodule option %B-z%b|%B--frozen%b to disable this warning.%f"
fi
return 0
fi
readonly DIR_NEW=${DIR}${TEMP}
{
download_tarball || return 1
if [[ ! -e ${TARBALL_TARGET} ]]; then
handle 'Already up to date'
return ${?}
fi
create_dir ${DIR_NEW} && untar_tarball ${DIR_NEW} || return 1
if (( ${+commands[diff]} )); then
LOG=$(command diff -x '.zdegit*' -x '*.zwc' -x '*.zwc.old' -qr ${DIR} ${DIR_NEW} 2>/dev/null)
LOG=${${LOG//${DIR_NEW}/new}//${DIR}/old}
fi
if ! ERR=$({ command cp -f ${INFO_TARGET} ${DIR_NEW} && \
command rm -rf ${DIR} && command mv -f ${DIR_NEW} ${DIR} } 2>&1); then
print_error "Error updating ${DIR}" ${ERR}
return 1
fi
handle Updated ${LOG}
} always {
command rm -f ${TARBALL_TARGET} 2>/dev/null
command rm -rf ${DIR_NEW} 2>/dev/null
}
;;
esac

View File

@ -1,97 +0,0 @@
# This runs in a new shell
builtin emulate -L zsh
readonly -i PRINTLEVEL=${1} SUBMODULES=${8}
readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} TYPE=${6} ONPULL=${9}
REV=${7}
print_error() {
print -u2 -PlR <%= clear_line %>"%F{red}<%= error %>%B${MODULE}:%b ${1}%f" ${2:+${(F):- ${(f)^2}}}
}
print_okay() {
if (( PRINTLEVEL > 0 )) print -PlR <%= clear_line %>"<%= okay %>%B${MODULE}:%b ${1}" ${2:+${(F):- ${(f)^2}}}
}
handle() {
if [[ -n ${ONPULL} ]]; then
if ! ERR=$(builtin cd -q ${DIR} 2>&1 && builtin eval ${ONPULL} 2>&1); then
print_error 'Error during on-pull' ${ERR}
return 1
elif [[ ${PRINTLEVEL} -gt 1 && -n ${ERR} ]]; then
builtin set ${1} ${2:+${2}$'\n'}"On-pull output:"$'\n'${ERR}
fi
fi
print_okay "${@}"
}
case ${ACTION} in
install)
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
handle Installed
else
print_error 'Error during git clone' ${ERR}
return 1
fi
;;
update)
if [[ ! -r ${DIR}/.git ]]; then
if (( PRINTLEVEL > 0 )); then
print -u2 -PR <%= clear_line %>"%F{yellow}<%= warn %>%B${MODULE}:%b Module was not installed using git. Will not try to update. Use zmodule option %B-z%b|%B--frozen%b to disable this warning.%f"
fi
return 0
fi
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
print_error "URL does not match. Expected ${URL}. Will not try to update."
return 1
fi
if ! ERR=$(command git -C ${DIR} fetch -pq origin 2>&1); then
print_error 'Error during git fetch' ${ERR}
return 1
fi
if [[ ${TYPE} == tag ]]; then
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
handle 'Already up to date'
return ${?}
fi
elif [[ -z ${REV} ]]; then
# Get HEAD remote branch
if ! ERR=$(command git -C ${DIR} remote set-head origin -a 2>&1); then
print_error 'Error during git remote set-head' ${ERR}
return 1
fi
if REV=$(command git -C ${DIR} symbolic-ref --short refs/remotes/origin/HEAD 2>&1); then
REV=${REV#origin/}
else
print_error 'Error during git symbolic-ref' ${REV}
return 1
fi
fi
if [[ ${TYPE} == branch ]]; then
LOG_REV=${REV}@{u}
else
LOG_REV=${REV}
fi
LOG=$(command git -C ${DIR} log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} -- 2>/dev/null)
if ! ERR=$(command git -C ${DIR} checkout -q ${REV} -- 2>&1); then
print_error 'Error during git checkout' ${ERR}
return 1
fi
if [[ ${TYPE} == branch ]]; then
if ! OUT=$(command git -C ${DIR} merge --ff-only --no-progress -n 2>&1); then
print_error 'Error during git merge' ${OUT}
return 1
fi
# keep just first line of OUT
OUT=${OUT%%($'\n'|$'\r')*}
else
OUT="Updating to ${TYPE} ${REV}"
fi
if (( SUBMODULES )); then
if ! ERR=$(command git -C ${DIR} submodule update --init --recursive -q -- 2>&1); then
print_error 'Error during git submodule update' ${ERR}
return 1
fi
fi
handle ${OUT} ${LOG}
;;
esac

View File

@ -1,23 +1,27 @@
<%
class Zim
attr_reader :version, :home, :min_zsh_version, :url_regex,
:clear_line, :ellipsis, :okay, :warn, :error, :done, :failed
:bold, :normal, :red, :normalred, :yellow, :normalyellow, :clear_line, :ellipsis, :okay, :warn, :error
def initialize
@version = "1.11.2"
@version = "1.13.1"
@home = "${ZDOTDIR:-${HOME}}"
@min_zsh_version = "5.2"
# Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo
# but not file:///path/to/repo or /path/to/repo
# ${match[3]} contains host, and ${match[4]} contains org/repo
@url_regex = "^([^:@/]+://)?([^@]+@)?([^:/]+)[:/]([^/]+/[^/]+)/?$"
@clear_line = "$'\\E[2K\\r'"
@bold = "\\E[1m"
@normal = "\\E[0m"
@yellow = "\\E[33m"
@normalyellow = "\\E[0;33m"
@red = "\\E[31m"
@normalred = "\\E[0;31m"
@clear_line = "\\E[2K\\r"
@ellipsis = " ..."
@okay = "%F{green})%f "
@okay = "\\E[32m)\\E[0m "
@warn = "! "
@error = "x "
@done = ""
@failed = ""
end
def render(filename)
@ -31,16 +35,6 @@ class Zim
def render_commented(filename)
render(filename).gsub(/^(?=.)/, "# ").gsub(/^$/, "#")
end
def render_escaped(filename)
render(filename).gsub(/(?=\$[^']|"|`)/, "\\\\").gsub(/#\{/, "$\{")
end
def render_tools(pattern, var)
Dir[pattern].sort.map { |filename|
" #{File.basename(filename, ".zsh.erb")}) #{var}=\"#{render_escaped(filename)}\" ;;"
}.join("\n")
end
end
zim = Zim.new
%># AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE.

857
zimfw.zsh

File diff suppressed because it is too large Load Diff