Compare commits
No commits in common. "master" and "v1.12.0" have entirely different histories.
34 changed files with 677 additions and 1052 deletions
89
CHANGELOG.md
89
CHANGELOG.md
|
@ -7,80 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Also output zimfw config and zimfw.zsh script paths in `info` action,
|
||||
following symlinks if any.
|
||||
- Don't output colors if `NO_COLOR` environment variable is set to a non-empty
|
||||
value.
|
||||
|
||||
## [1.15.1] - 2024-10-10
|
||||
|
||||
### Fixed
|
||||
|
||||
- Preserve original module if reinstall fails instead of removing it first.
|
||||
|
||||
## [1.15.0] - 2024-10-08
|
||||
|
||||
### Added
|
||||
|
||||
- `reinstall` action, that removes and then installs again the modules that
|
||||
failed any of the checks: (See [#542](https://github.com/zimfw/zimfw/issues/542))
|
||||
- module was installed with the defined tool,
|
||||
- module URL matches the defined one.
|
||||
- `--if-ostype` option to `zmodule`. This option is equivalent to
|
||||
`--if "[[ \${OSTYPE} == ${1} ]]"`.
|
||||
|
||||
### Changed
|
||||
|
||||
- Ask before uninstalling each unused module, instead of asking just once for
|
||||
all.
|
||||
- Add disclaimer comment at beginning of .zimrc file.
|
||||
|
||||
## [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.
|
||||
_No unreleased changes._
|
||||
|
||||
## [1.12.0] - 2023-07-17
|
||||
|
||||
|
@ -103,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Deprecated
|
||||
|
||||
- `check-dumpfile` action. The [completion] module alone now handles
|
||||
- The `zmodule check-dumpfile` action. The [completion] module alone now handles
|
||||
checking the dumpfile. (See
|
||||
[zimfw/completion#12](https://github.com/zimfw/completion/pull/12))
|
||||
|
||||
|
@ -187,7 +114,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
[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 zimfw
|
||||
- either manually delete the compiled files, as they won't be updated by Zim
|
||||
anymore (recommended):
|
||||
```
|
||||
for zfile in ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout); do
|
||||
|
@ -388,7 +315,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 initialized in .zshrc instead of .zimrc.
|
||||
- Zsh and modules are configured 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
|
||||
|
@ -427,13 +354,7 @@ 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.15.1...HEAD
|
||||
[1.15.1]: https://github.com/zimfw/zimfw/compare/v1.15.0...v1.15.1
|
||||
[1.15.0]: https://github.com/zimfw/zimfw/compare/v1.14.0...v1.15.0
|
||||
[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
|
||||
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.12.0...HEAD
|
||||
[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
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,7 +1,7 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2015-2016 Matt Hamilton and contributors
|
||||
Copyright (c) 2016-2024 Eric Nielsen, Matt Hamilton and contributors
|
||||
Copyright (c) 2016-2023 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
|
||||
|
|
135
README.md
135
README.md
|
@ -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,17 +47,15 @@ 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`:
|
||||
```zsh
|
||||
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
|
||||
```
|
||||
|
||||
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
|
||||
|
||||
* With `wget`:
|
||||
```zsh
|
||||
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.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
|
||||
|
@ -81,27 +79,19 @@ 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,
|
||||
zimfw works even without `git`!)
|
||||
This is optional, and only required if you don't have `git` installed (yes,
|
||||
Zim works even without `git`!)
|
||||
|
||||
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:
|
||||
2. To set where the directory used by Zim will be located:
|
||||
```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`.
|
||||
`~/.cache/zim` if you also include the step below, that automatically
|
||||
downloads the `zimfw` plugin manager.
|
||||
|
||||
4. To automatically download the zimfw plugin manager if missing:
|
||||
3. To automatically download the `zimfw` plugin manager if missing:
|
||||
```zsh
|
||||
# Download zimfw plugin manager if missing.
|
||||
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
|
||||
|
@ -117,27 +107,22 @@ 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. 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/share/zimfw/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.
|
||||
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}`.
|
||||
|
||||
5. To automatically install missing modules and update the static initialization
|
||||
4. 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 ${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} ]]; then
|
||||
# Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
|
||||
if [[ ! ${ZIM_HOME}/init.zsh -nt ${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 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.
|
||||
it, you must remember to manually run `zimfw install` every time after you
|
||||
update your [`~/.zimrc`](#create-zimrc) file.
|
||||
|
||||
6. To source the static script, that will initialize your modules:
|
||||
5. To source the static script, that will initialize your modules:
|
||||
```zsh
|
||||
# Initialize modules.
|
||||
source ${ZIM_HOME}/init.zsh
|
||||
|
@ -145,31 +130,18 @@ Add the lines below to your `~/.zshrc` file, in the following order:
|
|||
|
||||
#### Create `~/.zimrc`
|
||||
|
||||
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 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.
|
||||
|
||||
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:
|
||||
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
|
||||
|
@ -177,8 +149,6 @@ 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
|
||||
|
@ -196,15 +166,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 modules will be initialized in the same order they're defined.
|
||||
initialized. The initialization will be done in the same order it's 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.
|
||||
|
||||
|
@ -218,7 +188,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:
|
||||
|
@ -257,7 +227,7 @@ zation will be done in the same order it's defined.
|
|||
<url> Module absolute path or repository URL. The following URL formats
|
||||
are equivalent: <b>foo</b>, <b>zimfw/foo</b>, <b>https://github.com/zimfw/foo.git</b>.
|
||||
If an absolute path is given, the module is considered externally
|
||||
installed and won't be installed or updated by zimfw.
|
||||
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
|
||||
|
@ -269,16 +239,13 @@ Per-module options:
|
|||
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> <tool_name> Install and update the module using the defined tool. Default is
|
||||
either defined by <b>zstyle ':zim:zmodule' use '</b><tool_name><b>'</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
|
||||
<b>-u</b>|<b>--use</b> <<b>git</b>|<b>degit</b>> Install and update the module using the defined tool. Default is
|
||||
either defined by <b>zstyle ':zim:zmodule' use '</b><<b>git</b>|<b>degit</b>><b>'</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
|
||||
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 <url> 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't install or update git submodules.
|
||||
<b>-z</b>|<b>--frozen</b> Don't install or update the module.
|
||||
|
||||
|
@ -288,12 +255,6 @@ Per-module options:
|
|||
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>--if-command</b> <cmd_name> Will only initialize module root if specified external command is
|
||||
available. This is evaluated at every new terminal startup.
|
||||
Equivalent to <b>--if '(( ${+commands[</b><cmd_name><b>]} ))'</b>.
|
||||
<b>--if-ostype</b> <ostype> Will only initialize module root if <b>OSTYPE</b> is equal to the given
|
||||
expression. This is evaluated at every new terminal startup.
|
||||
Equivalent to <b>--if '[[ ${OSTYPE} == </b><ostype><b> ]]'</b>.
|
||||
<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.
|
||||
|
@ -332,17 +293,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
|
||||
--------
|
||||
Set the path of the directory used by zimfw with the `ZIM_HOME` environment
|
||||
Customize path of the directory used by Zim 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:
|
||||
|
@ -355,23 +316,11 @@ 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. 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:
|
||||
By default, `zimfw` will check if it has a new version available every 30 days.
|
||||
This can be disabled with:
|
||||
|
||||
zstyle ':zim' disable-version-check yes
|
||||
|
||||
To disable color output from zimfw, prefix the zimfw call with `NO_COLOR=1`,
|
||||
like:
|
||||
|
||||
NO_COLOR=1 zimfw install
|
||||
|
||||
or add the following to your `.zshrc`, which should also disable color output
|
||||
for other tools. See https://no-color.org/
|
||||
|
||||
export NO_COLOR=1
|
||||
|
||||
Uninstalling
|
||||
------------
|
||||
The best way to remove Zim is to manually delete `~/.zim`, `~/.zimrc`, and
|
||||
|
|
|
@ -1,243 +0,0 @@
|
|||
zmodule() {
|
||||
local -r zusage="Usage: ${_zbold}${0}${_znormal} <url> [${_zbold}-n${_znormal}|${_zbold}--name${_znormal} <module_name>] [${_zbold}-r${_znormal}|${_zbold}--root${_znormal} <path>] [options]
|
||||
|
||||
Add ${_zbold}zmodule${_znormal} calls to your ${_zbold}${_zconfig}${_znormal} 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: ${_zbold}foo${_znormal}, ${_zbold}zimfw/foo${_znormal}, ${_zbold}https://github.com/zimfw/foo.git${_znormal}.
|
||||
If an absolute path is given, the module is considered externally
|
||||
installed and won't be installed or updated by zimfw.
|
||||
${_zbold}-n${_znormal}|${_zbold}--name${_znormal} <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
|
||||
${_zbold}${ZIM_HOME}/${_znormal}<module_name>.
|
||||
${_zbold}-r${_znormal}|${_zbold}--root${_znormal} <path> Relative path to the module root.
|
||||
|
||||
Per-module options:
|
||||
${_zbold}-b${_znormal}|${_zbold}--branch${_znormal} <branch_name> Use specified branch when installing and updating the module.
|
||||
Overrides the tag option. Default: the repository default branch.
|
||||
${_zbold}-t${_znormal}|${_zbold}--tag${_znormal} <tag_name> Use specified tag when installing and updating the module. Over-
|
||||
rides the branch option.
|
||||
${_zbold}-u${_znormal}|${_zbold}--use${_znormal} <tool_name> Install and update the module using the defined tool. Default is
|
||||
either defined by ${_zbold}zstyle ':zim:zmodule' use '${_znormal}<tool_name>${_zbold}'${_znormal}, or ${_zbold}git${_znormal}
|
||||
if none is provided. The tools available are:
|
||||
${_zbold}git${_znormal} uses the git command. Local changes are preserved on updates.
|
||||
${_zbold}degit${_znormal} 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.
|
||||
${_zbold}mkdir${_znormal} creates an empty directory. The <url> is only used to set
|
||||
the module name. Use the ${_zbold}-c${_znormal}|${_zbold}--cmd${_znormal} or ${_zbold}--on-pull${_znormal} options to execute
|
||||
the desired command to generate the module files.
|
||||
${_zbold}--no-submodules${_znormal} Don't install or update git submodules.
|
||||
${_zbold}-z${_znormal}|${_zbold}--frozen${_znormal} 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:
|
||||
${_zbold}--if${_znormal} <test> Will only initialize module root if specified test returns a zero
|
||||
exit status. The test is evaluated at every new terminal startup.
|
||||
${_zbold}--if-command${_znormal} <cmd_name> Will only initialize module root if specified external command is
|
||||
available. This is evaluated at every new terminal startup.
|
||||
Equivalent to ${_zbold}--if '(( \${+commands[${_znormal}<cmd_name>${_zbold}]} ))'${_znormal}.
|
||||
${_zbold}--if-ostype${_znormal} <ostype> Will only initialize module root if ${_zbold}OSTYPE${_znormal} is equal to the given
|
||||
expression. This is evaluated at every new terminal startup.
|
||||
Equivalent to ${_zbold}--if '[[ \${OSTYPE} == ${_znormal}<ostype>${_zbold} ]]'${_znormal}.
|
||||
${_zbold}--on-pull${_znormal} <command> Execute command after installing or updating the module. The com-
|
||||
mand is executed in the module root directory.
|
||||
${_zbold}-d${_znormal}|${_zbold}--disabled${_znormal} 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:
|
||||
${_zbold}-f${_znormal}|${_zbold}--fpath${_znormal} <path> Will add specified path to fpath. The path is relative to the
|
||||
module root directory. Default: ${_zbold}functions${_znormal}, if the subdirectory
|
||||
exists and is non-empty.
|
||||
${_zbold}-a${_znormal}|${_zbold}--autoload${_znormal} <func_name> Will autoload specified function. Default: all valid names inside
|
||||
the ${_zbold}functions${_znormal} subdirectory, if any.
|
||||
${_zbold}-s${_znormal}|${_zbold}--source${_znormal} <file_path> Will source specified file. The path is relative to the module
|
||||
root directory. Default: ${_zbold}init.zsh${_znormal}, if a non-empty ${_zbold}functions${_znormal} sub-
|
||||
directory exists, else the largest of the files matching the glob
|
||||
${_zbold}(init.zsh|${_znormal}<name>${_zbold}.(zsh|plugin.zsh|zsh-theme|sh))${_znormal}, 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.
|
||||
${_zbold}-c${_znormal}|${_zbold}--cmd${_znormal} <command> Will execute specified command. Occurrences of the ${_zbold}{}${_znormal} placeholder
|
||||
in the command are substituted by the module root directory path.
|
||||
I.e., ${_zbold}-s 'foo.zsh'${_znormal} and ${_zbold}-c 'source {}/foo.zsh'${_znormal} 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 (( ! # )); then
|
||||
print -u2 -lR "${_zerror}${funcfiletrace[1]}: Missing zmodule url${_znormal}" '' ${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 "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Missing argument for zmodule option ${_zbold}${1}${_znormal}" '' ${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 "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Module already defined with a different URL. Expected ${_zbold}${_zurls[${zname}]}${_znormal}" '' ${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|--if-ostype|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
|
||||
if (( # < 2 )); then
|
||||
print -u2 -lR "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Missing argument for zmodule option ${_zbold}${1}${_znormal}" '' ${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 "${_zwarn}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalyellow} The zmodule option ${_zbold}${1}${_znormalyellow} has no effect for external modules${_znormal}"
|
||||
;;
|
||||
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}]} ))"
|
||||
;;
|
||||
--if-ostype)
|
||||
shift
|
||||
_zifs[${zroot_dir}]="[[ \${OSTYPE} == ${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 "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalred} Unknown zmodule option ${_zbold}${1}${_znormal}" '' ${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 "${_zerror}${funcfiletrace[1]}:${_zbold}${zname}: ${zroot_dir}${_znormalred} not found${_znormal}"
|
||||
_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 "${_zwarn}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalyellow} Nothing found to be initialized. Customize the module name, root or initialization with ${_zbold}zmodule${_znormalyellow} options.${_znormal}" '' ${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
|
||||
}
|
|
@ -1,12 +1,8 @@
|
|||
autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then
|
||||
print -u2 -R "${_zred}${0}: Error starting zimfw. You're using Zsh version ${_zbold}${ZSH_VERSION}${_znormalred} and versions < ${_zbold}<%= min_zsh_version %>${_znormalred} are not supported. Update your Zsh.${_znormal}"
|
||||
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"
|
||||
return 1
|
||||
fi
|
||||
autoload -Uz zargs
|
||||
|
||||
if (( ! ${+ZIM_HOME} )); then
|
||||
print -u2 -R "${_zred}${0}: ${_zbold}ZIM_HOME${_znormalred} not defined${_znormal}"
|
||||
return 1
|
||||
fi
|
||||
# Define zimfw location
|
||||
typeset -g __ZIMFW_FILE=${0}
|
||||
# Define Zim location
|
||||
if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:h}
|
||||
|
|
|
@ -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 -R "${_zokay}${_zbold}${2}:${_znormal} Already up to date"
|
||||
_zimfw_print -PR "<%= okay %>%B${2}:%b Already up to date"
|
||||
else
|
||||
if [[ -e ${2} ]]; then
|
||||
command mv -f ${2}{,.old} || return 1
|
||||
fi
|
||||
command mv -f ${1} ${2} && command chmod a+r ${2} && _zimfw_print -R "${_zokay}${_zbold}${2}:${_znormal} Updated.${_zrestartmsg}"
|
||||
command mv -f ${1} ${2} && _zimfw_print -PR "<%= okay %>%B${2}:%b Updated.${_zrestartmsg}"
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
_zimfw_build_init() {
|
||||
local -r ztarget=${ZIM_HOME}/init.zsh
|
||||
# Force update of init.zsh if it's older than .zimrc
|
||||
if [[ ${ztarget} -ot ${_zconfig} ]]; then
|
||||
if [[ ${ztarget} -ot ${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} ]]; then
|
||||
command mv -f ${ztarget}{,.old} || return 1
|
||||
fi
|
||||
_zimfw_mv =(
|
||||
print -R '# FILE AUTOMATICALLY GENERATED FROM '${_zconfig}
|
||||
print '# EDIT THE SOURCE FILE AND THEN RUN zimfw build. DO NOT DIRECTLY EDIT THIS FILE!'
|
||||
print
|
||||
print -R 'if [[ -e ${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} ]] zimfw() { source '${${(qqq)__ZIMFW_FILE}/${HOME}/\${HOME}}' "${@}" }'
|
||||
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
|
||||
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
|
||||
local zroot_dir zpre
|
||||
local -a zif_functions zif_cmds zroot_functions zroot_cmds
|
||||
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})
|
||||
|
@ -24,7 +22,7 @@ _zimfw_build_init() {
|
|||
fi
|
||||
done
|
||||
zpre=$'*\0'
|
||||
if (( ${#_zfpaths} )) print -R 'fpath=('${${(qqq)${_zfpaths#${~zpre}}:a}/${HOME}/\${HOME}}' ${fpath})'
|
||||
if (( ${#_zfpaths} )) print 'fpath=('${(q-)${_zfpaths#${~zpre}}:a}' ${fpath})'
|
||||
if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}}
|
||||
for zroot_dir in ${_zroot_dirs}; do
|
||||
zpre=${zroot_dir}$'\0'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
_zimfw_build_login_init() {
|
||||
local -r ztarget=${ZIM_HOME}/login_init.zsh
|
||||
# Force update of login_init.zsh if it's older than .zimrc
|
||||
if [[ ${ztarget} -ot ${_zconfig} ]]; then
|
||||
if [[ ${ztarget} -ot ${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} ]]; then
|
||||
command mv -f ${ztarget}{,.old} || return 1
|
||||
fi
|
||||
_zimfw_mv =(
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
_zimfw_build() {
|
||||
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
|
||||
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print -P '<%= done %>Done with build.'
|
||||
}
|
||||
|
|
230
src/stage2/30_zmodule.zsh.erb
Normal file
230
src/stage2/30_zmodule.zsh.erb
Normal file
|
@ -0,0 +1,230 @@
|
|||
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
|
||||
}
|
|
@ -1,25 +1,20 @@
|
|||
_zimfw_source_zimrc() {
|
||||
<%= render_all("src/functions/*.erb") %>
|
||||
{
|
||||
local -r _zflags=${1}
|
||||
local -i _zfailed=0
|
||||
if ! source ${_zconfig} || (( _zfailed )); then
|
||||
print -u2 -R "${_zred}Failed to source ${_zbold}${_zconfig}${_znormal}"
|
||||
return 1
|
||||
fi
|
||||
if (( _zflags & 1 && ${#_znames} == 0 )); then
|
||||
print -u2 -R "${_zred}No modules defined in ${_zbold}${_zconfig}${_znormal}"
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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 -R "${_zbold}${zunused:t}:${_znormal} ${zunused}${1}"
|
||||
for zunused (${_zunused_dirs}) _zimfw_print -PR "%B${zunused:t}:%b ${zunused}${1}"
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
_zimfw_check_dumpfile() {
|
||||
_zimfw_print -u2 "${_zwarn}Deprecated action. This is now handled by the completion module alone.${_znormal}"
|
||||
_zimfw_print -u2 -PR '%F{yellow}<%= warn %>Deprecated action. This is now handled by the completion module alone.'
|
||||
}
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
_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 ${${${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs --sort=-v:refname \
|
||||
print -R ${${(On)${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs \
|
||||
https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &!
|
||||
fi
|
||||
else
|
||||
# foreground check
|
||||
local tags
|
||||
tags=$(command git ls-remote --tags --refs --sort=-v:refname https://github.com/zimfw/zimfw.git 'v*') || return 1
|
||||
>! ${_zversion_target} <<<${${${(f)tags}##*v}[1]} || return 1
|
||||
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
|
||||
fi
|
||||
fi
|
||||
if [[ -f ${_zversion_target} ]]; then
|
||||
local -r zlatest_version=$(<${_zversion_target})
|
||||
if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
|
||||
_zimfw_print -u2 -R "${_zyellow}Latest zimfw version is ${_zbold}${zlatest_version}${_znormalyellow}. You're using version ${_zbold}${_zversion}${_znormalyellow}. Run ${_zbold}zimfw upgrade${_znormalyellow} to upgrade.${_znormal}"
|
||||
_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"
|
||||
return 4
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -4,5 +4,5 @@ _zimfw_clean_compiled() {
|
|||
local zopt
|
||||
if (( _zprintlevel > 0 )) zopt=-v
|
||||
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) && \
|
||||
_zimfw_print "Done with clean-compiled. Restart your terminal or run ${_zbold}zimfw compile${_znormal} to re-compile."
|
||||
_zimfw_print -P '<%= done %>Done with clean-compiled. Restart your terminal or run %Bzimfw compile%b to re-compile.'
|
||||
}
|
||||
|
|
|
@ -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 -R "Done with clean-dumpfile.${_zrestartmsg}"
|
||||
_zimfw_print -P "<%= done %>Done with clean-dumpfile.${_zrestartmsg}"
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
_zimfw_compile() {
|
||||
# Compile zimfw scripts
|
||||
# Compile Zim scripts
|
||||
local zroot_dir zfile
|
||||
for zroot_dir in ${_zroot_dirs:|_zdisabled_root_dirs}; do
|
||||
if [[ ! -w ${zroot_dir} ]]; then
|
||||
_zimfw_print -R "${_zwarn}${_zbold}${zroot_dir}:${_znormalyellow} No write permission, unable to compile.${_znormal}"
|
||||
_zimfw_print -PR "%F{yellow}<%= warn %>%B${zroot_dir}:%b No write permission, unable to compile.%f"
|
||||
continue
|
||||
fi
|
||||
for zfile in ${zroot_dir}/(^*test*/)#*.zsh(|-theme)(N-.); do
|
||||
if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then
|
||||
zcompile -UR ${zfile} && _zimfw_print -R "${_zokay}${_zbold}${zfile}.zwc:${_znormal} Compiled"
|
||||
zcompile -UR ${zfile} && _zimfw_print -PR "<%= okay %>%B${zfile}.zwc:%b Compiled"
|
||||
fi
|
||||
done
|
||||
done
|
||||
_zimfw_print 'Done with compile.'
|
||||
_zimfw_print -P '<%= done %>Done with compile.'
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
_zimfw_info() {
|
||||
_zimfw_info_print_symlink 'zimfw config' ${_zconfig}
|
||||
_zimfw_info_print_symlink ZIM_HOME ${ZIM_HOME}
|
||||
_zimfw_info_print_symlink 'zimfw script' ${__ZIMFW_FILE}
|
||||
print -R 'zimfw version: '${_zversion}' (built at <%= Time.now.utc %>, previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)'
|
||||
local zparam
|
||||
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZSH_VERSION; do
|
||||
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do
|
||||
print -R ${(r.22....:.)zparam}${(P)zparam}
|
||||
done
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
_zimfw_info_print_symlink() {
|
||||
print -Rn ${(r.22....:.)1}${2}
|
||||
if [[ -L ${2} ]] print -Rn ' -> '${2:A}
|
||||
print
|
||||
}
|
|
@ -1,17 +1,11 @@
|
|||
_zimfw_uninstall() {
|
||||
if (( _zprintlevel <= 0 )); then
|
||||
command rm -rf ${_zunused_dirs} || return 1
|
||||
else
|
||||
local zunused_dir
|
||||
print "Found ${_zbold}${#_zunused_dirs}${_znormal} unused module(s)."
|
||||
for zunused_dir in ${_zunused_dirs}; do
|
||||
if read -q "?Uninstall ${zunused_dir} [y/N]? "; then
|
||||
print
|
||||
command rm -rfv ${zunused_dir} || return 1
|
||||
else
|
||||
print
|
||||
fi
|
||||
done
|
||||
print 'Done with uninstall.'
|
||||
local zopt
|
||||
if (( _zprintlevel > 0 )) zopt=-v
|
||||
if (( ${#_zunused_dirs} )); then
|
||||
if (( _zprintlevel <= 0 )) || read -q "?Uninstall ${#_zunused_dirs} module(s) listed above [y/N]? "; then
|
||||
_zimfw_print
|
||||
command rm -rf ${zopt} ${_zunused_dirs} || return 1
|
||||
fi
|
||||
fi
|
||||
_zimfw_print -P '<%= done %>Done with uninstall.'
|
||||
}
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
_zimfw_upgrade() {
|
||||
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 "${_zred}No write permission to ${_zbold}${ztarget:h}${_znormalred}. Will not try to upgrade.${_znormal}"
|
||||
return 1
|
||||
fi
|
||||
local -r ztarget=${ZIM_HOME}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
|
||||
{
|
||||
if (( ${+commands[curl]} )); then
|
||||
command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1
|
||||
|
@ -12,7 +8,7 @@ _zimfw_upgrade() {
|
|||
if (( _zprintlevel <= 1 )) zopt=-q
|
||||
if ! command wget -nv ${zopt} -O ${ztarget}.new.gz ${zurl}; then
|
||||
if (( _zprintlevel <= 1 )); then
|
||||
print -u2 -R "${_zred}Failed to download ${_zbold}${zurl}${_znormalred}. Use ${_zbold}-v${_znormalred} option to see details.${_znormal}"
|
||||
print -u2 -PR "%F{red}<%= failed %>Failed to download %B${zurl}%b. Use %B-v%b option to see details.%f"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
|
@ -21,7 +17,7 @@ _zimfw_upgrade() {
|
|||
# .latest_version can be outdated and will yield a false warning if zimfw is
|
||||
# upgraded before .latest_version is refreshed. Bad thing about having a cache.
|
||||
_zimfw_mv ${ztarget}{.new,} && command rm -f ${ZIM_HOME}/.latest_version && \
|
||||
_zimfw_print 'Done with upgrade.'
|
||||
_zimfw_print -P '<%= done %>Done with upgrade.'
|
||||
} always {
|
||||
command rm -f ${ztarget}.new{,.gz}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,22 @@
|
|||
_zimfw_run_list() {
|
||||
local -r zname=${1}
|
||||
local -r zdir=${_zdirs[${zname}]}
|
||||
print -nR "${_zbold}${zname}:${_znormal} ${zdir}"
|
||||
print -PnR "%B${zname}:%b ${zdir}"
|
||||
if [[ -z ${_zurls[${zname}]} ]] print -n ' (external)'
|
||||
if (( ${_zfrozens[${zname}]} )) print -n ' (frozen)'
|
||||
if (( ${_zdisabled_root_dirs[(I)${zdir}]} )) print -n ' (disabled)'
|
||||
print
|
||||
if (( _zprintlevel > 1 )); then
|
||||
if [[ ${_zfrozens[${zname}]} -eq 0 && -n ${_zurls[${zname}]} ]]; then
|
||||
if [[ ${_ztools[${zname}]} == mkdir ]]; then
|
||||
print ' From: mkdir'
|
||||
print -nR " From: ${_zurls[${zname}]}, "
|
||||
if [[ -z ${_zrevs[${zname}]} ]]; then
|
||||
print -n 'default branch'
|
||||
else
|
||||
print -nR " From: ${_zurls[${zname}]}, "
|
||||
if [[ -z ${_zrevs[${zname}]} ]]; then
|
||||
print -n 'default branch'
|
||||
else
|
||||
print -nR "${_ztypes[${zname}]} ${_zrevs[${zname}]}"
|
||||
fi
|
||||
print -nR ", using ${_ztools[${zname}]}"
|
||||
if (( ! _zsubmodules[${zname}] )) print -n ', no git submodules'
|
||||
print
|
||||
print -nR "${_ztypes[${zname}]} ${_zrevs[${zname}]}"
|
||||
fi
|
||||
print -nR ", using ${_ztools[${zname}]}"
|
||||
if (( ! _zsubmodules[${zname}] )) print -n ', no git submodules'
|
||||
print
|
||||
if [[ -n ${_zonpulls[${zname}]} ]] print -R " On-pull: ${_zonpulls[${zname}]}"
|
||||
fi
|
||||
# Match the current module dir prefix from _zroot_dirs
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
_zimfw_create_dir() {
|
||||
if ! ERR=$(command mkdir -p ${1} 2>&1); then
|
||||
_zimfw_print_error "Error creating ${1}" ${ERR}
|
||||
return 1
|
||||
fi
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
_zimfw_print_error() {
|
||||
print -u2 -lR $'<%= clear_line %>'"${_zerror}${_zbold}${_zname}:${_znormalred} ${1}${_znormal}" ${2:+${(F):- ${(f)^2}}}
|
||||
print -u2 -PlR <%= clear_line %>"%F{red}<%= error %>%B${_zname}:%b ${1}%f" ${2:+${(F):- ${(f)^2}}}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
_zimfw_print_okay() {
|
||||
if (( _zprintlevel > ${2:-0} )) print -lR $'<%= clear_line %>'"${_zokay}${_zbold}${_zname}:${_znormal} ${1}" ${3:+${(F):- ${(f)^3}}}
|
||||
if (( _zprintlevel > ${2:-0} )) print -PlR <%= clear_line %>"<%= okay %>%B${_zname}:%b ${1}" ${3:+${(F):- ${(f)^3}}}
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
_zimfw_print_warn() {
|
||||
_zimfw_print -u2 -R $'<%= clear_line %>'"${_zwarn}${_zbold}${_zname}:${_znormalyellow} ${1}${_znormal}"
|
||||
}
|
|
@ -4,16 +4,22 @@ _zimfw_download_tarball() {
|
|||
readonly REPO=${match[4]%.git}
|
||||
fi
|
||||
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
|
||||
_zimfw_print_error "${URL} is not a valid URL. Will not try to ${ACTION}. The zimfw degit tool only supports GitHub URLs. Use zmodule option ${_zbold}--use git${_znormalred} to use git instead."
|
||||
_zimfw_print_error "${URL} is not a valid GitHub URL. Will not try to ${_zaction}."
|
||||
return 1
|
||||
fi
|
||||
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
|
||||
{
|
||||
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
|
||||
# Previous REV is in line 2, reserved for future use.
|
||||
readonly INFO_HEADER=${INFO[3]}
|
||||
if [[ -r ${INFO_TARGET} ]]; then
|
||||
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
|
||||
if [[ ${URL} != ${INFO[1]} ]]; then
|
||||
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
|
||||
return 1
|
||||
fi
|
||||
# Previous REV is in line 2, reserved for future use.
|
||||
readonly INFO_HEADER=${INFO[3]}
|
||||
fi
|
||||
readonly TARBALL_URL=https://api.github.com/repos/${REPO}/tarball/${REV}
|
||||
if [[ ${ACTION} == check ]]; then
|
||||
if [[ ${_zaction} == check ]]; then
|
||||
if [[ -z ${INFO_HEADER} ]] return 0
|
||||
if (( ${+commands[curl]} )); then
|
||||
command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET}
|
||||
|
@ -51,7 +57,7 @@ _zimfw_download_tarball() {
|
|||
_zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response"
|
||||
return 1
|
||||
fi
|
||||
if [[ ${ACTION} == check ]]; then
|
||||
if [[ ${_zaction} == check ]]; then
|
||||
command touch ${TARBALL_TARGET} # Update available
|
||||
else
|
||||
if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then
|
||||
|
@ -65,41 +71,25 @@ _zimfw_download_tarball() {
|
|||
}
|
||||
|
||||
_zimfw_untar_tarball() {
|
||||
if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then
|
||||
if ! ERR=$(command tar -C ${1} --strip=1 -xzf ${TARBALL_TARGET} 2>&1); then
|
||||
_zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
|
||||
return 1
|
||||
fi
|
||||
local zsubdir
|
||||
for zsubdir in ${1}/*(/); do
|
||||
if ! ERR=$(command mv -f ${zsubdir}/*(DN) ${1} 2>&1 && command rmdir ${zsubdir} 2>&1); then
|
||||
_zimfw_print_error "Error moving ${zsubdir}" ${ERR}
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
_zimfw_create_dir() {
|
||||
if ! ERR=$(command mkdir -p ${1} 2>&1); then
|
||||
_zimfw_print_error "Error creating ${1}" ${ERR}
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
_zimfw_tool_degit() {
|
||||
# This runs in a subshell
|
||||
readonly -i SUBMODULES=${6}
|
||||
readonly ACTION=${1} DIR=${2} URL=${3} REV=${5} ONPULL=${7} TEMP=.zdegit_${sysparams[pid]}_${RANDOM}
|
||||
readonly -i SUBMODULES=${5}
|
||||
readonly DIR=${1} URL=${2} REV=${4} ONPULL=${6} TEMP=.zdegit_${sysparams[pid]}
|
||||
readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit
|
||||
case ${ACTION} in
|
||||
pre|prereinstall)
|
||||
local premsg
|
||||
if [[ ${ACTION} == pre ]] premsg=" Use zmodule option ${_zbold}-z${_znormalred}|${_zbold}--frozen${_znormalred} to disable this error or run ${_zbold}zimfw reinstall${_znormalred} to reinstall."
|
||||
if [[ -e ${DIR} ]]; then
|
||||
if [[ ! -r ${INFO_TARGET} ]]; then
|
||||
_zimfw_print_error $'Module was not installed using zimfw\'s degit.'${premsg}
|
||||
return 1
|
||||
fi
|
||||
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
|
||||
if [[ ${URL} != ${INFO[1]} ]]; then
|
||||
_zimfw_print_error 'The zimfw degit URL does not match. Expected '${URL}.${premsg}
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
case ${_zaction} in
|
||||
install)
|
||||
{
|
||||
_zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1
|
||||
|
@ -111,10 +101,14 @@ _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"
|
||||
return 0
|
||||
fi
|
||||
readonly DIR_NEW=${DIR}${TEMP}
|
||||
{
|
||||
_zimfw_download_tarball || return 1
|
||||
if [[ ${ACTION} == check ]]; then
|
||||
if [[ ${_zaction} == check ]]; then
|
||||
if [[ -e ${TARBALL_TARGET} ]]; then
|
||||
_zimfw_print_okay 'Update available'
|
||||
return 4
|
||||
|
@ -145,7 +139,7 @@ _zimfw_tool_degit() {
|
|||
;;
|
||||
esac
|
||||
# Check after successful install or update
|
||||
if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
|
||||
_zimfw_print_warn "Module contains git submodules, which are not supported by zimfw's degit. Use zmodule option ${_zbold}--no-submodules${_znormalyellow} to disable this warning."
|
||||
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"
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -1,23 +1,9 @@
|
|||
_zimfw_tool_git() {
|
||||
# This runs in a subshell
|
||||
readonly -i SUBMODULES=${6}
|
||||
readonly ACTION=${1} DIR=${2} URL=${3} TYPE=${4} ONPULL=${7}
|
||||
REV=${5}
|
||||
case ${ACTION} in
|
||||
pre|prereinstall)
|
||||
local premsg
|
||||
if [[ ${ACTION} == pre ]] premsg=" Use zmodule option ${_zbold}-z${_znormalred}|${_zbold}--frozen${_znormalred} to disable this error or run ${_zbold}zimfw reinstall${_znormalred} to reinstall."
|
||||
if [[ -e ${DIR} ]]; then
|
||||
if [[ ! -r ${DIR}/.git ]]; then
|
||||
_zimfw_print_error 'Module was not installed using git.'${premsg}
|
||||
return 1
|
||||
fi
|
||||
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
|
||||
_zimfw_print_error 'The git URL does not match. Expected '${URL}.${premsg}
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
readonly -i SUBMODULES=${5}
|
||||
readonly DIR=${1} URL=${2} TYPE=${3} ONPULL=${6}
|
||||
REV=${4}
|
||||
case ${_zaction} in
|
||||
install)
|
||||
if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then
|
||||
_zimfw_pull_print_okay Installed
|
||||
|
@ -27,6 +13,14 @@ _zimfw_tool_git() {
|
|||
fi
|
||||
;;
|
||||
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"
|
||||
return 0
|
||||
fi
|
||||
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
|
||||
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
|
||||
return 1
|
||||
fi
|
||||
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
|
||||
_zimfw_print_error 'Error during git fetch' ${ERR}
|
||||
return 1
|
||||
|
@ -46,7 +40,7 @@ _zimfw_tool_git() {
|
|||
fi
|
||||
fi
|
||||
TO_REV=${REV}@{u}
|
||||
if [[ ${ACTION} == check ]]; then
|
||||
if [[ ${_zaction} == check ]]; then
|
||||
readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${TO_REV} -- 2>/dev/null)
|
||||
if (( BEHIND )); then
|
||||
_zimfw_print_okay "Update available [behind ${BEHIND}]"
|
||||
|
@ -58,7 +52,7 @@ _zimfw_tool_git() {
|
|||
fi
|
||||
else
|
||||
if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then
|
||||
if [[ ${ACTION} == check ]]; then
|
||||
if [[ ${_zaction} == check ]]; then
|
||||
_zimfw_print_okay 'Already up to date' 1
|
||||
return 0
|
||||
else
|
||||
|
@ -66,17 +60,13 @@ _zimfw_tool_git() {
|
|||
return ${?}
|
||||
fi
|
||||
fi
|
||||
if [[ ${ACTION} == check ]]; then
|
||||
if [[ ${_zaction} == check ]]; then
|
||||
_zimfw_print_okay 'Update available'
|
||||
return 4
|
||||
fi
|
||||
TO_REV=${REV}
|
||||
fi
|
||||
if [[ -z ${NO_COLOR} ]]; then
|
||||
LOG=$(command git -C ${DIR} log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${TO_REV} -- 2>/dev/null)
|
||||
else
|
||||
LOG=$(command git -C ${DIR} log --graph --format='%h %s (%cr)' ..${TO_REV} -- 2>/dev/null)
|
||||
fi
|
||||
LOG=$(command git -C ${DIR} log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${TO_REV} -- 2>/dev/null)
|
||||
if ! ERR=$(command git -C ${DIR} checkout -q ${REV} -- 2>&1); then
|
||||
_zimfw_print_error 'Error during git checkout' ${ERR}
|
||||
return 1
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
_zimfw_tool_mkdir() {
|
||||
# This runs in a subshell
|
||||
readonly -i SUBMODULES=${6}
|
||||
readonly ACTION=${1} DIR=${2} TYPE=${4} REV=${5} ONPULL=${7}
|
||||
if [[ ${ACTION} == (pre|prereinstall|check) ]] return 0
|
||||
if [[ -n ${REV} ]]; then
|
||||
_zimfw_print_warn "The zmodule option ${_zbold}-${TYPE[1]}${_znormalyellow}|${_zbold}--${TYPE}${_znormalyellow} has no effect when using the mkdir tool"
|
||||
fi
|
||||
if (( ! SUBMODULES )); then
|
||||
_zimfw_print_warn "The zmodule option ${_zbold}--no-submodules${_znormalyellow} 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
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
_zimfw_run_tool() {
|
||||
local zaction=${1}
|
||||
local -r _zname=${2}
|
||||
local -r _zname=${1}
|
||||
if [[ -z ${_zurls[${_zname}]} ]]; then
|
||||
_zimfw_print_okay 'Skipping external module' 1
|
||||
return 0
|
||||
|
@ -9,60 +8,38 @@ _zimfw_run_tool() {
|
|||
_zimfw_print_okay 'Skipping frozen module' 1
|
||||
return 0
|
||||
fi
|
||||
local -r ztool=${_ztools[${_zname}]}
|
||||
if [[ ${ztool} != (degit|git|mkdir) ]]; then
|
||||
_zimfw_print_error "Unknown tool ${ztool}"
|
||||
return 1
|
||||
fi
|
||||
set "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
|
||||
if [[ ${zaction} == reinstall ]]; then
|
||||
_zimfw_tool_${ztool} prereinstall "${@}" && return 0
|
||||
if (( _zprintlevel > 0 )); then
|
||||
if read -q "?Reinstall ${_zname} [y/N]? "; then
|
||||
print
|
||||
else
|
||||
print
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
local -r zdir_new=.${_zdirs[${_zname}]}_${sysparams[pid]}_${RANDOM}
|
||||
_zimfw_print -nR 'Reinstalling '${_zname}'<%= ellipsis %>'
|
||||
{
|
||||
_zimfw_tool_${ztool} install ${zdir_new} "${@:2}" || return 1
|
||||
if ! ERR=$({ command rm -rf ${_zdirs[${_zname}]} && command mv -f ${zdir_new} ${_zdirs[${_zname}]} } 2>&1); then
|
||||
_zimfw_print_error "Error updating ${_zdirs[${_zname}]}" ${ERR}
|
||||
return 1
|
||||
fi
|
||||
} always {
|
||||
command rm -rf ${zdir_new} 2>/dev/null
|
||||
}
|
||||
return 0
|
||||
else
|
||||
_zimfw_tool_${ztool} pre "${@}" || return 1
|
||||
fi
|
||||
case ${zaction} in
|
||||
case ${_zaction} in
|
||||
install)
|
||||
if [[ -e ${_zdirs[${_zname}]} ]]; then
|
||||
_zimfw_print_okay 'Skipping already installed module' 1
|
||||
return 0
|
||||
fi
|
||||
_zimfw_print -nR $'<%= clear_line %>Installing '${_zname}'<%= ellipsis %>'
|
||||
_zimfw_print -nR <%= clear_line %>"Installing ${_zname}<%= ellipsis %>"
|
||||
;;
|
||||
check|update)
|
||||
if [[ ! -d ${_zdirs[${_zname}]} ]]; then
|
||||
_zimfw_print_error "Not installed. Run ${_zbold}zimfw install${_znormalred} to install."
|
||||
_zimfw_print_error 'Not installed. Run %Bzimfw install%b to install.'
|
||||
return 1
|
||||
fi
|
||||
if [[ ${zaction} == check ]]; then
|
||||
if (( _zprintlevel > 1 )) print -nR $'<%= clear_line %>Checking '${_zname}'<%= ellipsis %>'
|
||||
if [[ ${_zaction} == check ]]; then
|
||||
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
|
||||
;;
|
||||
*)
|
||||
_zimfw_print_error "Unknown action ${zaction}"
|
||||
_zimfw_print_error "Unknown action ${_zaction}"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
local -r ztool=${_ztools[${_zname}]}
|
||||
case ${ztool} in
|
||||
degit|git)
|
||||
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
|
||||
;;
|
||||
*)
|
||||
_zimfw_print_error "Unknown tool ${ztool}"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
_zimfw_tool_${ztool} ${zaction} "${@}"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
_zimfw_run_tool_action() {
|
||||
local -i zmaxprocs=0
|
||||
if [[ ${1} == reinstall ]] zmaxprocs=1
|
||||
_zimfw_source_zimrc 1 || return 1
|
||||
zargs -n 2 -P ${zmaxprocs} -- "${_znames[@]}" -- _zimfw_run_tool ${1}
|
||||
local -r _zaction=${1}
|
||||
_zimfw_source_zimrc 1 && zargs -n 1 -P 0 -- "${_znames[@]}" -- _zimfw_run_tool
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -1,74 +1,57 @@
|
|||
zimfw() {
|
||||
builtin emulate -L zsh -o EXTENDED_GLOB
|
||||
if [[ -z ${NO_COLOR} ]]; then
|
||||
local -r _znormal=$'\E[0m' _zbold=$'\E[1m' _zred=$'\E[31m' _znormalred=$'\E[0;31m' _zgreen=$'\E[32m' _zyellow=$'\E[33m' _znormalyellow=$'\E[0;33m'
|
||||
else
|
||||
local -r _znormal= _zbold= _zred= _znormalred= _zgreen= _zyellow= _znormalyellow=
|
||||
fi
|
||||
local -r _zerror="${_zred}<%= error %>" _zokay="${_zgreen}<%= okay %>${_znormal}" _zwarn="${_zyellow}<%= warn %>"
|
||||
local -r _zconfig=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zversion='<%= version %>'
|
||||
local -r zusage="Usage: ${_zbold}${0}${_znormal} <action> [${_zbold}-q${_znormal}|${_zbold}-v${_znormal}]
|
||||
local -r _zversion='<%= version %>' _zversion_target=${ZIM_HOME}/.latest_version zusage="Usage: %B${0}%b <action> [%B-q%b|%B-v%b]
|
||||
|
||||
Actions:
|
||||
${_zbold}build${_znormal} Build ${_zbold}${ZIM_HOME}/init.zsh${_znormal} and ${_zbold}${ZIM_HOME}/login_init.zsh${_znormal}.
|
||||
Also does ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see its output.
|
||||
${_zbold}clean${_znormal} Clean all. Does both ${_zbold}clean-compiled${_znormal} and ${_zbold}clean-dumpfile${_znormal}.
|
||||
${_zbold}clean-compiled${_znormal} Clean Zsh compiled files.
|
||||
${_zbold}clean-dumpfile${_znormal} Clean completion dumpfile.
|
||||
${_zbold}compile${_znormal} Compile Zsh files.
|
||||
${_zbold}help${_znormal} Print this help.
|
||||
${_zbold}info${_znormal} Print zimfw and system info.
|
||||
${_zbold}list${_znormal} List all modules currently defined in ${_zbold}${_zconfig}${_znormal}.
|
||||
Use ${_zbold}-v${_znormal} to also see the modules details.
|
||||
${_zbold}init${_znormal} Same as ${_zbold}install${_znormal}, but with output tailored to be used at terminal startup.
|
||||
${_zbold}install${_znormal} Install new modules. Also does ${_zbold}build${_znormal}, ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see their
|
||||
%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
|
||||
output, any on-pull output and skipped modules.
|
||||
${_zbold}reinstall${_znormal} Reinstall modules that failed check. Prompts for confirmation. Use ${_zbold}-q${_znormal} for
|
||||
quiet reinstall. Also does ${_zbold}build${_znormal}, ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see their output,
|
||||
any on-pull output and skipped modules.
|
||||
${_zbold}uninstall${_znormal} Delete unused modules. Prompts for confirmation. Use ${_zbold}-q${_znormal} for quiet uninstall.
|
||||
${_zbold}check${_znormal} Check if updates for current modules are available. Use ${_zbold}-v${_znormal} to also see
|
||||
%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
|
||||
skipped and up to date modules.
|
||||
${_zbold}update${_znormal} Update current modules. Also does ${_zbold}build${_znormal}, ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see their
|
||||
%Bupdate%b Update current modules. Also does %Bbuild%b, %Bcompile%b. Use %B-v%b to also see their
|
||||
output, any on-pull output and skipped modules.
|
||||
${_zbold}check-version${_znormal} Check if a new version of zimfw is available.
|
||||
${_zbold}upgrade${_znormal} Upgrade zimfw. Also does ${_zbold}compile${_znormal}. Use ${_zbold}-v${_znormal} to also see its output.
|
||||
${_zbold}version${_znormal} Print zimfw version.
|
||||
%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.
|
||||
|
||||
Options:
|
||||
${_zbold}-q${_znormal} Quiet (yes to prompts and only outputs errors)
|
||||
${_zbold}-v${_znormal} Verbose (outputs more details)"
|
||||
%B-q%b Quiet (yes to prompts and only outputs errors)
|
||||
%B-v%b 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 -lR "${_zred}${0}: Too many options${_znormal}" '' ${zusage}
|
||||
print -u2 -PlR "%F{red}${0}: Too many options%f" '' ${zusage}
|
||||
return 2
|
||||
elif (( # > 1 )); then
|
||||
case ${2} in
|
||||
-q) _zprintlevel=0 ;;
|
||||
-v) _zprintlevel=2 ;;
|
||||
*)
|
||||
print -u2 -lR "${_zred}${0}: Unknown option ${2}${_znormal}" '' ${zusage}
|
||||
print -u2 -PlR "%F{red}${0}: Unknown option ${2}%f" '' ${zusage}
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
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 ! zstyle -t ':zim' disable-version-check && [[ ${1} != check-version ]]; then
|
||||
# If .latest_version does not exist or was not modified in the last 30 days
|
||||
[[ -f ${_zversion_target}(#qNm-30) ]]; local -r zversion_check_force=${?}
|
||||
_zimfw_check_version ${zversion_check_force} 1
|
||||
fi
|
||||
|
||||
if [[ ! -w ${ZIM_HOME} && ${1} == (build|check|init|install|update|reinstall|check-version) ]]; then
|
||||
print -u2 -R "${_zred}${0}: No write permission to ${_zbold}${ZIM_HOME}${_znormalred}. Will not try to ${1}.${_znormal}"
|
||||
return 1
|
||||
fi
|
||||
local _zrestartmsg=' Restart your terminal for changes to take effect.'
|
||||
case ${1} in
|
||||
build)
|
||||
|
@ -77,11 +60,11 @@ Options:
|
|||
_zimfw_compile
|
||||
;;
|
||||
check-dumpfile) _zimfw_check_dumpfile ;;
|
||||
clean) _zimfw_source_zimrc 0 && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
|
||||
clean-compiled) _zimfw_source_zimrc 0 && _zimfw_clean_compiled ;;
|
||||
clean) _zimfw_source_zimrc 2 && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
|
||||
clean-compiled) _zimfw_source_zimrc 2 && _zimfw_clean_compiled ;;
|
||||
clean-dumpfile) _zimfw_clean_dumpfile ;;
|
||||
compile) _zimfw_source_zimrc 0 && _zimfw_compile ;;
|
||||
help) print -R ${zusage} ;;
|
||||
compile) _zimfw_source_zimrc 2 && _zimfw_compile ;;
|
||||
help) print -PR ${zusage} ;;
|
||||
info) _zimfw_info ;;
|
||||
list)
|
||||
_zimfw_source_zimrc 3 && zargs -n 1 -- "${_znames[@]}" -- _zimfw_run_list && \
|
||||
|
@ -91,31 +74,31 @@ Options:
|
|||
_zrestartmsg=
|
||||
_zimfw_run_tool_action ${1} || return 1
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_print -R "Done with ${1}." # Only printed in verbose mode
|
||||
_zimfw_print -PR "<%= done %>Done with ${1}." # Only printed in verbose mode
|
||||
;;
|
||||
init)
|
||||
_zrestartmsg=
|
||||
_zimfw_run_tool_action install || return 1
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_print 'Done with install.' # Only printed in verbose mode
|
||||
_zimfw_print -PR "<%= done %>Done with install." # Only printed in verbose mode
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
|
||||
;;
|
||||
install|update|reinstall)
|
||||
install|update)
|
||||
_zimfw_run_tool_action ${1} || return 1
|
||||
_zimfw_print -R "Done with ${1}.${_zrestartmsg}"
|
||||
_zimfw_print -PR "<%= done %>Done with ${1}.${_zrestartmsg}"
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
|
||||
;;
|
||||
uninstall) _zimfw_source_zimrc 0 && _zimfw_list_unuseds && _zimfw_uninstall ;;
|
||||
uninstall) _zimfw_source_zimrc 2 && _zimfw_list_unuseds && _zimfw_uninstall ;;
|
||||
check-version) _zimfw_check_version 1 ;;
|
||||
upgrade)
|
||||
_zimfw_upgrade || return 1
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_source_zimrc 0 && _zimfw_compile
|
||||
_zimfw_source_zimrc 2 && _zimfw_compile
|
||||
;;
|
||||
version) print -R ${_zversion} ;;
|
||||
version) print -PR ${_zversion} ;;
|
||||
*)
|
||||
print -u2 -lR "${_zred}${0}: Unknown action ${1}${_znormal}" '' ${zusage}
|
||||
print -u2 -PlR "%F{red}${0}: Unknown action ${1}%f" '' ${zusage}
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
<%
|
||||
class Zim
|
||||
attr_reader :version, :home, :min_zsh_version, :url_regex,
|
||||
:bold, :normal, :red, :normalred, :yellow, :normalyellow, :clear_line, :ellipsis, :okay, :warn, :error
|
||||
:clear_line, :ellipsis, :okay, :warn, :error, :done, :failed
|
||||
|
||||
def initialize
|
||||
@version = "1.16.0-SNAPSHOT"
|
||||
@version = "1.12.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"
|
||||
@clear_line = "$'\\E[2K\\r'"
|
||||
@ellipsis = " ..."
|
||||
@okay = ") "
|
||||
@okay = "%F{green})%f "
|
||||
@warn = "! "
|
||||
@error = "x "
|
||||
@done = ""
|
||||
@failed = ""
|
||||
end
|
||||
|
||||
def render(filename)
|
||||
|
@ -36,4 +38,8 @@ zim = Zim.new
|
|||
|
||||
<%= zim.render_commented("LICENSE") %>
|
||||
<%= zim.render_all("src/stage2/*.erb") %>
|
||||
zimfw "${@}"
|
||||
if [[ ${functrace[1]} == zmodule:* ]]; then
|
||||
zmodule "${@}"
|
||||
else
|
||||
zimfw "${@}"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue