1
0
Fork 0
mirror of synced 2024-06-26 10:21:10 -04:00

Compare commits

..

21 commits

Author SHA1 Message Date
Eric Nielsen 6166fce1a1
v1.14.0 2024-06-25 12:32:13 -05:00
Eric Nielsen 3b7908dca1
Try to upgrade zimfw.zsh if it's a symlink
Initially the idea was to not allow this so upgrades are disabled when
the script is installed using a package manager, but this is an
unnecessary complexity. Making it less smart and more predictable.
2024-06-25 09:08:10 -05:00
Eric Nielsen 0785d87ea4
Improve error messages and check ZIM_HOME
for write permission. Also, if ZIM_HOME is not defined, don't "autoload"
the zimfw function, since this is going to be a scenario where the user
only has something like `source /path/to/zim/init.zsh` in their .zshrc.
2024-06-21 15:43:48 -05:00
Eric Nielsen eb37844857
Disable background version check if no write access
to zimfw.zsh or if it's a symlink or not a regular file. It does not
make sense to show a message to user saying "Run zimfw upgrade to
upgrade" if the action will then fail.
2024-06-18 17:40:12 -05:00
Eric Nielsen 3e812ed311
Don't upgrade zimfw.zsh if not in a writable path
or if it's a symlink or not a regular file. This makes more sense now
that zimfw.zsh can exist outside ZIM_HOME, that the same file can be
used my multiple users in the same machine, and that it is going to be
possible to install it with a package manager once it's stable to do so.
2024-06-18 17:13:53 -05:00
Eric Nielsen 897afc9cf9
Reapply "Use ${HOME} in generated static init.zsh script"
This reverts commit 9a47fde0c8.
2024-06-17 07:29:19 -05:00
Eric Nielsen 76164d6217
Allow zimfw.zsh to exist outside ZIM_HOME
and change initialization so ZIM_HOME is required before sourcing the
script.
2024-06-14 20:17:07 -05:00
Eric Nielsen 9a47fde0c8
Revert "Use ${HOME} in generated static init.zsh script"
This reverts commit 06f8bc71a3.

This breaks allowing a machine to have just one init.zsh script that can
be sourced by different users.
2024-06-10 07:52:45 -05:00
Eric Nielsen 06f8bc71a3
Use ${HOME} in generated static init.zsh script
Fixes #509
2024-06-09 11:32:08 -05:00
Eric Nielsen 9dc4056c4e
chmod a+r init.zsh so all users can read it
This better allows a global instalation of Zim that can be sourced by
other users in the same machine.

See #486
2024-06-03 08:51:20 -05:00
Eric Nielsen 96f60da366
Improve zimfw's degit error message
Hopefully make it clearer when either the git or the degit tool is being
used.

See #535
2024-05-30 09:38:44 -05:00
Eric Nielsen cdd9258d5c
Don't expose the zmodule function outside zimfw
Don't want to maintain extra code to allow zmodule to run outside zimfw.
This has no added benefit and might confuse users. If you were calling
zmodule in the shell just to get the help message, hopefully you can
look that up in the documentation instead.
2024-05-30 09:21:16 -05:00
Eric Nielsen 4fcc85b2db
Update README.md with ZIM_CONFIG_FILE instructions
Also add git-info and duration-info modules to the basic templates for a
better user experience.
2024-05-26 12:44:49 -05:00
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
31 changed files with 727 additions and 538 deletions

View file

@ -9,6 +9,51 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_No unreleased changes._
## [1.14.0] - 2024-06-25
### Changed
- Don't expand `${HOME}` in the init.zsh script. (See
[#509](https://github.com/zimfw/zimfw/issues/509))
- Don't allow calling `zmodule` from the command line. Let it fail with "command
not found" instead, as it's intended to be used only in the .zimrc script.
- `ZIM_HOME` must be defined before sourcing zimfw.zsh. All documentation was
already doing so, hence not considering this as a breaking change.
- Allow zimfw.zsh to exist anywhere else, not only inside `ZIM_HOME`. This
enables installing the zimfw.zsh script independently with a package manager.
- Don't try to upgrade if sourced zimfw.zsh is not in a writable path.
- Don't try actions that write to `ZIM_HOME` if user has no write permissions
there.
### Fixed
- Update error messages to hopefully make it clearer when either the git or the
degit tool is being used.
- Set read permissions to generated init.zsh script, so it can be read from
other users.
## [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
@ -30,7 +75,7 @@ _No unreleased changes._
### Deprecated
- The `zmodule check-dumpfile` action. The [completion] module alone now handles
- `check-dumpfile` action. The [completion] module alone now handles
checking the dumpfile. (See
[zimfw/completion#12](https://github.com/zimfw/completion/pull/12))
@ -114,7 +159,7 @@ _No unreleased changes._
[here](https://github.com/zimfw/completion/blob/9386a76eac3f55b1c04d57d26238f725b4b3ba25/init.zsh#L10-L11).
- Don't compile user Zsh startup scripts anymore
(See [#450](https://github.com/zimfw/zimfw/pull/450)). This means you can:
- either manually delete the compiled files, as they won't be updated by Zim
- either manually delete the compiled files, as they won't be updated by zimfw
anymore (recommended):
```
for zfile in ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout); do
@ -315,7 +360,7 @@ Take your time to review the updated [README.md] and the changes listed below.
- The Zim "core" is reduced to a single file, namely zimfw.zsh, that is
self-updated without requiring git. With this, `ZIM_HOME` is not (the root of)
a git repo anymore.
- Zsh and modules are configured in .zshrc instead of .zimrc.
- Zsh and modules are initialized in .zshrc instead of .zimrc.
- .zimrc is not sourced during Zsh startup anymore, and only contains the module
definitions.
- Zim's init.zsh and login_init.zsh scripts are generated by the `zimfw` CLI
@ -354,7 +399,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.12.0...HEAD
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.14.0...HEAD
[1.14.0]: https://github.com/zimfw/zimfw/compare/v1.13.1...v1.14.0
[1.13.1]: https://github.com/zimfw/zimfw/compare/v1.13.0...v1.13.1
[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

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

122
README.md
View file

@ -17,7 +17,7 @@
What is Zim?
------------
Zim is a Zsh configuration framework that bundles a [plugin manager](#usage),
useful [modules], and a wide variety of [themes], without compromising on [speed].
useful [modules] and a wide variety of [themes], without compromising on [speed].
Check how Zim compares to other frameworks and plugin managers:
@ -47,15 +47,17 @@ Installing Zim is easy. You can choose either the automatic or manual method bel
This will install a predefined set of modules and a theme for you.
* With `curl`:
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```zsh
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
* With `wget`:
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```zsh
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
Restart your terminal and you're done. Enjoy your Zsh IMproved! Take some time
to tweak your [`~/.zshrc`](#set-up-zshrc) file, and to also check the available
to tweak your [`~/.zshrc`](#set-up-zshrc) file and to also check the available
[modules] and [themes] you can add to your [`~/.zimrc`](#create-zimrc).
### Manual installation
@ -79,19 +81,27 @@ Add the lines below to your `~/.zshrc` file, in the following order:
```zsh
zstyle ':zim:zmodule' use 'degit'
````
This is optional, and only required if you don't have `git` installed (yes,
Zim works even without `git`!)
This is optional and only required if you don't have `git` installed (yes,
zimfw works even without `git`!)
2. To set where the directory used by Zim will be located:
2. To set where the zimfw plugin manager configuration file will be located:
```zsh
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
```
This is optional. The value of `ZIM_CONFIG_FILE` can be any path your user
has at least read access to. By default, the file must be at `~/.zimrc`, if
the `ZDOTDIR` environment variable is not defined. Otherwise, it must be at
`${ZDOTDIR}/.zimrc`.
3. To set the directory where the zimfw plugin manager will keep necessary files:
```zsh
ZIM_HOME=~/.zim
```
The value of `ZIM_HOME` can be any directory your user has write access to.
You can even set it to a cache directory like `${XDG_CACHE_HOME}/zim` or
`~/.cache/zim` if you also include the step below, that automatically
downloads the `zimfw` plugin manager.
`~/.cache/zim`.
3. To automatically download the `zimfw` plugin manager if missing:
4. To automatically download the zimfw plugin manager if missing:
```zsh
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
@ -107,22 +117,27 @@ Add the lines below to your `~/.zshrc` file, in the following order:
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
```
This is optional. If you choose to not include this step, you should manually
download the `zimfw.zsh` script once and keep it at `${ZIM_HOME}`.
This is optional. Alternatively, you can download the `zimfw.zsh` script
anywhere your user has write access to: just replace the occurrences of
`${ZIM_HOME}/zimfw.zsh` by the preferred path, like `/usr/local/bin/zimfw.zsh`
for example. If you choose to not include this step, you should manually
download the `zimfw.zsh` script once and keep it at the preferred path.
4. To automatically install missing modules and update the static initialization
5. To automatically install missing modules and update the static initialization
script if missing or outdated:
```zsh
# Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
# Install missing modules and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
```
This step is optional, but highly recommended. If you choose to not include
it, you must remember to manually run `zimfw install` every time after you
update your [`~/.zimrc`](#create-zimrc) file.
it, you must remember to manually run `zimfw install` every time you update
your [`~/.zimrc`](#create-zimrc) file. If you have chosen to keep the
`zimfw.zsh` in a different path as mentioned in the previous step, replace
`${ZIM_HOME}/zimfw.zsh` by the chosen path.
5. To source the static script, that will initialize your modules:
6. To source the static script, that will initialize your modules:
```zsh
# Initialize modules.
source ${ZIM_HOME}/init.zsh
@ -130,18 +145,31 @@ Add the lines below to your `~/.zshrc` file, in the following order:
#### Create `~/.zimrc`
You must create your `.zimrc` file at `~/.zimrc`, if the `ZDOTDIR` environment
variable is not defined. Otherwise, it must be at `${ZDOTDIR}/.zimrc`. It's
referred to as `~/.zimrc` in the documentation for the sake of simplicity.
This file configures the zimfw plugin manager. It's referred to as `~/.zimrc`
in the documentation for the sake of simplicity, but the actual location of the
file is defined by the following rules:
You can start with just:
1. You can define the full path and name of the file with a `ZIM_CONFIG_FILE`
environment variable. For example:
```zsh
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
```
2. Or, if you defined a `ZDOTDIR` environment variable, then the file must be at
`${ZDOTDIR}/.zimrc`
3. Otherwise, it must be at at `~/.zimrc`, which is it's default location.
As for the contents of the file, you can start with just:
```zsh
zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions
```
If you also want one of our prompt [themes]:
```
```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship
zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions
@ -149,6 +177,8 @@ zmodule zsh-users/zsh-autosuggestions
If you want to use our [completion] module too, instead of using `compinit` directly:
```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship
zmodule zsh-users/zsh-completions --fpath src
zmodule completion
@ -166,15 +196,15 @@ define the modules you want to use.
Usage
-----
The `zimfw` plugin manager installs your modules at `${ZIM_HOME}/modules`, and
The zimfw plugin manager installs your modules at `${ZIM_HOME}/modules` and
builds a static script at `${ZIM_HOME}/init.zsh` that will initialize them. Your
modules are defined in your `~/.zimrc` file.
The `~/.zimrc` file must contain `zmodule` calls to define the modules to be
initialized. The initialization will be done in the same order it's defined.
initialized. The modules will be initialized in the same order they're defined.
The `~/.zimrc` file is not sourced during Zsh startup, and it's only used to
configure the `zimfw` plugin manager.
The `~/.zimrc` file is not sourced during Zsh startup and it's only used to
configure the zimfw plugin manager.
Check [examples of `~/.zimrc` files](#create-zimrc) above.
@ -188,7 +218,7 @@ Below are some usage examples:
* A module at an absolute path, that is already installed:
`zmodule /usr/local/share/zsh-autosuggestions`
* A module with a custom fpath: `zmodule zsh-users/zsh-completions --fpath src`
* A module with a custom initialization file, and with git submodules disabled:
* A module with a custom initialization file and with git submodules disabled:
`zmodule spaceship-prompt/spaceship-prompt --source spaceship.zsh --no-submodules` or
`zmodule spaceship-prompt/spaceship-prompt --name spaceship --no-submodules`
* A module with two custom initialization files:
@ -227,7 +257,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 +269,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 +288,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.
@ -293,17 +329,17 @@ The Zim plugin manager:
* Added new modules to `~/.zimrc`? Run `zimfw install`.
* Removed modules from `~/.zimrc`? Run `zimfw uninstall`.
* Want to update your modules to their latest revisions? Run `zimfw update`.
* Want to upgrade `zimfw` to its latest version? Run `zimfw upgrade`.
* For more information about the `zimfw` plugin manager, run `zimfw help`.
* Want to upgrade zimfw to its latest version? Run `zimfw upgrade`.
* For more information about the zimfw plugin manager, run `zimfw help`.
Settings
--------
Customize path of the directory used by Zim with the `ZIM_HOME` environment
Set the path of the directory used by zimfw with the `ZIM_HOME` environment
variable:
ZIM_HOME=~/.zim
By default, the `zimfw` plugin manager configuration file must be at `~/.zimrc`,
By default, the zimfw plugin manager configuration file must be at `~/.zimrc`,
if the `ZDOTDIR` environment variable is not defined. Otherwise, it must be at
`${ZDOTDIR}/.zimrc`. You can customize its full path and name with the
`ZIM_CONFIG_FILE` environment variable:
@ -316,8 +352,10 @@ lighter module installations, you can set degit as the default tool with:
zstyle ':zim:zmodule' use 'degit'
By default, `zimfw` will check if it has a new version available every 30 days.
This can be disabled with:
By default, zimfw will check if it has a new version available every 30 days. If
the `zimfw.zsh` file cannot be upgraded, either because your user does not have
write access to it, or because it was sourced from a symlink, then this will be
disabled. This can be manually disabled with:
zstyle ':zim' disable-version-check yes

View file

@ -0,0 +1,241 @@
zmodule() {
local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc}
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 <%= 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: <%= 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.
<%= 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
<%= bold %>'${ZIM_HOME}$'/<%= normal %><module_name>.
<%= bold %>-r<%= normal %>|<%= bold %>--root<%= normal %> <path> Relative path to the module root.
Per-module options:
<%= 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.
<%= bold %>-t<%= normal %>|<%= bold %>--tag<%= normal %> <tag_name> Use specified tag when installing and updating the module. Over-
rides the branch option.
<%= 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.
<%= 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:
<%= 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.
<%= 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.
<%= 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:
<%= 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.
<%= 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
<%= 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.
<%= 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., <%= 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.'
if [[ ${${funcfiletrace[1]%:*}:A} != ${ztarget:A} ]]; then
print -u2 -lR $'<%= red %>'${0}$': Must be called from <%= bold %>'${ztarget}$'<%= normal %>' '' ${zusage}
return 2
fi
if (( ! # )); then
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$': Missing zmodule url<%= normal %>' '' ${zusage}
_zfailed=1
return 2
fi
local zurl=${1} zname=${1:t} zroot zarg
local -a zfpaths zfunctions zcmds
if [[ ${zurl} =~ ^[^:/]+: ]]; then
zname=${zname%.git}
elif [[ ${zurl} != /* ]]; then
# Count number of slashes
case ${#zurl//[^\/]/} in
0) zurl=https://github.com/zimfw/${zurl}.git ;;
1) zurl=https://github.com/${zurl}.git ;;
esac
fi
shift
while [[ ${1} == (-n|--name|-r|--root) ]]; do
if (( # < 2 )); then
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Missing argument for zmodule option <%= bold %>'${1}$'<%= normal %>' '' ${zusage}
_zfailed=1
return 2
fi
case ${1} in
-n|--name)
shift
zname=${${1%%/##}##/##}
;;
-r|--root)
shift
zroot=${${1%%/##}##/##}
;;
esac
shift
done
if [[ ${zurl} == /* ]]; then
_zdirs[${zname}]=${zurl%%/##}
zurl=
else
_zdirs[${zname}]=${ZIM_HOME}/modules/${zname}
fi
if [[ ${+_zurls[${zname}]} -ne 0 && ${_zurls[${zname}]} != ${zurl} ]]; then
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
_zurls[${zname}]=${zurl}
local -r zroot_dir=${_zdirs[${zname}]}${zroot:+/${zroot}}
_zroot_dirs+=(${zroot_dir})
# Set default values
if (( ! ${+_ztools[${zname}]} )); then
zstyle -s ':zim:zmodule' use "_ztools[${zname}]" || _ztools[${zname}]=git
fi
if (( ! ${+_ztypes[${zname}]} )) _ztypes[${zname}]=branch
if (( ! ${+_zsubmodules[${zname}]} )) _zsubmodules[${zname}]=1
# Set values from options
while (( # > 0 )); do
case ${1} in
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|--if-command|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
if (( # < 2 )); then
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Missing argument for zmodule option <%= bold %>'${1}$'<%= normal %>' '' ${zusage}
_zfailed=1
return 2
fi
;;
esac
case ${1} in
-b|--branch|-t|--tag|-u|--use|--no-submodules)
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
-b|--branch)
shift
_ztypes[${zname}]=branch
_zrevs[${zname}]=${1}
;;
-t|--tag)
shift
_ztypes[${zname}]=tag
_zrevs[${zname}]=${1}
;;
-u|--use)
shift
_ztools[${zname}]=${1}
;;
--no-submodules) _zsubmodules[${zname}]=0 ;;
-z|--frozen) _zfrozens[${zname}]=1 ;;
--on-pull)
shift
zarg=${1}
if [[ -n ${zroot} ]] zarg="(builtin cd -q ${zroot}; ${zarg})"
_zonpulls[${zname}]="${_zonpulls[${zname}]+${_zonpulls[${zname}]}; }${zarg}"
;;
--if)
shift
_zifs[${zroot_dir}]=${1}
;;
--if-command)
shift
_zifs[${zroot_dir}]="(( \${+commands[${1}]} ))"
;;
-f|--fpath)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zfpaths+=(${zarg})
;;
-a|--autoload)
shift
zfunctions+=(${1})
;;
-s|--source)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zcmds+=('source '${(qqq)zarg:a})
;;
-c|--cmd)
shift
zcmds+=(${1//{}/${(qqq)zroot_dir:a}})
;;
-d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;;
*)
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Unknown zmodule option <%= bold %>'${1}$'<%= normal %>' '' ${zusage}
_zfailed=1
return 2
;;
esac
shift
done
if (( _zflags & 1 )); then
_znames+=(${zname})
fi
if (( _zflags & 2 )); then
if [[ ! -e ${zroot_dir} ]]; then
print -u2 -R $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}': '${zroot_dir}$'<%= normalred %> not found<%= normal %>'
_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
zcmds=('source '${(qqq)^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 '${(qqq)^zscripts:a})
fi
fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
_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'
_zfpaths+=(${zpre}${^zfpaths})
_zfunctions+=(${zpre}${^zfunctions})
zcmds=(${zcmds//${HOME}/\${HOME}})
_zcmds+=(${zpre}${^zcmds})
fi
}

View file

@ -1,8 +1,12 @@
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:h}
if (( ! ${+ZIM_HOME} )); then
print -u2 -R $'<%= red %>'${0}$': <%= bold %>ZIM_HOME<%= normalred %> not defined<%= normal %>'
return 1
fi
# Define zimfw location
typeset -g __ZIMFW_FILE=${0}

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} && command chmod a+r ${2} && _zimfw_print -R $'<%= okay %><%= bold %>'${2}$':<%= normal %> Updated.'${_zrestartmsg}
fi
}

View file

@ -5,8 +5,7 @@ _zimfw_build_init() {
command mv -f ${ztarget}{,.old} || return 1
fi
_zimfw_mv =(
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R 'if (( ${+ZIM_HOME} )) zimfw() { source '${${(qqq)__ZIMFW_FILE}/${HOME}/\${HOME}}' "${@}" }'
local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})
@ -22,7 +21,7 @@ _zimfw_build_init() {
fi
done
zpre=$'*\0'
if (( ${#_zfpaths} )) print 'fpath=('${(q-)${_zfpaths#${~zpre}}:a}' ${fpath})'
if (( ${#_zfpaths} )) print -R 'fpath=('${${(qqq)${_zfpaths#${~zpre}}:a}/${HOME}/\${HOME}}' ${fpath})'
if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}}
for zroot_dir in ${_zroot_dirs}; do
zpre=${zroot_dir}$'\0'

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,230 +0,0 @@
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]
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.
<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.
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>.
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.
Per-module options:
%B-b%b|%B--branch%b <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-
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
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.
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
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-
mand is executed in the module root directory.
%B-d%b|%B--disabled%b 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
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-
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.
<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
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.
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."
if [[ ${${funcfiletrace[1]%:*}:A} != ${ztarget:A} ]]; then
print -u2 -PlR "%F{red}${0}: Must be called from %B${ztarget}%b%f" '' ${zusage}
return 2
fi
if (( ! # )); then
print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}: Missing zmodule url%f" '' ${zusage}
_zfailed=1
return 2
fi
local zurl=${1} zname=${1:t} zroot zarg
local -a zfpaths zfunctions zcmds
if [[ ${zurl} =~ ^[^:/]+: ]]; then
zname=${zname%.git}
elif [[ ${zurl} != /* ]]; then
# Count number of slashes
case ${#zurl//[^\/]/} in
0) zurl=https://github.com/zimfw/${zurl}.git ;;
1) zurl=https://github.com/${zurl}.git ;;
esac
fi
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}
_zfailed=1
return 2
fi
case ${1} in
-n|--name)
shift
zname=${${1%%/##}##/##}
;;
-r|--root)
shift
zroot=${${1%%/##}##/##}
;;
esac
shift
done
if [[ ${zurl} == /* ]]; then
_zdirs[${zname}]=${zurl%%/##}
zurl=
else
_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}
_zfailed=1
return 2
fi
_zurls[${zname}]=${zurl}
local -r zroot_dir=${_zdirs[${zname}]}${zroot:+/${zroot}}
_zroot_dirs+=(${zroot_dir})
# Set default values
if (( ! ${+_ztools[${zname}]} )); then
zstyle -s ':zim:zmodule' use "_ztools[${zname}]" || _ztools[${zname}]=git
fi
if (( ! ${+_ztypes[${zname}]} )) _ztypes[${zname}]=branch
if (( ! ${+_zsubmodules[${zname}]} )) _zsubmodules[${zname}]=1
# 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)
if (( # < 2 )); then
print -u2 -PlR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zname}:%b Missing argument for zmodule option %B${1}%b%f" '' ${zusage}
_zfailed=1
return 2
fi
;;
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"
;;
esac
case ${1} in
-b|--branch)
shift
_ztypes[${zname}]=branch
_zrevs[${zname}]=${1}
;;
-t|--tag)
shift
_ztypes[${zname}]=tag
_zrevs[${zname}]=${1}
;;
-u|--use)
shift
_ztools[${zname}]=${1}
;;
--no-submodules) _zsubmodules[${zname}]=0 ;;
-z|--frozen) _zfrozens[${zname}]=1 ;;
--on-pull)
shift
zarg=${1}
if [[ -n ${zroot} ]] zarg="(builtin cd -q ${zroot}; ${zarg})"
_zonpulls[${zname}]="${_zonpulls[${zname}]+${_zonpulls[${zname}]}; }${zarg}"
;;
--if)
shift
_zifs[${zroot_dir}]=${1}
;;
-f|--fpath)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zfpaths+=(${zarg})
;;
-a|--autoload)
shift
zfunctions+=(${1})
;;
-s|--source)
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zcmds+=("source ${(q-)zarg:a}")
;;
-c|--cmd)
shift
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}
_zfailed=1
return 2
;;
esac
shift
done
if (( _zflags & 1 )); then
_znames+=(${zname})
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"
_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
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})
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}
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})
_zcmds+=(${zpre}${^zcmds})
fi
}

View file

@ -1,20 +1,25 @@
_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"
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -PR "%F{red}<%= failed %>No modules defined in %B${ztarget}%b%f"
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
<%= render_all("src/functions/*.erb") %>
{
local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>'
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
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
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
}
}

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,3 +1,3 @@
_zimfw_check_dumpfile() {
_zimfw_print -u2 -PR '%F{yellow}<%= warn %>Deprecated action. This is now handled by the completion module alone.'
_zimfw_print -u2 $'<%= yellow %><%= warn %>Deprecated action. This is now handled by the completion module alone.<%= normal %>'
}

View file

@ -1,24 +1,22 @@
_zimfw_check_version() {
if (( ${1} )); 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)
if (( ${2} )); then
# background check
if [[ -w ${_zversion_target:h} ]]; then
print -R ${${(On)${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs \
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 https://github.com/zimfw/zimfw.git 'v*') || return 1
>! ${_zversion_target} <<<${${(On)${(f)tags}##*v}[1]} || return 1
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 -PR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"
_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

@ -4,5 +4,5 @@ _zimfw_clean_compiled() {
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

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

View file

@ -1,16 +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 -PR "%F{yellow}<%= warn %>%B${zroot_dir}:%b No write permission, unable to compile.%f"
_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

@ -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

@ -1,5 +1,9 @@
_zimfw_upgrade() {
local -r ztarget=${ZIM_HOME}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
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 $'<%= red %>No write permission to <%= bold %>'${ztarget:h}$'<%= normalred %>. Will not try to upgrade.<%= normal %>'
return 1
fi
{
if (( ${+commands[curl]} )); then
command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1
@ -8,7 +12,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 +21,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

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

View file

@ -1,3 +1,3 @@
_zimfw_print_okay() {
if (( _zprintlevel > ${2:-0} )) print -PlR <%= clear_line %>"<%= okay %>%B${_zname}:%b ${1}" ${3:+${(F):- ${(f)^3}}}
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

@ -4,7 +4,7 @@ _zimfw_download_tarball() {
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}."
_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 <%= bold %>--use git<%= normalred %> to use git instead.'
return 1
fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
@ -12,7 +12,7 @@ _zimfw_download_tarball() {
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}."
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
# Previous REV is in line 2, reserved for future use.
@ -71,17 +71,17 @@ _zimfw_download_tarball() {
}
_zimfw_untar_tarball() {
if ! ERR=$(command tar -C ${1} --strip=1 -xzf ${TARBALL_TARGET} 2>&1); then
if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then
_zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1
fi
}
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${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() {
@ -102,7 +102,7 @@ _zimfw_tool_degit() {
;;
check|update)
if [[ ! -r ${INFO_TARGET} ]]; then
_zimfw_print -u2 -PR <%= clear_line %>"%F{yellow}<%= warn %>%B${_zname}:%b Module was not installed using Zim's degit. Will not try to ${_zaction}. Use zmodule option %B-z%b|%B--frozen%b to disable this warning.%f"
_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}
@ -139,7 +139,7 @@ _zimfw_tool_degit() {
;;
esac
# Check after successful install or update
if [[ ${_zprintlevel} -gt 0 && ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
print -u2 -PR <%= clear_line %>"%F{yellow}<%= warn %>%B${_zname}:%b Module contains git submodules, which are not supported by Zim's degit. Use zmodule option %B--no-submodules%b to disable this warning.%f"
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

@ -14,11 +14,11 @@ _zimfw_tool_git() {
;;
check|update)
if [[ ! -r ${DIR}/.git ]]; then
_zimfw_print -u2 -PR <%= clear_line %>"%F{yellow}<%= warn %>%B${_zname}:%b Module was not installed using git. Will not try to ${_zaction}. Use zmodule option %B-z%b|%B--frozen%b to disable this warning.%f"
_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}."
_zimfw_print_error "The git 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

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

@ -14,17 +14,17 @@ _zimfw_run_tool() {
_zimfw_print_okay 'Skipping already installed module' 1
return 0
fi
_zimfw_print -nR <%= clear_line %>"Installing ${_zname}<%= ellipsis %>"
_zimfw_print -nR $'<%= clear_line %>Installing '${_zname}'<%= ellipsis %>'
;;
check|update)
if [[ ! -d ${_zdirs[${_zname}]} ]]; then
_zimfw_print_error 'Not installed. Run %Bzimfw install%b to install.'
_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 %>"
if (( _zprintlevel > 1 )) print -nR $'<%= clear_line %>Checking '${_zname}'<%= ellipsis %>'
else
_zimfw_print -nR <%= clear_line %>"Updating ${_zname}<%= ellipsis %>"
_zimfw_print -nR $'<%= clear_line %>Updating '${_zname}'<%= ellipsis %>'
fi
;;
*)
@ -34,7 +34,7 @@ _zimfw_run_tool() {
esac
local -r ztool=${_ztools[${_zname}]}
case ${ztool} in
degit|git)
degit|git|mkdir)
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
;;
*)

View file

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

View file

@ -1,57 +1,64 @@
zimfw() {
builtin emulate -L zsh -o EXTENDED_GLOB
local -r _zversion='<%= version %>' _zversion_target=${ZIM_HOME}/.latest_version zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
local -r _zversion='<%= 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 %Bcompile%b. Use %B-v%b to also see its output.
%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, %Bcompile%b. Use %B-v%b to also see their
<%= 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.
%Buninstall%b Delete unused modules. Prompts for confirmation. Use %B-q%b for quiet uninstall.
%Bcheck%b Check if updates for current modules are available. Use %B-v%b to also see
<%= 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.
%Bupdate%b Update current modules. Also does %Bbuild%b, %Bcompile%b. Use %B-v%b to also see their
<%= 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.
%Bcheck-version%b Check if a new version of zimfw is available.
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
%Bversion%b Print zimfw version.
<%= 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 && [[ ${1} != check-version ]]; then
local -r _zversion_target=${ZIM_HOME}/.latest_version
if ! zstyle -t ':zim' disable-version-check && \
[[ ${1} != check-version && -w ${ZIM_HOME} && -w ${__ZIMFW_FILE:A:h} ]]
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
if [[ ! -w ${ZIM_HOME} && ${1} == (build|check|init|install|update|check-version) ]]; then
print -u2 -R $'<%= red %>'${0}$': No write permission to <%= bold %>'${ZIM_HOME}$'<%= normalred %>. Will not try to '${1}$'.<%= normal %>'
return 1
fi
local _zrestartmsg=' Restart your terminal for changes to take effect.'
case ${1} in
build)
@ -64,7 +71,7 @@ Options:
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 && \
@ -74,18 +81,18 @@ Options:
_zrestartmsg=
_zimfw_run_tool_action ${1} || return 1
(( _zprintlevel-- ))
_zimfw_print -PR "<%= done %>Done with ${1}." # Only printed in verbose mode
_zimfw_print -R "Done with ${1}." # Only printed in verbose mode
;;
init)
_zrestartmsg=
_zimfw_run_tool_action install || return 1
(( _zprintlevel-- ))
_zimfw_print -PR "<%= done %>Done with install." # Only printed in verbose mode
_zimfw_print 'Done with install.' # Only printed in verbose mode
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
install|update)
_zimfw_run_tool_action ${1} || return 1
_zimfw_print -PR "<%= done %>Done with ${1}.${_zrestartmsg}"
_zimfw_print -R "Done with ${1}.${_zrestartmsg}"
(( _zprintlevel-- ))
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
@ -96,9 +103,9 @@ Options:
(( _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,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.12.0"
@version = "1.14.0"
@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)
@ -38,8 +42,4 @@ zim = Zim.new
<%= zim.render_commented("LICENSE") %>
<%= zim.render_all("src/stage2/*.erb") %>
if [[ ${functrace[1]} == zmodule:* ]]; then
zmodule "${@}"
else
zimfw "${@}"
fi
zimfw "${@}"

352
zimfw.zsh
View file

@ -4,7 +4,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
@ -25,13 +25,17 @@
# SOFTWARE.
autoload -Uz is-at-least && if ! is-at-least 5.2; then
print -u2 -PR "%F{red}${0}: Error starting Zim. You're using Zsh version %B${ZSH_VERSION}%b and versions < %B5.2%b are not supported. Upgrade your Zsh.%f"
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'
return 1
fi
autoload -Uz zargs
# Define Zim location
if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:h}
if (( ! ${+ZIM_HOME} )); then
print -u2 -R $'\E[31m'${0}$': \E[1mZIM_HOME\E[0;31m not defined\E[0m'
return 1
fi
# Define zimfw location
typeset -g __ZIMFW_FILE=${0}
_zimfw_print() {
if (( _zprintlevel > 0 )) print "${@}"
@ -41,12 +45,12 @@ _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 "%F{green})%f %B${2}:%b Already up to date"
_zimfw_print -R $'\E[32m)\E[0m \E[1m'${2}$':\E[0m 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 "%F{green})%f %B${2}:%b Updated.${_zrestartmsg}"
command mv -f ${1} ${2} && command chmod a+r ${2} && _zimfw_print -R $'\E[32m)\E[0m \E[1m'${2}$':\E[0m Updated.'${_zrestartmsg}
fi
}
@ -57,8 +61,7 @@ _zimfw_build_init() {
command mv -f ${ztarget}{,.old} || return 1
fi
_zimfw_mv =(
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R 'if (( ${+ZIM_HOME} )) zimfw() { source '${${(qqq)__ZIMFW_FILE}/${HOME}/\${HOME}}' "${@}" }'
local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})
@ -74,7 +77,7 @@ _zimfw_build_init() {
fi
done
zpre=$'*\0'
if (( ${#_zfpaths} )) print 'fpath=('${(q-)${_zfpaths#${~zpre}}:a}' ${fpath})'
if (( ${#_zfpaths} )) print -R 'fpath=('${${(qqq)${_zfpaths#${~zpre}}:a}/${HOME}/\${HOME}}' ${fpath})'
if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}}
for zroot_dir in ${_zroot_dirs}; do
zpre=${zroot_dir}$'\0'
@ -107,80 +110,87 @@ _zimfw_build_login_init() {
}
_zimfw_build() {
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P 'Done with build.'
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
}
_zimfw_source_zimrc() {
zmodule() {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${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: \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]
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 \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.
<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: \E[1mfoo\E[0m, \E[1mzimfw/foo\E[0m, \E[1mhttps://github.com/zimfw/foo.git\E[0m.
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.
\E[1m-n\E[0m|\E[1m--name\E[0m <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.
\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.
Per-module options:
%B-b%b|%B--branch%b <branch_name> Use specified branch when installing and updating the module.
\E[1m-b\E[0m|\E[1m--branch\E[0m <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-
\E[1m-t\E[0m|\E[1m--tag\E[0m <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
\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
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.
\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.
\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.
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
\E[1m--if\E[0m <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-
\E[1m--if-command\E[0m <cmd_name> Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to \E[1m--if \'(( \${+commands[\E[0m<cmd_name>\E[1m]} ))\'\E[0m.
\E[1m--on-pull\E[0m <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.
\E[1m-d\E[0m|\E[1m--disabled\E[0m 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
\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
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-
\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-
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.
\E[1m(init.zsh|\E[0m<name>\E[1m.(zsh|plugin.zsh|zsh-theme|sh))\E[0m, 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
\E[1m-c\E[0m|\E[1m--cmd\E[0m <command> Will execute specified command. Occurrences of the \E[1m{}\E[0m 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., \E[1m-s \'foo.zsh\'\E[0m and \E[1m-c \'source {}/foo.zsh\'\E[0m 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 $'\E[31m'${0}$': Must be called from \E[1m'${ztarget}$'\E[0m' '' ${zusage}
return 2
fi
if (( ! # )); then
print -u2 -PlR "%F{red}x ${funcfiletrace[1]}: Missing zmodule url%f" '' ${zusage}
print -u2 -lR $'\E[31mx '${funcfiletrace[1]}$': Missing zmodule url\E[0m' '' ${zusage}
_zfailed=1
return 2
fi
@ -198,7 +208,7 @@ Per-call initialization options:
shift
while [[ ${1} == (-n|--name|-r|--root) ]]; do
if (( # < 2 )); then
print -u2 -PlR "%F{red}x ${funcfiletrace[1]}:%B${zname}:%b Missing argument for zmodule option %B${1}%b%f" '' ${zusage}
print -u2 -lR $'\E[31mx '${funcfiletrace[1]}$':\E[1m'${zname}$':\E[0;31m Missing argument for zmodule option \E[1m'${1}$'\E[0m' '' ${zusage}
_zfailed=1
return 2
fi
@ -221,7 +231,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}x ${funcfiletrace[1]}:%B${zname}:%b Module already defined with a different URL. Expected %B${_zurls[${zname}]}%b%f" '' ${zusage}
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}
_zfailed=1
return 2
fi
@ -237,9 +247,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}x ${funcfiletrace[1]}:%B${zname}:%b Missing argument for zmodule option %B${1}%b%f" '' ${zusage}
print -u2 -lR $'\E[31mx '${funcfiletrace[1]}$':\E[1m'${zname}$':\E[0;31m Missing argument for zmodule option \E[1m'${1}$'\E[0m' '' ${zusage}
_zfailed=1
return 2
fi
@ -247,7 +257,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}! ${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 $'\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'
;;
esac
case ${1} in
@ -277,6 +287,10 @@ Per-call initialization options:
shift
_zifs[${zroot_dir}]=${1}
;;
--if-command)
shift
_zifs[${zroot_dir}]="(( \${+commands[${1}]} ))"
;;
-f|--fpath)
shift
zarg=${1}
@ -291,15 +305,15 @@ Per-call initialization options:
shift
zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zcmds+=("source ${(q-)zarg:a}")
zcmds+=('source '${(qqq)zarg:a})
;;
-c|--cmd)
shift
zcmds+=(${1//{}/${(q-)zroot_dir:a}})
zcmds+=(${1//{}/${(qqq)zroot_dir:a}})
;;
-d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;;
*)
print -u2 -PlR "%F{red}x ${funcfiletrace[1]}:%B${zname}:%b Unknown zmodule option %B${1}%b%f" '' ${zusage}
print -u2 -lR $'\E[31mx '${funcfiletrace[1]}$':\E[1m'${zname}$':\E[0;31m Unknown zmodule option \E[1m'${1}$'\E[0m' '' ${zusage}
_zfailed=1
return 2
;;
@ -311,7 +325,7 @@ Per-call initialization options:
fi
if (( _zflags & 2 )); then
if [[ ! -e ${zroot_dir} ]]; then
print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zname}: ${zroot_dir}%b not found%f"
print -u2 -R $'\E[31mx '${funcfiletrace[1]}$':\E[1m'${zname}': '${zroot_dir}$'\E[0;31m not found\E[0m'
_zfailed=1
return 1
fi
@ -323,43 +337,47 @@ 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 '${(qqq)^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 '${(qqq)^zscripts:a})
fi
fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
_zimfw_print -u2 -PlR "%F{yellow}! ${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 $'\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}
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})
zcmds=(${zcmds//${HOME}/\${HOME}})
_zcmds+=(${zpre}${^zcmds})
fi
}
_zimfw_source_zimrc() {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -PR "%F{red}Failed to source %B${ztarget}%b%f"
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -PR "%F{red}No modules defined in %B${ztarget}%b%f"
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
{
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
}
}
_zimfw_list_unuseds() {
@ -378,34 +396,32 @@ _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 $'\E[1m'${zunused:t}$':\E[0m '${zunused}${1}
}
_zimfw_check_dumpfile() {
_zimfw_print -u2 -PR '%F{yellow}! Deprecated action. This is now handled by the completion module alone.'
_zimfw_print -u2 $'\E[33m! Deprecated action. This is now handled by the completion module alone.\E[0m'
}
_zimfw_check_version() {
if (( ${1} )); 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)
if (( ${2} )); then
# background check
if [[ -w ${_zversion_target:h} ]]; then
print -R ${${(On)${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs \
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 https://github.com/zimfw/zimfw.git 'v*') || return 1
>! ${_zversion_target} <<<${${(On)${(f)tags}##*v}[1]} || return 1
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 -PR "%F{yellow}Latest zimfw version is %B${zlatest_version}%b. You're using version %B${_zversion}%b. Run %Bzimfw upgrade%b to upgrade.%f"
_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'
return 4
fi
fi
@ -417,7 +433,7 @@ _zimfw_clean_compiled() {
local zopt
if (( _zprintlevel > 0 )) zopt=-v
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) && \
_zimfw_print -P '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 \E[1mzimfw compile\E[0m to re-compile.'
}
_zimfw_clean_dumpfile() {
@ -425,28 +441,28 @@ _zimfw_clean_dumpfile() {
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump
if (( _zprintlevel > 0 )) zopt=-v
command rm -f ${zopt} ${zdumpfile}(|.dat|.zwc(|.old))(N) && \
_zimfw_print -P "Done with clean-dumpfile.${_zrestartmsg}"
_zimfw_print -R "Done with clean-dumpfile.${_zrestartmsg}"
}
_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 -PR "%F{yellow}! %B${zroot_dir}:%b No write permission, unable to compile.%f"
_zimfw_print -R $'\E[33m! \E[1m'${zroot_dir}$':\E[0;33m No write permission, unable to compile.\E[0m'
continue
fi
for zfile in ${zroot_dir}/(^*test*/)#*.zsh(|-theme)(N-.); do
if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then
zcompile -UR ${zfile} && _zimfw_print -PR "%F{green})%f %B${zfile}.zwc:%b Compiled"
zcompile -UR ${zfile} && _zimfw_print -R $'\E[32m)\E[0m \E[1m'${zfile}$'.zwc:\E[0m Compiled'
fi
done
done
_zimfw_print -P 'Done with compile.'
_zimfw_print 'Done with compile.'
}
_zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2023-07-17 23:54:58 UTC, previous commit is 49386ca)'
print -R 'zimfw version: '${_zversion}' (built at 2024-06-25 17:29:35 UTC, previous commit is 3b7908d)'
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}
@ -462,11 +478,15 @@ _zimfw_uninstall() {
command rm -rf ${zopt} ${_zunused_dirs} || return 1
fi
fi
_zimfw_print -P 'Done with uninstall.'
_zimfw_print 'Done with uninstall.'
}
_zimfw_upgrade() {
local -r ztarget=${ZIM_HOME}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
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'
return 1
fi
{
if (( ${+commands[curl]} )); then
command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1
@ -475,7 +495,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 to download %B${zurl}%b. Use %B-v%b option to see details.%f"
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'
fi
return 1
fi
@ -484,7 +504,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 with upgrade.'
_zimfw_print 'Done with upgrade.'
} always {
command rm -f ${ztarget}.new{,.gz}
}
@ -493,7 +513,7 @@ _zimfw_upgrade() {
_zimfw_run_list() {
local -r zname=${1}
local -r zdir=${_zdirs[${zname}]}
print -PnR "%B${zname}:%b ${zdir}"
print -nR $'\E[1m'${zname}$':\E[0m '${zdir}
if [[ -z ${_zurls[${zname}]} ]] print -n ' (external)'
if (( ${_zfrozens[${zname}]} )) print -n ' (frozen)'
if (( ${_zdisabled_root_dirs[(I)${zdir}]} )) print -n ' (disabled)'
@ -531,12 +551,23 @@ _zimfw_run_list() {
fi
}
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${ERR}
return 1
fi
}
_zimfw_print_error() {
print -u2 -PlR $'\E[2K\r'"%F{red}x %B${_zname}:%b ${1}%f" ${2:+${(F):- ${(f)^2}}}
print -u2 -lR $'\E[2K\r\E[31mx \E[1m'${_zname}$':\E[0;31m '${1}$'\E[0m' ${2:+${(F):- ${(f)^2}}}
}
_zimfw_print_okay() {
if (( _zprintlevel > ${2:-0} )) print -PlR $'\E[2K\r'"%F{green})%f %B${_zname}:%b ${1}" ${3:+${(F):- ${(f)^3}}}
if (( _zprintlevel > ${2:-0} )) print -lR $'\E[2K\r\E[32m)\E[0m \E[1m'${_zname}$':\E[0m '${1} ${3:+${(F):- ${(f)^3}}}
}
_zimfw_print_warn() {
_zimfw_print -u2 -R $'\E[2K\r\E[33m! \E[1m'${_zname}$':\E[0;33m '${1}$'\E[0m'
}
_zimfw_pull_print_okay() {
@ -559,7 +590,7 @@ _zimfw_download_tarball() {
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}."
_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.'
return 1
fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
@ -567,7 +598,7 @@ _zimfw_download_tarball() {
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}."
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
# Previous REV is in line 2, reserved for future use.
@ -626,17 +657,17 @@ _zimfw_download_tarball() {
}
_zimfw_untar_tarball() {
if ! ERR=$(command tar -C ${1} --strip=1 -xzf ${TARBALL_TARGET} 2>&1); then
if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then
_zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1
fi
}
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${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() {
@ -657,7 +688,7 @@ _zimfw_tool_degit() {
;;
check|update)
if [[ ! -r ${INFO_TARGET} ]]; then
_zimfw_print -u2 -PR $'\E[2K\r'"%F{yellow}! %B${_zname}:%b Module was not installed using Zim's degit. Will not try to ${_zaction}. Use zmodule option %B-z%b|%B--frozen%b to disable this warning.%f"
_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.'
return 0
fi
readonly DIR_NEW=${DIR}${TEMP}
@ -694,8 +725,8 @@ _zimfw_tool_degit() {
;;
esac
# Check after successful install or update
if [[ ${_zprintlevel} -gt 0 && ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
print -u2 -PR $'\E[2K\r'"%F{yellow}! %B${_zname}:%b Module contains git submodules, which are not supported by Zim's degit. Use zmodule option %B--no-submodules%b to disable this warning.%f"
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.'
fi
}
@ -715,11 +746,11 @@ _zimfw_tool_git() {
;;
check|update)
if [[ ! -r ${DIR}/.git ]]; then
_zimfw_print -u2 -PR $'\E[2K\r'"%F{yellow}! %B${_zname}:%b Module was not installed using git. Will not try to ${_zaction}. Use zmodule option %B-z%b|%B--frozen%b to disable this warning.%f"
_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.'
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}."
_zimfw_print_error "The git 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
@ -793,6 +824,21 @@ _zimfw_tool_git() {
esac
}
_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
}
_zimfw_run_tool() {
local -r _zname=${1}
if [[ -z ${_zurls[${_zname}]} ]]; then
@ -809,17 +855,17 @@ _zimfw_run_tool() {
_zimfw_print_okay 'Skipping already installed module' 1
return 0
fi
_zimfw_print -nR $'\E[2K\r'"Installing ${_zname} ..."
_zimfw_print -nR $'\E[2K\rInstalling '${_zname}' ...'
;;
check|update)
if [[ ! -d ${_zdirs[${_zname}]} ]]; then
_zimfw_print_error 'Not installed. Run %Bzimfw install%b to install.'
_zimfw_print_error $'Not installed. Run \E[1mzimfw install\E[0;31m to install.'
return 1
fi
if [[ ${_zaction} == check ]]; then
if (( _zprintlevel > 1 )) print -nR $'\E[2K\r'"Checking ${_zname} ..."
if (( _zprintlevel > 1 )) print -nR $'\E[2K\rChecking '${_zname}' ...'
else
_zimfw_print -nR $'\E[2K\r'"Updating ${_zname} ..."
_zimfw_print -nR $'\E[2K\rUpdating '${_zname}' ...'
fi
;;
*)
@ -829,7 +875,7 @@ _zimfw_run_tool() {
esac
local -r ztool=${_ztools[${_zname}]}
case ${ztool} in
degit|git)
degit|git|mkdir)
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
;;
*)
@ -841,64 +887,72 @@ _zimfw_run_tool() {
_zimfw_run_tool_action() {
local -r _zaction=${1}
_zimfw_source_zimrc 1 && zargs -n 1 -P 0 -- "${_znames[@]}" -- _zimfw_run_tool
_zimfw_source_zimrc 1 || return 1
zargs -n 1 -P 0 -- "${_znames[@]}" -- _zimfw_run_tool
return 0
}
zimfw() {
builtin emulate -L zsh -o EXTENDED_GLOB
local -r _zversion='1.12.0' _zversion_target=${ZIM_HOME}/.latest_version zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
local -r _zversion='1.14.0' zusage=$'Usage: \E[1m'${0}$'\E[0m <action> [\E[1m-q\E[0m|\E[1m-v\E[0m]
Actions:
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
Also does %Bcompile%b. Use %B-v%b to also see its output.
%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:-${ZDOTDIR:-${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, %Bcompile%b. Use %B-v%b to also see their
\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
output, any on-pull output and skipped modules.
%Buninstall%b Delete unused modules. Prompts for confirmation. Use %B-q%b for quiet uninstall.
%Bcheck%b Check if updates for current modules are available. Use %B-v%b to also see
\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
skipped and up to date modules.
%Bupdate%b Update current modules. Also does %Bbuild%b, %Bcompile%b. Use %B-v%b to also see their
\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
output, any on-pull output and skipped modules.
%Bcheck-version%b Check if a new version of zimfw is available.
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
%Bversion%b Print zimfw version.
\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.
Options:
%B-q%b Quiet (yes to prompts and only outputs errors)
%B-v%b Verbose (outputs more details)"
\E[1m-q\E[0m Quiet (yes to prompts and only outputs errors)
\E[1m-v\E[0m 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 $'\E[31m'${0}$': Too many options\E[0m' '' ${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 $'\E[31m'${0}': Unknown option '${2}$'\E[0m' '' ${zusage}
return 2
;;
esac
fi
if ! zstyle -t ':zim' disable-version-check && [[ ${1} != check-version ]]; then
local -r _zversion_target=${ZIM_HOME}/.latest_version
if ! zstyle -t ':zim' disable-version-check && \
[[ ${1} != check-version && -w ${ZIM_HOME} && -w ${__ZIMFW_FILE:A:h} ]]
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
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
local _zrestartmsg=' Restart your terminal for changes to take effect.'
case ${1} in
build)
@ -911,7 +965,7 @@ Options:
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 && \
@ -921,18 +975,18 @@ Options:
_zrestartmsg=
_zimfw_run_tool_action ${1} || return 1
(( _zprintlevel-- ))
_zimfw_print -PR "Done with ${1}." # Only printed in verbose mode
_zimfw_print -R "Done with ${1}." # Only printed in verbose mode
;;
init)
_zrestartmsg=
_zimfw_run_tool_action install || return 1
(( _zprintlevel-- ))
_zimfw_print -PR "Done with install." # Only printed in verbose mode
_zimfw_print 'Done with install.' # Only printed in verbose mode
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
install|update)
_zimfw_run_tool_action ${1} || return 1
_zimfw_print -PR "Done with ${1}.${_zrestartmsg}"
_zimfw_print -R "Done with ${1}.${_zrestartmsg}"
(( _zprintlevel-- ))
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
;;
@ -943,16 +997,12 @@ Options:
(( _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 $'\E[31m'${0}': Unknown action '${1}$'\E[0m' '' ${zusage}
return 2
;;
esac
}
if [[ ${functrace[1]} == zmodule:* ]]; then
zmodule "${@}"
else
zimfw "${@}"
fi
zimfw "${@}"