pax_global_header00006660000000000000000000000064151212532140014506gustar00rootroot0000000000000052 comment=70cb088435b79e32b8f9b8bb82a6fc2dbaa996d3 zimfw-1.20.0/000077500000000000000000000000001512125321400127225ustar00rootroot00000000000000zimfw-1.20.0/.github/000077500000000000000000000000001512125321400142625ustar00rootroot00000000000000zimfw-1.20.0/.github/action/000077500000000000000000000000001512125321400155375ustar00rootroot00000000000000zimfw-1.20.0/.github/action/Dockerfile000066400000000000000000000001431512125321400175270ustar00rootroot00000000000000FROM alpine:latest RUN apk add -U --no-cache zsh bash git make shellcheck ENTRYPOINT ["zsh", "-c"] zimfw-1.20.0/.github/action/action.yml000066400000000000000000000002301512125321400175320ustar00rootroot00000000000000name: 'Zsh Command' inputs: cmd: required: true default: 'exit' runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.cmd }} zimfw-1.20.0/.github/workflows/000077500000000000000000000000001512125321400163175ustar00rootroot00000000000000zimfw-1.20.0/.github/workflows/main.yml000066400000000000000000000004111512125321400177620ustar00rootroot00000000000000name: Run test on: push jobs: run: runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v5 with: submodules: true - name: Run test uses: ./.github/action with: cmd: | make test zimfw-1.20.0/.gitignore000066400000000000000000000001741512125321400147140ustar00rootroot00000000000000*.swp *.zwc *.zwc.old /modules/ /.latest_version /init.zsh /init.zsh.old /login_init.zsh /login_init.zsh.old /zimfw.zsh.old zimfw-1.20.0/.gitmodules000066400000000000000000000007451512125321400151050ustar00rootroot00000000000000[submodule "test/bats"] path = test/bats url = https://github.com/bats-core/bats-core.git [submodule "test/test_helper/bats-support"] path = test/test_helper/bats-support url = https://github.com/bats-core/bats-support.git [submodule "test/test_helper/bats-assert"] path = test/test_helper/bats-assert url = https://github.com/bats-core/bats-assert.git [submodule "test/test_helper/bats-file"] path = test/test_helper/bats-file url = https://github.com/bats-core/bats-file.git zimfw-1.20.0/CHANGELOG.md000066400000000000000000000510561512125321400145420ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] _No unreleased changes._ ## [1.20.0] - 2025-12-19 ### Changed - Output of `list` and `uninstall` actions. Module names are already their relative path from `ZIM_HOME`, so listing their full path afterwards was redundant. The full path to external modules is now shown in verbose mode. Not considering this as a breaking change since zimfw's output is not meant to be parsed by scripts. - Uncommented `zmodule zsh-users/zsh-history-substring-search` from generated .zimrc, since our [input] module can now do a deferred initialization of it. See announcement [here](https://github.com/zimfw/zimfw/discussions/426#discussioncomment-15272879). ## [1.19.1] - 2025-11-19 Automated tests with [bats] were introduced in this version, allowing a better understanding of some edge case scenarios and being helpful to the work on improving how they're handled. ### Fixed - Don't expand `${HOME}` in fpath in the init.zsh script. - Show skipped `mkdir` modules in `check` action in verbose mode. - Do `build` after `uninstall` action. - Allow defining new modules as both `--frozen` and `--disabled` so they're neither installed nor initialized. Defining a new module as just `--frozen` is still going to cause errors when trying to initialize it and nothing is found. - Show `--if` option values on `list` action output in verbose mode. - For modules with multiple roots, show the respective options nested under each root on `list` action output in verbose mode. - Allow defining multiple roots in a module when using the `mkdir` tool. The tool will create the subdirectories automatically in this case. ## [1.19.0] - 2025-11-05 ### Added - Generate .zimrc if not found, to hopefully make installation easier. - Fail module check if git default remote branch has diverged. This allows novice users to more easily reinstall the affected module to fix the issue. ### Changed - Expand aliases when compiling with zcompile for a more predictable behavior. - Include modules/ prefix when outputting module names. ## [1.18.0] - 2025-03-20 Changes in this release are one more little step towards better adherence to the [command line interface guidelines]. ### Added - `--help` and `--version` actions. These are aliases to the already existing `help` and `version` actions. ### Changed - Disable color output when executed through a pipe or as a non-TTY ssh command. ## [1.17.1] - 2025-02-12 ### Fixed - Create `ZIM_HOME` if it does not exist. - Simplify output. Don't send any ANSI escape codes to the terminal when `NO_COLOR` is set. ## [1.17.0] - 2025-01-16 ### Added - Also list not installed modules with `list` action, when not in verbose mode. - `auto` tool in `zmodule`, which auto detects the best tool available for installing a new module or the tool used when an existing module was installed. This is now the default tool and makes life automatically easier for users without git installed. ### Fixed - Print help or version even if `ZIM_HOME` is not set. - "no such file or directory: /path/to/.zdegit" error when installing a new module with the degit tool. ## [1.16.0] - 2024-11-25 ### 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 init.zsh 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. ## [1.12.0] - 2023-07-17 ### Added - `check-version` action, that immediately checks if a new version of zimfw is available and returns code 4 if there is one. - `check` action, that checks if there are updates available for current modules. - Output of `LANG` and `LC_*` parameters in `info` action. ### Changed - Don't resolve symlinks when building init.zsh. ### Fixed - Show warning when there's no write permission to compile Zsh scripts. ## [1.11.3] - 2023-02-26 ### Deprecated - `check-dumpfile` action. The [completion] module alone now handles checking the dumpfile. (See [zimfw/completion#12](https://github.com/zimfw/completion/pull/12)) ## [1.11.2] - 2023-02-16 ### Fixed - Quote path names in init.zsh to properly handle path names with spaces. ## [1.11.1] - 2023-02-04 ### Fixed - Use `_zim_dumpfile_fpath` defined by the completion module [here](https://github.com/zimfw/completion/blob/33737e8c15fa8dba9af47bef8408b1af2599c21b/init.zsh#L11), right before `compinit` is run, to more accurately do `zimfw check-dumpfile`. ## [1.11.0] - 2022-12-18 ### Added - `--if` option to `zmodule` that will only initialize the module root if the specified test returns a zero exit status. The test is evaluated at every new terminal startup. - Ability to customize the .zimrc file name and path with the `ZIM_CONFIG_FILE` environment variable. ## [1.10.0] - 2022-09-27 ### Added - `--root` option to `zmodule`. Combined with the ability to call `zmodule` multiple times for the same module, this allows initializing from multiple roots in repositories like prezto or ohmyzsh. Also, `--on-pull` and `--disable` now work on a per-module-root basis. ### Changed - Show `OSTYPE`, `TERM`, `TERM_PROGRAM` and `TERM_PROGRAM_VERSION` environment variables instead of calling the `uname -a` command to show system info in the `zimfw info` action. ## [1.9.1] - 2022-05-24 ### Fixed - Override repository options along multiple `zmodule` calls with the same module name. - Show already installed modules skipped with install action and `-v`. - Consider external module directory paths when calling compile action directly. - Ignore return value from `zargs` with `-P`. (See https://www.zsh.org/mla/workers/2022/msg00611.html) ## [1.9.0] - 2022-05-09 ### Added - `--on-pull` option to `zmodule`, which allows setting a command that is always triggered after the module is installed or updated. ## [1.8.0] - 2022-01-25 ### Added - `check-dumpfile` action. It runs in the build, install and update actions, and checks if a new completion configuration needs to be dumped. It's intended to be used with `compinit -C`, so no checks are done during the shell startup. (See [zimfw/completion#8](https://github.com/zimfw/completion/pull/8)) - `--no-submodules` option to `zmodule`, which disables installing or updating git submodules. ## [1.7.0] - 2022-01-12 ### Changed - The output of `zimfw init` to be friendlier to the terminal startup screen when called without `-q`. - Only compile scripts via the zimfw tool after actions where scripts can change (build, install, update, upgrade). - Move compilation of the completion dumpfile to the completion module, [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 anymore (recommended): ``` for zfile in ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout); do rm -f ${zfile}.zwc(|.old)(N) done ``` - or add the following to your .zlogin so Zsh startup scripts continue to be compiled: ```diff +for zfile in ${ZDOTDIR:-${HOME}}/.z(shenv|profile|shrc|login|logout); do + if [[ ! ${zfile}.zwc -nt ${zfile} ]] zcompile -R ${zfile} +done +unset zfile ``` ### Deprecated - The login_init.zsh script, which is now empty. This means you can safely remove the following line from your .zlogin: ```diff -source ${ZIM_HOME}/login_init.zsh -q &! ``` ## [1.6.2] - 2021-11-21 ### Fixed - Force local zsh emulation options, so the code is not broken by unexpected option changes by the user. ## [1.6.1] - 2021-11-08 ### Fixed - Missing line break before showing git log when using the git tool to update. ## [1.6.0] - 2021-11-06 ### Added - `list` action. Using it with `-v` also shows the current details for all modules. ### Changed - Be quieter and don't output warnings when `-q` is provided. - Be more verbose when `-v` is provided: show skipped external and frozen modules with the install and update actions. - Show warning instead of error when module was not installed with the tool currently in use. - Manually setting any `zmodule` initialization option will disable all the default values from the other initialization options, so only user-provided values are used in this case. I.e. it's either all automatic, or all manual. - Also install new modules when starting a new shell (via `zimfw init`, that is sourced in .zshrc). ### Fixed - Error in `zimfw update` with the `git` tool when module directory is under a symlinked directory. - Warning when `WARN_CREATE_GLOBAL` is set and `ZIM_HOME` is not. - "zsh: command not found: zmodule" when trying to run `zmodule` from the shell. Show a more informative error instead. - Don't try to install or update external modules. ## [1.5.0] - 2021-08-10 ### Added - Option to use the new `degit` tool in `zmodule`, that is able to install and update modules from GitHub without requiring `git`. Modules are installed faster and take less disk space when using this tool. It can be set as the default with `zstyle ':zim:zmodule' use 'degit'`. ### Fixed - Force `core.autocrlf=false` when doing `git clone`. (See [#404](https://github.com/zimfw/zimfw/issues/404)) - Allow uninstalling modules with custom names that have a slash. ## [1.4.3] - 2021-03-19 ### Fixed - Prefer the prezto module format when using defaults to initialize a module. This is the format we use in our Zim Framework modules. It's not well documented anywhere officially, but in short words a prezto module can have: * a `functions` subdirectory that is added to the fpath by the framework, * files inside the `functions` subdirectory that are autoloaded by the framework (except for those with names matching `_*` or `prompt_*_setup`), * an `init.zsh` file that is sourced by the framework. ## [1.4.2] - 2021-02-19 ### Fixed - "Not a valid ref: refs/remotes/origin/main" error in `zimfw update`, when the repository's default branch was renamed to main. ## [1.4.1] - 2021-02-17 ### Fixed - Correctly get the repository's default branch in `zimfw update`. The related change in version 1.4.0 actually broke updating the modules, as new changes stopped being fetched. ## [1.4.0] - 2021-01-07 ### Added - Prompt before uninstalling modules, unless `-q` is set. - Show build date in info. ### Fixed - Show error when no parameter is provided to `-c|--cmd` in `zmodule`. - Use repository's default branch instead of hardcoding the default to `master` in `zimfw update`, when no branch is specified in `zmodule`. ## [1.3.2] - 2020-08-01 ### Fixed - Compiled files must also be cleaned from modules defined with absolute paths. ## [1.3.1] - 2020-07-24 ### Fixed - "gzip: stdin: unexpected end of file" error when trying to upgrade. (See [#407](https://github.com/zimfw/zimfw/issues/407)) ## [1.3.0] - 2020-07-05 ### Added - `-c|-cmd` option to `zmodule`. This allows for executing any specified command. ## [1.2.2] - 2020-06-10 ### Fixed - Allow local modules to be initialized and compiled in their respective directories, when absolute paths are given, instead of forcing them to be installed inside `ZIM_HOME`. ## [1.2.1] - 2020-05-26 ### Fixed - "No such file or directory" error when building a new file. This was a regression introduced after replacing `cmp` by `cksum` in version 1.2.0. - Show warning message when nothing found to be initialized in a module. ## [1.2.0] - 2020-05-17 ### Changed - Use `cksum` instead of `cmp`, and `zargs` instead of `xargs`, so we don't depend on busybox or diffutils and findutils. ### Fixed - Error messages and the `zmodule` usage text. ## [1.1.1] - 2020-01-26 ### Fixed - "no such file or directory" error before initial check for latest version. - Show error when no modules defined in .zimrc, instead of allowing xargs to execute the action with no positional parameters. ## [1.1.0] - 2020-01-20 ### Added - `help` and `version` actions. - `-v` verbose option. Normal mode output is now focused on the specified action. - Asynchronously check the latest version every 30 days. This can be disabled with `zstyle ':zim' disable-version-check yes`. ### Changed - When upgrading, download latest release asset instead of raw file from the master branch. - `curl` is preferred over `wget`. (See [#360](https://github.com/zimfw/zimfw/issues/360)) - `wget`'s output is only shown in verbose mode. ## [1.0.1] - 2020-01-09 ### Fixed - Zsh 5.2 does not recognize the `:P` modifier. Replace it by `:A`. - Also compile and clean .zprofile among the startup files. - Don't fail on `clean-dumpfile` when there's nothing to remove. ## [1.0.0] - 2020-01-07 This is a major change, where modules are not git submodules in the Zim repo anymore, but customized and installed separately as individual repositories. External modules can more easily be installed, updated and uninstalled. This makes Zim a project for Zsh that is both a set of community-maintained modules with a default installation (like on-my-zsh and prezto) and a plugin manager (like antigen and zplug). This version is not backwards-compatible with previous versions, so a new installation of Zim is required. Take your time to review the updated [README.md] and the changes listed below. ### Added - `zimfw` CLI tool. - `zmodule` function to define modules. - Automatic installation script. - zsh-users/zsh-autosuggestions is enabled by default in new installations. ### Changed - 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. - .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 tool and contain static code. This allows for constant startup time, regardless of how complex the module definitions are. - Zim modules moved to individual repositories in the https://github.com/zimfw organization. - Zim modules are configured with `zstyle` instead of environment variables. - Zim themes are sourced directly, instead of working with prompinit, and are configured with environment variables instead of with promptinit parameters. - The [environment] module is reduced in scope to to only set Zsh options. The additional code moved to the [input] module (smart-URL widgets), the [utility] module (default pager), and a new [termtitle] module (terminal window title). - The minimal theme is renamed to [s1ck94]. ### Removed - `zmanage` CLI tool. - The directory and history modules. Their code moved into the [environment] module. - The prompt module, and the external lean, liquidprompt and pure themes. Use `zmodule miekg/lean`, or `zmodule nojhan/liquidprompt`, or `zmodule sindresorhus/pure --source async.zsh --source pure.zsh` to define one of these external themes, respectively. The Zim themes moved to individual repositories. - Support for themes that require promptinit. (See [#325](https://github.com/zimfw/zimfw/issues/325)) ### Fixed - `ZIM_HOME` is set in .zshenv instead of .zshrc. The issue was that the variable was not available in .zlogin in non-interactive login shells. [bats]:https://bats-core.readthedocs.io [command line interface guidelines]: https://clig.dev [completion]: https://github.com/zimfw/completion [README.md]: https://github.com/zimfw/zimfw/blob/master/README.md [environment]: https://github.com/zimfw/environment [input]: https://github.com/zimfw/input [utility]: https://github.com/zimfw/utility [termtitle]: https://github.com/zimfw/termtitle [s1ck94]: https://github.com/zimfw/s1ck94 [Unreleased]: https://github.com/zimfw/zimfw/compare/v1.20.0...HEAD [1.20.0]: https://github.com/zimfw/zimfw/compare/v1.19.1...v1.20.0 [1.19.1]: https://github.com/zimfw/zimfw/compare/v1.19.0...v1.19.1 [1.19.0]: https://github.com/zimfw/zimfw/compare/v1.18.0...v1.19.0 [1.18.0]: https://github.com/zimfw/zimfw/compare/v1.17.1...v1.18.0 [1.17.1]: https://github.com/zimfw/zimfw/compare/v1.17.0...v1.17.1 [1.17.0]: https://github.com/zimfw/zimfw/compare/v1.16.0...v1.17.0 [1.16.0]: https://github.com/zimfw/zimfw/compare/v1.15.1...v1.16.0 [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 [1.12.0]: https://github.com/zimfw/zimfw/compare/v1.11.3...v1.12.0 [1.11.3]: https://github.com/zimfw/zimfw/compare/v1.11.2...v1.11.3 [1.11.2]: https://github.com/zimfw/zimfw/compare/v1.11.1...v1.11.2 [1.11.1]: https://github.com/zimfw/zimfw/compare/v1.11.0...v1.11.1 [1.11.0]: https://github.com/zimfw/zimfw/compare/v1.10.0...v1.11.0 [1.10.0]: https://github.com/zimfw/zimfw/compare/v1.9.1...v1.10.0 [1.9.1]: https://github.com/zimfw/zimfw/compare/v1.9.0...v1.9.1 [1.9.0]: https://github.com/zimfw/zimfw/compare/v1.8.0...v1.9.0 [1.8.0]: https://github.com/zimfw/zimfw/compare/v1.7.0...v1.8.0 [1.7.0]: https://github.com/zimfw/zimfw/compare/v1.6.2...v1.7.0 [1.6.2]: https://github.com/zimfw/zimfw/compare/v1.6.1...v1.6.2 [1.6.1]: https://github.com/zimfw/zimfw/compare/v1.6.0...v1.6.1 [1.6.0]: https://github.com/zimfw/zimfw/compare/v1.5.0...v1.6.0 [1.5.0]: https://github.com/zimfw/zimfw/compare/v1.4.3...v1.5.0 [1.4.3]: https://github.com/zimfw/zimfw/compare/v1.4.2...v1.4.3 [1.4.2]: https://github.com/zimfw/zimfw/compare/v1.4.1...v1.4.2 [1.4.1]: https://github.com/zimfw/zimfw/compare/v1.4.0...v1.4.1 [1.4.0]: https://github.com/zimfw/zimfw/compare/v1.3.2...v1.4.0 [1.3.2]: https://github.com/zimfw/zimfw/compare/v1.3.1...v1.3.2 [1.3.1]: https://github.com/zimfw/zimfw/compare/v1.3.0...v1.3.1 [1.3.0]: https://github.com/zimfw/zimfw/compare/v1.2.2...v1.3.0 [1.2.2]: https://github.com/zimfw/zimfw/compare/v1.2.1...v1.2.2 [1.2.1]: https://github.com/zimfw/zimfw/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/zimfw/zimfw/compare/v1.1.1...v1.2.0 [1.1.1]: https://github.com/zimfw/zimfw/compare/v1.1.0...v1.1.1 [1.1.0]: https://github.com/zimfw/zimfw/compare/v1.0.1...v1.1.0 [1.0.1]: https://github.com/zimfw/zimfw/compare/v1.0.0...v1.0.1 [1.0.0]: https://github.com/zimfw/zimfw/compare/5d66578...v1.0.0 zimfw-1.20.0/LICENSE000066400000000000000000000022111512125321400137230ustar00rootroot00000000000000MIT License Copyright (c) 2015-2016 Matt Hamilton and contributors Copyright (c) 2016-2025 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 in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. zimfw-1.20.0/Makefile000066400000000000000000000003501512125321400143600ustar00rootroot00000000000000.PHONY: lint test srcfiles := src/zimfw.zsh.erb $(wildcard src/*/*.erb src/templates/*) LICENSE zimfw.zsh: $(srcfiles) erb $< >| $@ lint: @shellcheck test/test_*.bats test: zimfw.zsh lint @test/bats/bin/bats test/test_*.bats zimfw-1.20.0/README.md000066400000000000000000000427741512125321400142170ustar00rootroot00000000000000
Zim Framework logo

Zim Framework: The Zsh configuration framework with blazing speed and modular extensions.

GitHub


Zim Framework is a Zsh configuration framework that bundles a [plugin manager](#usage), useful [modules] and a wide variety of [themes], without compromising on [speed]. Check how Zim Framework compares to other frameworks and plugin managers: Table of Contents ----------------- * [Installation](#installation) * [Automatic installation](#automatic-installation) * [Homebrew](#homebrew) * [Manual installation](#manual-installation) * [Set up `~/.zshrc`](#set-up-zshrc) * [Usage](#usage) * [`zmodule`](#zmodule) * [`zimfw`](#zimfw) * [Settings](#settings) * [Uninstalling](#uninstalling) Installation ------------ Installing Zim Framework is easy. You can choose either the automatic or manual method below: ### Automatic installation 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 ``` * With `wget`: ```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 [modules] and [themes] you can add to your `~/.zimrc`. ### Homebrew 1. Install zimfw with brew: ```zsh brew install --formula zimfw ``` 2. Add the following to your `~/.zshrc`: ```zsh ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim # 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 /path/to/zimfw.zsh init fi # Initialize modules. source ${ZIM_HOME}/init.zsh ``` replacing `/path/to/zimfw.zsh` with the path where brew installed the script, which is shown in the brew formula caveats. It is usually: * `/opt/homebrew/opt/zimfw/share/zimfw.zsh` on Apple Silicon macOS, * `/usr/local/opt/zimfw/share/zimfw.zsh` on Intel macOS, * `/home/linuxbrew/.linuxbrew/opt/zimfw/share/zimfw.zsh` on Linux. 3. Restart your terminal and you're done. Enjoy your Zsh IMproved! ### Manual installation 1. Set Zsh as the default shell, if you haven't done so already: ```zsh chsh -s $(which zsh) ``` 2. [Set up your `~/.zshrc` file](#set-up-zshrc) 3. Restart your terminal and you're done. Enjoy your Zsh IMproved! #### Set up `~/.zshrc` Add the lines below to your `~/.zshrc` file, in the following order: 1. 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`. 2. To set the directory where the zimfw plugin manager will keep necessary files: ```zsh ZIM_HOME=${ZDOTDIR:-${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`. 3. To automatically download the zimfw plugin manager if missing: ```zsh # Download zimfw plugin manager if missing. if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \ https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh fi ``` Or if you use `wget` instead of `curl`: ```zsh # Download zimfw plugin manager if missing. if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then mkdir -p ${ZIM_HOME} && wget -nv -O ${ZIM_HOME}/zimfw.zsh \ https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh fi ``` This is optional. Alternatively, the `zimfw.zsh` script can be installed with a package manager or downloaded 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 install or 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 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 source ${ZIM_HOME}/zimfw.zsh init 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` file. If you have chosen to keep the `zimfw.zsh` script 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: ```zsh # Initialize modules. source ${ZIM_HOME}/init.zsh ``` Usage ----- 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. The `~/.zimrc` file is not sourced during Zsh startup and it's only used to configure the zimfw plugin manager. ### zmodule Below are some usage examples: * A module from the [@zimfw] organization: `zmodule archive` * A module from another GitHub organization: `zmodule StackExchange/blackbox` * A module with a custom URL: `zmodule https://gitlab.com/Spriithy/basher.git` * 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: `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: `zmodule sindresorhus/pure --source async.zsh --source pure.zsh`. Separate zmodule calls can also be used. In this equivalent example, the second call automatically discovers the second file to be sourced: ``` zmodule sindresorhus/pure --source async.zsh zmodule sindresorhus/pure ``` * A module with a custom initialization command: `zmodule skywind3000/z.lua --cmd 'eval "$(lua {}/z.lua --init zsh enhanced once)"'` * A module with an on-pull command. It can be used to create a cached initialization script: `zmodule skywind3000/z.lua --on-pull 'lua z.lua --init zsh enhanced once >! init.zsh'` * A module with a big git repository: `zmodule romkatv/powerlevel10k --use degit` * A module with a custom root subdirectory: `zmodule ohmyzsh/ohmyzsh --root plugins/vim-interaction` * A module with multiple roots: ``` zmodule sorin-ionescu/prezto --root modules/command-not-found zmodule sorin-ionescu/prezto --root modules/gnu-utility ``` or ``` zmodule ohmyzsh/ohmyzsh --root plugins/perl zmodule ohmyzsh/ohmyzsh --root plugins/vim-interaction ```
Want help with the complete zmodule usage?
Usage: zmodule <url> [-n|--name <module_name>] [-r|--root <path>] [options]

Add zmodule calls to your ~/.zimrc file to define the modules to be initialized. The initiali-
zation will be done in the same order it's defined.

  <url>                      Module absolute path or repository URL. The following are equiva-
                             lent: 'foo', 'zimfw/foo', 'https://github.com/zimfw/foo.git'.
                             If an absolute path is given, the module is considered externally
                             installed and won't be installed or updated by zimfw.
  -n, --name <module_name>   Set a custom module name. Default: the last component in <url>.
                             Slashes can be used inside <module_name> to organize the module
                             into subdirectories. The module will be installed at
                             ${ZIM_HOME}/<module_name>.
  -r, --root <path>          Relative path to the module root.

Per-module options:
  -b, --branch <branch_name>
                             Use specified branch when installing and updating the module.
                             Overrides the tag option. Default: the repository default branch.
  -t, --tag <tag_name>       Use specified tag when installing and updating the module. Over-
                             rides the branch option.
  -u, --use <tool_name>      Install and update the module using the defined tool. Default is
                             either defined using zstyle ':zim:zmodule' use '<tool_name>' or
                             set to 'auto'. The tools available are:
                             'auto' tries to auto detect the tool to be used. When installing
                             a new module, 'git' will be used if the git command is available,
                             otherwise 'degit' will be used.
                             'git' uses the git command. Local changes are preserved on up-
                             dates.
                             'degit' 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.
                             'mkdir' creates an empty directory. The <url> is only used to set
                             the module name. Use the -c, --cmd option or --on-pull option to
                             execute the desired command to generate the module files.
      --no-submodules        Don't install or update git submodules.
  -z, --frozen               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:
      --if <test>            Will only initialize module root if specified test returns a zero
                             exit status. The test is evaluated at every new terminal startup.
      --if-command <command_name>
                             Will only initialize module root if specified external command is
                             available. This is evaluated at every new terminal startup.
                             Equivalent to --if '(( \${+commands[<command_name>]} ))'.
      --if-ostype <ostype>   Will only initialize module root if OSTYPE is equal to the given
                             expression. This is evaluated at every new terminal startup.
                             Equivalent to --if '[[ \${OSTYPE} == <ostype> ]]'.
      --on-pull <command>    Execute command after installing or updating the module. The com-
                             mand is executed in the module root directory.
  -d, --disabled             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:
  -f, --fpath <path>         Will add specified path to fpath. The path is relative to the
                             module root directory. Default: 'functions', if the subdirectory
                             exists and is non-empty.
  -a, --autoload <function_name>
                             Will autoload specified function. Default: all valid names inside
                             the functions subdirectory, if any.
  -s, --source <file_path>   Will source specified file. The path is relative to the module
                             root directory. Default: 'init.zsh', if a non-empty functions
                             subdirectory exists, else the largest of the files matching the
                             glob (init.zsh|<name>.(zsh|plugin.zsh|zsh-theme|sh)), if any. The
                             <name> in the glob is resolved to the last component of the mod-
                             ule name and the last component of the path to the module root.
  -c, --cmd <command>        Will execute specified command. Occurrences of the {} placeholder
                             in the command are substituted by the module root directory path.
                             I.e., -s 'foo.zsh' and -c 'source {}/foo.zsh' 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.
### zimfw The Zim Framework 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`. Settings -------- Set the path of the directory used by zimfw with the `ZIM_HOME` environment variable: ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim 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: ZIM_CONFIG_FILE=~/.config/zsh/zimrc The zimfw plugin manager will detect if `git` is installed and fall back to work without `git` with its degit tool. If you want to take advantage of its degit tool regardless for faster and 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, because your user does not have write access to it, then this will be disabled. This can be manually disabled with: zstyle ':zim' disable-version-check yes By default, zimfw will disable color output when executed through a pipe or as a non-TTY ssh command. To force disabling color output, 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 Framework is to manually delete `~/.zim`, `~/.zimrc`, and remove the initialization lines from your `~/.zshenv`, `~/.zshrc` and `~/.zlogin`. [modules]: https://zimfw.sh/docs/modules/ [themes]: https://zimfw.sh/docs/themes/ [speed]: https://github.com/zimfw/zimfw/wiki/Speed [@zimfw]: https://github.com/zimfw [completion]: https://github.com/zimfw/completion [zsh-users/zsh-completions]: https://github.com/zsh-users/zsh-completions zimfw-1.20.0/src/000077500000000000000000000000001512125321400135115ustar00rootroot00000000000000zimfw-1.20.0/src/functions/000077500000000000000000000000001512125321400155215ustar00rootroot00000000000000zimfw-1.20.0/src/functions/30_zmodule.zsh.erb000066400000000000000000000327371512125321400210130ustar00rootroot00000000000000zmodule() { local -r zusage="Usage: ${_zbold}${0}${_znormal} [${_zbold}-n${_znormal}|${_zbold}--name${_znormal} ] [${_zbold}-r${_znormal}|${_zbold}--root${_znormal} ] [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. Module absolute path or repository URL. The following are equiva- lent: ${_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} Set a custom module name. Default: the last component in . Slashes can be used inside to organize the module into subdirectories. The module will be installed at ${_zbold}${ZIM_HOME}/${_znormal}. ${_zbold}-r${_znormal}, ${_zbold}--root${_znormal} Relative path to the module root. Per-module options: ${_zbold}-b${_znormal}, ${_zbold}--branch${_znormal} Use specified branch when installing and updating the module. Overrides the tag option. Default: the repository default branch. ${_zbold}-t${_znormal}, ${_zbold}--tag${_znormal} Use specified tag when installing and updating the module. Over- rides the branch option. ${_zbold}-u${_znormal}, ${_zbold}--use${_znormal} Install and update the module using the defined tool. Default is either defined using ${_zbold}zstyle ':zim:zmodule' use '${_znormal}${_zbold}'${_znormal} or set to ${_zbold}'auto'${_znormal}. The tools available are: ${_zbold}'auto'${_znormal} tries to auto detect the tool to be used. When installing a new module, ${_zbold}'git'${_znormal} will be used if the git command is available, otherwise ${_zbold}'degit'${_znormal} will be used. ${_zbold}'git'${_znormal} uses the git command. Local changes are preserved on up- dates. ${_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 is only used to set the module name. Use the ${_zbold}-c${_znormal}, ${_zbold}--cmd${_znormal} option or ${_zbold}--on-pull${_znormal} option 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} 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} 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}${_zbold}]} ))'${_znormal}. ${_zbold}--if-ostype${_znormal} 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}${_zbold} ]]'${_znormal}. ${_zbold}--on-pull${_znormal} 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} 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} Will autoload specified function. Default: all valid names inside the ${_zbold}functions${_znormal} subdirectory, if any. ${_zbold}-s${_znormal}, ${_zbold}--source${_znormal} 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} subdirectory exists, else the largest of the files matching the glob ${_zbold}(init.zsh|${_znormal}${_zbold}.(zsh|plugin.zsh|zsh-theme|sh))${_znormal}, if any. The in the glob is resolved to the last component of the mod- ule name and the last component of the path to the module root. ${_zbold}-c${_znormal}, ${_zbold}--cmd${_znormal} 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 zname=modules/${zname} _znames+=(${zname}) if [[ ${zurl} == /* ]]; then _zpaths[${zname}]=${zurl%%/##} zurl= else _zpaths[${zname}]=${ZIM_HOME}/${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=${_zpaths[${zname}]}${zroot:+/${zroot}} _zroot_dirs+=(${zroot_dir}) # Set default values if (( ! ${+_ztools[${zname}]} )); then zstyle -s ':zim:zmodule' use "_ztools[${zname}]" || _ztools[${zname}]=auto 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_paths+=(${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 # Detect tool if auto and not external and not frozen module if [[ ${_ztools[${zname}]} == auto && -n ${_zurls[${zname}]} && _zfrozens[${zname}] -eq 0 ]]; then if [[ -e ${_zpaths[${zname}]} ]]; then if [[ -r ${_zpaths[${zname}]}/.git ]]; then _ztools[${zname}]=git elif [[ -r ${_zpaths[${zname}]}/.zdegit ]]; then _ztools[${zname}]=degit else _zimfw_print -u2 -lR "${_zwarn}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalyellow} Could not auto detect tool, will default to ${_zbold}mkdir${_znormalyellow}. Use zmodule option ${_zbold}-u${_znormalyellow}|${_zbold}--use${_znormalyellow} to stop this warning.${_znormal}" _ztools[${zname}]=mkdir fi else if [[ ${+commands[git]} -ne 0 && -x ${commands[git]} ]]; then _ztools[${zname}]=git else _ztools[${zname}]=degit fi fi fi if (( ! ${_zdisabled_paths[(I)${zroot_dir}]} && _zeager )); 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=(${${(@qqq)zfpaths:a}/${HOME}/\${HOME}}) _zfpaths+=(${zpre}${^zfpaths}) _zfunctions+=(${zpre}${^zfunctions}) zcmds=(${zcmds//${HOME}/\${HOME}}) _zcmds+=(${zpre}${^zcmds}) fi } zimfw-1.20.0/src/stage2/000077500000000000000000000000001512125321400146765ustar00rootroot00000000000000zimfw-1.20.0/src/stage2/20_guard.zsh.erb000066400000000000000000000005601512125321400175770ustar00rootroot00000000000000autoload -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}" return 1 fi # Define zimfw location typeset -g __ZIMFW_FILE=${0:a} zimfw-1.20.0/src/stage2/22_zimfw_print.zsh.erb000066400000000000000000000000741512125321400210470ustar00rootroot00000000000000_zimfw_print() { if (( _zprintlevel > 0 )) print "${@}" } zimfw-1.20.0/src/stage2/28_zimfw_mv.zsh.erb000066400000000000000000000007111512125321400203410ustar00rootroot00000000000000_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" 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" fi } zimfw-1.20.0/src/stage2/29_zimfw_build_init.zsh.erb000066400000000000000000000037311512125321400220470ustar00rootroot00000000000000_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 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}}' "${@}" }' local zroot_dir zpre local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) # Keep fpath constant regardless of "if" root dirs, to avoid confusing compinit. # Move all from zfunctions and zcmds with "if" root dirs prefixes. for zroot_dir in ${_zroot_dirs}; do if (( ${+_zifs[${zroot_dir}]} )); then zpre=${zroot_dir}$'\0' zif_functions+=(${(M)zfunctions:#${zpre}*}) zif_cmds+=(${(M)zcmds:#${zpre}*}) zfunctions=(${zfunctions:#${zpre}*}) zcmds=(${zcmds:#${zpre}*}) fi done zpre=$'*\0' if (( ${#_zfpaths} )) print -R 'fpath=('${_zfpaths#${~zpre}}' ${fpath})' if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}} for zroot_dir in ${_zroot_dirs}; do zpre=${zroot_dir}$'\0' if (( ${+_zifs[${zroot_dir}]} )); then zroot_functions=(${${(M)zif_functions:#${zpre}*}#${zpre}}) zroot_cmds=(${${(M)zif_cmds:#${zpre}*}#${zpre}}) if (( ${#zroot_functions} || ${#zroot_cmds} )); then print -R 'if '${_zifs[${zroot_dir}]}'; then' if (( ${#zroot_functions} )) print -R ' autoload -Uz -- '${zroot_functions} if (( ${#zroot_cmds} )) print -R ${(F):- ${^zroot_cmds}} print fi fi else zroot_cmds=(${${(M)zcmds:#${zpre}*}#${zpre}}) if (( ${#zroot_cmds} )) print -R ${(F)zroot_cmds} fi done ) ${ztarget} } zimfw-1.20.0/src/stage2/29_zimfw_build_login_init.zsh.erb000066400000000000000000000004731512125321400232370ustar00rootroot00000000000000_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 command mv -f ${ztarget}{,.old} || return 1 fi _zimfw_mv =( print '# Do nothing. This file is deprecated.' ) ${ztarget} } zimfw-1.20.0/src/stage2/30_zimfw_build.zsh.erb000066400000000000000000000001641512125321400210110ustar00rootroot00000000000000_zimfw_build() { _zimfw_build_init && _zimfw_build_login_init && _zimfw_print "Done with build.${_zrestartmsg}" } zimfw-1.20.0/src/stage2/31_zimfw_source_zimrc.zsh.erb000066400000000000000000000020161512125321400224150ustar00rootroot00000000000000_zimfw_source_zimrc() { <%= render_all("src/functions/*.erb") %> { local -ri _zeager=${1} local -i _zfailed=0 if [[ ! -e ${_zconfig} ]]; then _zimfw_print -u2 "${_zyellow}Config file not found, will create ${_zbold}${_zconfig}${_znormal}" command mkdir -p ${_zconfig:h} || return 1 print -Rn "<%= render_template("src/templates/zimrc") %>" >${_zconfig} || return 1 fi if ! source ${_zconfig} || (( _zfailed )); then print -u2 -R "${_zred}Failed to source ${_zbold}${_zconfig}${_znormal}" return 1 fi if (( ${#_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 paths prefixes local zpath zpre for zpath in ${_zdisabled_paths}; do zpre=${zpath}$'\0' _zfpaths=(${_zfpaths:#${zpre}*}) _zfunctions=(${_zfunctions:#${zpre}*}) _zcmds=(${_zcmds:#${zpre}*}) done } always { unfunction zmodule } } zimfw-1.20.0/src/stage2/34_zimfw_list_unused_paths.zsh.erb000066400000000000000000000010521512125321400234500ustar00rootroot00000000000000_zimfw_list_unused_paths() { local -i i=1 local zinstalled=(${ZIM_HOME}/modules/*(N/)) local -r zpaths=(${(v)_zpaths}) # Search into subdirectories while (( i <= ${#zinstalled} )); do if (( zpaths[(I)${zinstalled[i]}/*] )); then zinstalled+=(${zinstalled[i]}/*(N/)) zinstalled[i]=() else (( i++ )) fi done # Unused = all installed dirs not in zpaths _zunused_paths=(${zinstalled:|zpaths}) local zunused for zunused (${_zunused_paths}) _zimfw_print -R "${_zbold}${zunused##${ZIM_HOME}/}${_znormal}${1}" } zimfw-1.20.0/src/stage2/50_zimfw_check_dumpfile.zsh.erb000066400000000000000000000002161512125321400226540ustar00rootroot00000000000000_zimfw_check_dumpfile() { _zimfw_print -u2 "${_zyellow}Deprecated action. This is now handled by the completion module alone.${_znormal}" } zimfw-1.20.0/src/stage2/50_zimfw_check_version.zsh.erb000066400000000000000000000020741512125321400225400ustar00rootroot00000000000000_zimfw_check_version() { if (( ${1} )); then if (( ${2} )); then # background check if [[ -w ${_zversion_target:h} ]]; then print -R ${${${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs --sort=-v:refname \ https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &! fi else # foreground check local tags tags=$(command git ls-remote --tags --refs --sort=-v:refname https://github.com/zimfw/zimfw.git 'v*') || return 1 >! ${_zversion_target} <<<${${${(f)tags}##*v}[1]} || return 1 fi fi if [[ -f ${_zversion_target} ]]; then local -r zlatest_version=$(<${_zversion_target}) if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then _zimfw_print -u2 -R "${_zyellow}Latest zimfw version is ${_zbold}${zlatest_version}${_znormalyellow}. You're using version ${_zbold}${_zversion}${_znormalyellow}. Run ${_zbold}zimfw upgrade${_znormalyellow} to upgrade.${_znormal}" return 4 fi fi } zimfw-1.20.0/src/stage2/50_zimfw_clean_compiled.zsh.erb000066400000000000000000000006501512125321400226520ustar00rootroot00000000000000_zimfw_clean_compiled() { # Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once. local -Ur zscriptdirs=(${ZIM_HOME:A} ${${(v)_zpaths##${ZIM_HOME}/*}:A}) 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-1.20.0/src/stage2/50_zimfw_clean_dumpfile.zsh.erb000066400000000000000000000004571512125321400226700ustar00rootroot00000000000000_zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump if (( _zprintlevel > 0 )) zopt=-v command rm -f ${zopt} ${zdumpfile}(|.dat|.zwc(|.old))(N) && \ _zimfw_print -R "Done with clean-dumpfile.${_zrestartmsg}" } zimfw-1.20.0/src/stage2/50_zimfw_compile.zsh.erb000066400000000000000000000011131512125321400213370ustar00rootroot00000000000000_zimfw_compile() { # Compile zimfw scripts local zroot_dir zfile for zroot_dir in ${_zroot_dirs:|_zdisabled_paths}; do if [[ ! -w ${zroot_dir} ]]; then _zimfw_print -R "${_zwarn}${_zbold}${zroot_dir}:${_znormalyellow} No write permission, unable to compile.${_znormal}" continue fi for zfile in ${zroot_dir}/(^*test*/)#*.zsh(|-theme)(N-.); do if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then zcompile -R ${zfile} && _zimfw_print -R "${_zokay}${_zbold}${zfile}.zwc:${_znormal} Compiled" fi done done _zimfw_print 'Done with compile.' } zimfw-1.20.0/src/stage2/50_zimfw_info.zsh.erb000066400000000000000000000007751512125321400206570ustar00rootroot00000000000000_zimfw_info() { _zimfw_info_print_symlink ZIM_HOME ${ZIM_HOME} _zimfw_info_print_symlink 'zimfw config' ${_zconfig} _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 print -R ${(r.22....:.)zparam}${(P)zparam} done } zimfw-1.20.0/src/stage2/50_zimfw_info_print_symlink.zsh.erb000066400000000000000000000001631512125321400236300ustar00rootroot00000000000000_zimfw_info_print_symlink() { print -Rn ${(r.22....:.)1}${2} if [[ -L ${2} ]] print -Rn ' -> '${2:A} print } zimfw-1.20.0/src/stage2/50_zimfw_uninstall.zsh.erb000066400000000000000000000007211512125321400217240ustar00rootroot00000000000000_zimfw_uninstall() { if (( _zprintlevel <= 0 )); then command rm -rf ${_zunused_paths} || return 1 else local zunused_path print "Found ${_zbold}${#_zunused_paths}${_znormal} unused module(s)." for zunused_path in ${_zunused_paths}; do if read -q "?Uninstall ${zunused_path} [y/N]? "; then print command rm -rfv ${zunused_path} || return 1 else print fi done print 'Done with uninstall.' fi } zimfw-1.20.0/src/stage2/50_zimfw_upgrade.zsh.erb000066400000000000000000000023151512125321400213430ustar00rootroot00000000000000_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 { if [[ ${+commands[curl]} -ne 0 && -x ${commands[curl]} ]]; then command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1 else local zopt 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}" fi return 1 fi fi command gunzip -f ${ztarget}.new.gz || return 1 # .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.${_zrestartmsg}" } always { command rm -f ${ztarget}.new{,.gz} } } zimfw-1.20.0/src/stage2/69_zimfw_run_list.zsh.erb000066400000000000000000000041101512125321400215600ustar00rootroot00000000000000_zimfw_run_list() { local -r zname=${1} local -r zpath=${_zpaths[${zname}]} local -r zroot_dirs=(${(M)_zroot_dirs:#${zpath}(|/*)}) print -nR ${_zbold}${zname}${_znormal} if [[ ! -e ${zpath} ]] print -n ' (not installed)' if [[ -z ${_zurls[${zname}]} ]] print -n ' (external)' if (( _zfrozens[${zname}] )) print -n ' (frozen)' if [[ ${_zdisabled_paths[(I)${zpath}]} -ne 0 && ${zroot_dirs} == (${zpath}) ]] print -n ' (disabled)' print if (( _zprintlevel > 1 )); then if [[ -z ${_zurls[${zname}]} ]]; then print -R ' From: '${zpath} elif (( ! _zfrozens[${zname}] )); then if [[ ${_ztools[${zname}]} == mkdir ]]; then print ' From: mkdir' 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 fi if [[ -n ${_zonpulls[${zname}]} ]] print -R " On-pull: ${_zonpulls[${zname}]}" fi local zroot_dir zindent zpre local -a zfpaths zfunctions zcmds for zroot_dir in ${zroot_dirs}; do if [[ ${zroot_dirs} == (${zpath}) ]]; then zindent=' ' else if [[ ${zroot_dir} == ${zpath} ]]; then print -n ' Root: .' else print -nR ' Root: '${zroot_dir##${zpath}/} fi if (( _zdisabled_paths[(I)${zroot_dir}] )) print -n ' (disabled)' print zindent=' ' fi if (( ${+_zifs[${zroot_dir}]} )) print -R ${zindent}'if: '${_zifs[${zroot_dir}]} zpre=${zroot_dir}$'\0' zfpaths=(${${(M)_zfpaths:#${zpre}*}#${zpre}}) zfunctions=(${${(M)_zfunctions:#${zpre}*}#${zpre}}) zcmds=(${${(M)_zcmds:#${zpre}*}#${zpre}}) if (( ${#zfpaths} )) print -R ${zindent}'fpath: '${zfpaths} if (( ${#zfunctions} )) print -R ${zindent}'autoload: '${zfunctions} if (( ${#zcmds} )) print -R ${zindent}'cmd: '${(j:; :)zcmds} done fi } zimfw-1.20.0/src/stage2/70_zimfw_create_dir.zsh.erb000066400000000000000000000002151512125321400220140ustar00rootroot00000000000000_zimfw_create_dir() { if ! ERR=$(command mkdir -p ${1} 2>&1); then _zimfw_print_error "Error creating ${1}" ${ERR} return 1 fi } zimfw-1.20.0/src/stage2/70_zimfw_print_error.zsh.erb000066400000000000000000000002001512125321400222520ustar00rootroot00000000000000_zimfw_print_error() { print -u2 -lR "${_zerror}${_zbold}${_zname}:${_znormalred} ${1}${_znormal}" ${2:+${(F):- ${(f)^2}}} } zimfw-1.20.0/src/stage2/70_zimfw_print_okay.zsh.erb000066400000000000000000000002141512125321400220710ustar00rootroot00000000000000_zimfw_print_okay() { if (( _zprintlevel > ${2:-0} )) print -lR "${_zokay}${_zbold}${_zname}:${_znormal} ${1}" ${3:+${(F):- ${(f)^3}}} } zimfw-1.20.0/src/stage2/70_zimfw_print_warn.zsh.erb000066400000000000000000000001561512125321400221020ustar00rootroot00000000000000_zimfw_print_warn() { _zimfw_print -u2 -R "${_zwarn}${_zbold}${_zname}:${_znormalyellow} ${1}${_znormal}" } zimfw-1.20.0/src/stage2/71_zimfw_pull_print_okay.zsh.erb000066400000000000000000000010021512125321400231220ustar00rootroot00000000000000_zimfw_pull_print_okay() { # Useb by tools, which run in a subshell if [[ -n ${ONPULL} ]]; then if ! ERR=$(builtin cd -q ${DIR} 2>&1 && builtin eval ${ONPULL} 2>&1); then _zimfw_print_error 'Error during on-pull' ${ERR} return 1 elif [[ ${_zprintlevel} -gt 1 && -n ${ERR} ]]; then # Overrides ${3} to include the on-pull output, to be used by _zimfw_print_okay below. builtin set ${1} ${2:-0} ${3:+${3}$'\n'}'On-pull output:'$'\n'${ERR} fi fi _zimfw_print_okay "${@}" } zimfw-1.20.0/src/stage2/75_zimfw_tool_degit.zsh.erb000066400000000000000000000137661512125321400220700ustar00rootroot00000000000000_zimfw_download_tarball() { if [[ ${URL} =~ <%= url_regex %> ]]; then readonly HOST=${match[3]} readonly REPO=${match[4]%.git} fi if [[ ${HOST} != github.com || -z ${REPO} ]]; then _zimfw_print_error "${URL} is not a valid 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." return 1 fi readonly HEADERS_TARGET=${DIR}/${TEMP}_headers { if [[ ${ACTION} != install ]]; then readonly INFO=("${(@f)"$(<${INFO_TARGET})"}") # 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 [[ -z ${INFO_HEADER} ]] return 0 if [[ ${+commands[curl]} -ne 0 && -x ${commands[curl]} ]]; then command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET} else command wget --spider -qS --header=${INFO_HEADER} ${TARBALL_URL} 2>${HEADERS_TARGET} fi else if [[ ${+commands[curl]} -ne 0 && -x ${commands[curl]} ]]; then if ! ERR=$(command curl -fsSL ${INFO_HEADER:+-H} ${INFO_HEADER} -o ${TARBALL_TARGET} -D ${HEADERS_TARGET} ${TARBALL_URL} 2>&1); then _zimfw_print_error "Error downloading ${TARBALL_URL} with curl" ${ERR} return 1 fi else # wget returns 8 when 304 Not Modified, so we cannot use wget's error codes command wget -qS ${INFO_HEADER:+--header=${INFO_HEADER}} -O ${TARBALL_TARGET} ${TARBALL_URL} 2>${HEADERS_TARGET} fi fi while IFS= read -r HEADER; do HEADER=${${HEADER## ##}%%$'\r'##} if [[ ${HEADER} == HTTP/* ]]; then HTTP_CODE=${${(s: :)HEADER}[2]} elif [[ ${${(L)HEADER%%:*}%% ##} == etag ]]; then ETAG=${${HEADER#*:}## ##} fi done < ${HEADERS_TARGET} if (( HTTP_CODE == 304 )); then # Not Modified command rm -f ${TARBALL_TARGET} 2>/dev/null return 0 elif (( HTTP_CODE != 200 )); then _zimfw_print_error "Error downloading ${TARBALL_URL}, HTTP code ${HTTP_CODE}" return 1 fi if [[ -z ${ETAG} ]]; then _zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response" return 1 fi if [[ ${ACTION} == check ]]; then command touch ${TARBALL_TARGET} # Update available else if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then _zimfw_print_error "Error creating or updating ${INFO_TARGET}" return 1 fi fi } always { command rm -f ${HEADERS_TARGET} 2>/dev/null } } _zimfw_untar_tarball() { if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then _zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR} return 1 fi local zsubdir for zsubdir in ${1}/*(/); do if ! ERR=$(command mv -f ${zsubdir}/*(DN) ${1} 2>&1 && command rmdir ${zsubdir} 2>&1); then _zimfw_print_error "Error moving ${zsubdir}" ${ERR} return 1 fi done } _zimfw_tool_degit() { # This runs in a subshell readonly -i SUBMODULES=${6} readonly ACTION=${1} DIR=${2} URL=${3} REV=${5} ONPULL=${7} TEMP=.zdegit_${sysparams[pid]}_${RANDOM} 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 ;; install) { _zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1 } always { # return 1 does not change ${TRY_BLOCK_ERROR}, only changes ${?} (( TRY_BLOCK_ERROR = ? )) command rm -f ${TARBALL_TARGET} 2>/dev/null if (( TRY_BLOCK_ERROR )) command rm -rf ${DIR} 2>/dev/null } ;; check|update) readonly DIR_NEW=${DIR}${TEMP} { _zimfw_download_tarball || return 1 if [[ ${ACTION} == check ]]; then if [[ -e ${TARBALL_TARGET} ]]; then _zimfw_print_okay 'Update available' return 4 fi _zimfw_print_okay 'Already up to date' 1 return 0 else if [[ -e ${TARBALL_TARGET} ]]; then _zimfw_create_dir ${DIR_NEW} && _zimfw_untar_tarball ${DIR_NEW} || return 1 if [[ ${+commands[diff]} -ne 0 && -x ${commands[diff]} ]]; then LOG=$(command diff -x '.zdegit*' -x '*.zwc' -x '*.zwc.old' -qr ${DIR} ${DIR_NEW} 2>/dev/null) LOG=${${LOG//${DIR_NEW}/new}//${DIR}/old} fi if ! ERR=$({ command cp -f ${INFO_TARGET} ${DIR_NEW} && \ command rm -rf ${DIR} && command mv -f ${DIR_NEW} ${DIR} } 2>&1); then _zimfw_print_error "Error updating ${DIR}" ${ERR} return 1 fi _zimfw_pull_print_okay Updated 0 ${LOG} || return 1 else _zimfw_pull_print_okay 'Already up to date' || return 1 fi fi } always { command rm -f ${TARBALL_TARGET} 2>/dev/null command rm -rf ${DIR_NEW} 2>/dev/null } ;; esac # Check after successful install or update if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then _zimfw_print_warn "Module contains git submodules, which are not supported by zimfw's degit. Use zmodule option ${_zbold}--no-submodules${_znormalyellow} to stop this warning." fi } zimfw-1.20.0/src/stage2/75_zimfw_tool_git.zsh.erb000066400000000000000000000110331512125321400215400ustar00rootroot00000000000000_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 if [[ ${TYPE} == branch ]]; then if [[ -z ${REV} ]]; then if REV=$(command git -C ${DIR} symbolic-ref --short refs/remotes/origin/HEAD 2>&1); then REV=${REV#origin/} else _zimfw_print_error 'Error during git symbolic-ref.'${premsg} ${REV} return 1 fi fi readonly AHEAD_AND_BEHIND=$(command git -C ${DIR} rev-list --count --left-right ${REV}...${REV}@{u} -- 2>/dev/null) readonly -i AHEAD=${AHEAD_AND_BEHIND[(w)1]} readonly -i BEHIND=${AHEAD_AND_BEHIND[(w)2]} if (( AHEAD && BEHIND )); then _zimfw_print_error "Diverged [ahead ${AHEAD}, behind ${BEHIND}]."${premsg} return 1 fi fi fi ;; install) if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then _zimfw_pull_print_okay Installed else _zimfw_print_error 'Error during git clone' ${ERR} return 1 fi ;; check|update) if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then _zimfw_print_error 'Error during git fetch' ${ERR} return 1 fi if [[ ${TYPE} == branch ]]; then if [[ -z ${REV} ]]; then # Get HEAD remote branch if ! ERR=$(command git -C ${DIR} remote set-head origin -a 2>&1); then _zimfw_print_error 'Error during git remote set-head' ${ERR} return 1 fi if REV=$(command git -C ${DIR} symbolic-ref --short refs/remotes/origin/HEAD 2>&1); then REV=${REV#origin/} else _zimfw_print_error 'Error during git symbolic-ref' ${REV} return 1 fi fi if [[ ${ACTION} == check ]]; then readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${REV}@{u} -- 2>/dev/null) if (( BEHIND )); then _zimfw_print_okay "Update available [behind ${BEHIND}]" return 4 else _zimfw_print_okay 'Already up to date' 1 return 0 fi fi TO_REV=${REV}@{u} else if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then if [[ ${ACTION} == check ]]; then _zimfw_print_okay 'Already up to date' 1 return 0 else _zimfw_pull_print_okay 'Already up to date' return ${?} fi fi if [[ ${ACTION} == check ]]; then _zimfw_print_okay 'Update available' return 4 fi TO_REV=${REV} fi if [[ -z ${NO_COLOR} && -t 1 ]]; 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 if ! ERR=$(command git -C ${DIR} checkout -q ${REV} -- 2>&1); then _zimfw_print_error 'Error during git checkout' ${ERR} return 1 fi if [[ ${TYPE} == branch ]]; then if ! OUT=$(command git -C ${DIR} merge --ff-only --no-progress -n 2>&1); then _zimfw_print_error 'Error during git merge' ${OUT} return 1 fi # keep just first line of OUT OUT=${OUT%%($'\n'|$'\r')*} else OUT="Updating to ${TYPE} ${REV}" fi if (( SUBMODULES )); then if ! ERR=$(command git -C ${DIR} submodule update --init --recursive -q -- 2>&1); then _zimfw_print_error 'Error during git submodule update' ${ERR} return 1 fi fi _zimfw_pull_print_okay ${OUT} 0 ${LOG} ;; esac } zimfw-1.20.0/src/stage2/75_zimfw_tool_mkdir.zsh.erb000066400000000000000000000016271512125321400220730ustar00rootroot00000000000000_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) ]] return 0 if [[ ${ACTION} == check ]]; then _zimfw_print_okay 'Skipping mkdir module' 1 return 0 fi 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 local -r zroot_dirs=(${(M)_zroot_dirs:#${DIR}(|/*)}) local zroot_dir for zroot_dir in ${zroot_dirs}; do _zimfw_create_dir ${zroot_dir} || return 1 done _zimfw_pull_print_okay Created || return 1 fi } zimfw-1.20.0/src/stage2/77_zimfw_run_tool.zsh.erb000066400000000000000000000035161512125321400215720ustar00rootroot00000000000000_zimfw_run_tool() { local zaction=${1} local -r _zname=${2} if [[ -z ${_zurls[${_zname}]} ]]; then _zimfw_print_okay 'Skipping external module' 1 return 0 fi if (( _zfrozens[${_zname}] )); then _zimfw_print_okay 'Skipping frozen module' 1 return 0 fi local -r ztool=${_ztools[${_zname}]} if [[ ${ztool} != (degit|git|mkdir) ]]; then _zimfw_print_error "Unknown tool ${ztool}" return 1 fi set "${_zpaths[${_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 zpath_new=.${_zpaths[${_zname}]}_${sysparams[pid]}_${RANDOM} { _zimfw_tool_${ztool} install ${zpath_new} "${@:2}" || return 1 if ! ERR=$({ command rm -rf ${_zpaths[${_zname}]} && command mv -f ${zpath_new} ${_zpaths[${_zname}]} } 2>&1); then _zimfw_print_error "Error reinstalling ${_zpaths[${_zname}]}" ${ERR} return 1 fi } always { command rm -rf ${zpath_new} 2>/dev/null } return 0 else _zimfw_tool_${ztool} pre "${@}" || return 1 fi case ${zaction} in install) if [[ -e ${_zpaths[${_zname}]} ]]; then _zimfw_print_okay 'Skipping already installed module' 1 return 0 fi ;; check|update) if [[ ! -d ${_zpaths[${_zname}]} ]]; then _zimfw_print_error "Not installed. Run ${_zbold}zimfw install${_znormalred} to install." return 1 fi ;; *) _zimfw_print_error "Unknown action ${zaction}" return 1 ;; esac _zimfw_tool_${ztool} ${zaction} "${@}" } zimfw-1.20.0/src/stage2/78_zimfw_run_tool_action.zsh.erb000066400000000000000000000003241512125321400231220ustar00rootroot00000000000000_zimfw_run_tool_action() { local -i zmaxprocs=0 if [[ ${1} == reinstall ]] zmaxprocs=1 _zimfw_source_zimrc 0 || return 1 zargs -n 2 -P ${zmaxprocs} -- "${_znames[@]}" -- _zimfw_run_tool ${1} return 0 } zimfw-1.20.0/src/stage2/80_zimfw.zsh.erb000066400000000000000000000156301512125321400176430ustar00rootroot00000000000000zimfw() { builtin emulate -L zsh -o EXTENDED_GLOB if [[ -z ${NO_COLOR} && -t 1 ]]; 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} [option] 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}info${_znormal} Print zimfw and system info. ${_zbold}list${_znormal} List all modules defined in ${_zbold}${_zconfig}${_znormal}. Use ${_zbold}-v${_znormal} to also see their initialization details. ${_zbold}init${_znormal} Same as ${_zbold}install${_znormal}, but with output tailored for the terminal startup. ${_zbold}install${_znormal} Install new modules. 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}update${_znormal} Update current modules. 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}reinstall${_znormal} Reinstall modules that failed check. Prompts for confirmation, unless ${_zbold}-q${_znormal} is used. 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, unless ${_zbold}-q${_znormal} is used. Also does ${_zbold}build${_znormal}. Use ${_zbold}-v${_znormal} to also see its output. ${_zbold}check${_znormal} Check if updates for current modules are available. Use ${_zbold}-v${_znormal} to also see skipped and up to date 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}help${_znormal}, ${_zbold}--help${_znormal} Print this help. ${_zbold}version${_znormal}, ${_zbold}--version${_znormal} Print zimfw version. Options: ${_zbold}-q${_znormal} Quiet (yes to prompts and only output errors) ${_zbold}-v${_znormal} Verbose (output more details)" local -i _zprintlevel=1 if (( # > 2 )); then print -u2 -lR "${_zred}${0}: Too many options${_znormal}" '' ${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} return 2 ;; esac fi case ${1} in help|--help) print -R ${zusage} return ;; version|--version) print -R ${_zversion} return ;; esac if (( ! ${+ZIM_HOME} )); then print -u2 -R "${_zred}${0}: ${_zbold}ZIM_HOME${_znormalred} not defined${_znormal}" return 1 fi if [[ ! -e ${ZIM_HOME} ]]; then command mkdir -p ${ZIM_HOME} || return 1 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 .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 -Ua _znames _zroot_dirs _zdisabled_paths local -A _zfrozens _ztools _zpaths _zurls _ztypes _zrevs _zsubmodules _zonpulls _zifs local -a _zfpaths _zfunctions _zcmds _zunused_paths local _zrestartmsg=' Restart your terminal for changes to take effect.' autoload -Uz zargs case ${1} in build) _zimfw_source_zimrc 1 && _zimfw_build || return 1 (( _zprintlevel-- )) _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-dumpfile) _zimfw_clean_dumpfile ;; compile) _zimfw_source_zimrc 0 && _zimfw_compile ;; info) _zimfw_info ;; list) _zimfw_source_zimrc $(( _zprintlevel > 1 )) && \ zargs -n 1 -- "${_znames[@]}" -- _zimfw_run_list && \ _zimfw_list_unused_paths ' (unused)' ;; check) _zimfw_run_tool_action ${1} || return 1 (( _zprintlevel-- )) _zimfw_print -R "Done with ${1}. Run ${_zbold}zimfw update${_znormal} to update modules." # 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_source_zimrc 1 && _zimfw_build && _zimfw_compile ;; install|update|reinstall) _zimfw_run_tool_action ${1} || return 1 _zimfw_print -R "Done with ${1}.${_zrestartmsg}" (( _zprintlevel-- )) _zimfw_source_zimrc 1 && _zimfw_build && _zimfw_compile ;; uninstall) _zimfw_source_zimrc 0 && _zimfw_list_unused_paths && _zimfw_uninstall || return 1 (( _zprintlevel-- )) _zimfw_source_zimrc 1 && _zimfw_build ;; check-version) _zimfw_check_version 1 (( _zprintlevel-- )) _zimfw_print -R "Done with ${1}." # Only printed in verbose mode ;; upgrade) _zimfw_upgrade || return 1 (( _zprintlevel-- )) _zimfw_source_zimrc 0 && _zimfw_compile ;; *) print -u2 -lR "${_zred}${0}: Unknown action ${1}${_znormal}" '' ${zusage} return 2 ;; esac } zimfw-1.20.0/src/templates/000077500000000000000000000000001512125321400155075ustar00rootroot00000000000000zimfw-1.20.0/src/templates/zimrc000066400000000000000000000027501512125321400165620ustar00rootroot00000000000000# # This is not sourced during shell startup and is only used to configure zimfw. # # # Modules # # Sets sane Zsh built-in environment options. zmodule environment # Provides handy git aliases and functions. zmodule git # Applies correct bindkeys for input events. zmodule input # Sets a custom terminal title. zmodule termtitle # Utility aliases and functions. Adds colour to ls, grep and less. zmodule utility # <-- Normally new modules should be added here. Check each module documentation # for any caveats. # # Prompt # # Exposes how long the last command took to run to prompts. zmodule duration-info # Exposes git repository status information to prompts. zmodule git-info # A heavily reduced, ASCII-only version of the Spaceship and Starship prompts. zmodule asciiship # # Completion # # Additional completion definitions for Zsh. zmodule zsh-users/zsh-completions --fpath src # Enables and configures smart and extensive tab completion, must be sourced # after all modules that add completion definitions. zmodule completion # # Modules that must be initialized last # # Fish-like syntax highlighting for Zsh, must be sourced after completion. zmodule zsh-users/zsh-syntax-highlighting # Fish-like history search for Zsh, must be sourced after # zsh-users/zsh-syntax-highlighting. zmodule zsh-users/zsh-history-substring-search # Fish-like autosuggestions for Zsh. Add the following to your ~/.zshrc to boost # performance: ZSH_AUTOSUGGEST_MANUAL_REBIND=1 zmodule zsh-users/zsh-autosuggestions zimfw-1.20.0/src/zimfw.zsh.erb000066400000000000000000000022161512125321400161430ustar00rootroot00000000000000<% class Zim attr_reader :version, :home, :min_zsh_version, :url_regex, :okay, :warn, :error def initialize @version = "1.20.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 = "^([^:@/]+://)?([^@]+@)?([^:/]+)[:/]([^/]+/[^/]+)/?$" @okay = ") " @warn = "! " @error = "x " end def render(filename) ERB.new(File.read(filename)).result(binding) end def render_all(pattern) Dir[pattern].sort.map { |filename| render(filename) }.join("\n") end def render_template(filename) render(filename) .gsub(/\\/, "\\\\\\\\") .gsub(/(?=\$[^']|"|`)/, "\\\\") end def render_commented(filename) render(filename).gsub(/^(?=.)/, "# ").gsub(/^$/, "#") end end zim = Zim.new %># AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE. # DO NOT DIRECTLY EDIT THIS FILE! <%= zim.render_commented("LICENSE") %> <%= zim.render_all("src/stage2/*.erb") %> zimfw "${@}" zimfw-1.20.0/test/000077500000000000000000000000001512125321400137015ustar00rootroot00000000000000zimfw-1.20.0/test/bats/000077500000000000000000000000001512125321400146325ustar00rootroot00000000000000zimfw-1.20.0/test/test_actions.bats000066400000000000000000000047331512125321400172620ustar00rootroot00000000000000setup() { # shellcheck disable=SC2034 BATS_LIB_PATH="${BATS_TEST_DIRNAME}"/test_helper bats_load_library setup_all setup_all } @test 'can print info' { run zsh "${PWD}"/zimfw.zsh info assert_success assert_line "ZIM_HOME: ${ZIM_HOME}" assert_line "zimfw config: ${HOME}/.zimrc" assert_line "zimfw script: ${PWD}/zimfw.zsh" } @test 'can print info with symlinks' { mkdir -p "${HOME}"/dotfiles/zim touch "${HOME}"/dotfiles/zimrc ln -s "${HOME}"/dotfiles/zim "${HOME}"/.zim ln -s "${HOME}"/dotfiles/zimrc "${HOME}"/.zimrc ln -s "${PWD}"/zimfw.zsh "${HOME}"/zimfw.zsh REAL_HOME="$(realpath "${HOME}")" run zsh "${HOME}"/zimfw.zsh info assert_success assert_line "ZIM_HOME: ${HOME}/.zim -> ${REAL_HOME}/dotfiles/zim" assert_line "zimfw config: ${HOME}/.zimrc -> ${REAL_HOME}/dotfiles/zimrc" assert_line "zimfw script: ${HOME}/zimfw.zsh -> ${PWD}/zimfw.zsh" } @test 'can turn script path to absolute path' { cat >"${HOME}"/.zimrc <test.sh <<<"echo test"' EOF cat >"${HOME}"/expected_init.zsh <= latest version (will be greater than when current version is not released yet) printf '%s\n%s\n' "${LATEST_VERSION}" "${CURRENT_VERSION}" | sort -cV if [ "${CURRENT_VERSION}" = "${LATEST_VERSION}" ]; then assert_output '' else assert_output "Latest zimfw version is ${LATEST_VERSION}. You're using version ${CURRENT_VERSION}. Run zimfw upgrade to upgrade." fi } zimfw-1.20.0/test/test_helper/000077500000000000000000000000001512125321400162175ustar00rootroot00000000000000zimfw-1.20.0/test/test_helper/bats-assert/000077500000000000000000000000001512125321400204475ustar00rootroot00000000000000zimfw-1.20.0/test/test_helper/bats-file/000077500000000000000000000000001512125321400200655ustar00rootroot00000000000000zimfw-1.20.0/test/test_helper/bats-support/000077500000000000000000000000001512125321400206625ustar00rootroot00000000000000zimfw-1.20.0/test/test_helper/setup_all000066400000000000000000000006601512125321400201340ustar00rootroot00000000000000# vim:et sts=2 sw=2 ft=sh setup_all() { bats_load_library bats-support bats_load_library bats-assert bats_load_library bats-file command -v git # assert git command installed assert_file_exists "${PWD}"/zimfw.zsh export HOME="${BATS_TEST_TMPDIR}" export ZIM_HOME="${HOME}"/.zim cat >"${HOME}"/.zshenv <"${HOME}"/.zshrc <"${HOME}"/.zimrc <init.zsh <<<"print test"' --cmd 'cat {}/init.zsh' EOF cat >"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/external/init.zsh <"${HOME}"/.zimrc <init.zsh <<<"print test"' zmodule ${HOME}/external EOF cat >"${HOME}"/expected_init.zsh <init.zsh <<<\"print test\" cmd: source \"\${HOME}/.zim/modules/test/init.zsh\" modules/external (external) From: ${HOME}/external cmd: source \"\${HOME}/external/init.zsh\"" cat >"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/external-zsh/external.zsh <"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <custom.zsh <<<"print custom"' zmodule custom --root 1 --on-pull '>custom.zsh <<<"print custom1"' zmodule custom --root 2 --on-pull '>custom.zsh <<<"print custom2"' EOF cat >"${HOME}"/expected_init.zsh <custom.zsh <<<\"print custom\"; (builtin cd -q 1; >custom.zsh <<<\"print custom1\"); (builtin cd -q 2; >custom.zsh <<<\"print custom2\") Root: . cmd: source \"\${HOME}/.zim/modules/custom/custom.zsh\" Root: 1 cmd: source \"\${HOME}/.zim/modules/custom/1/custom.zsh\" Root: 2 cmd: source \"\${HOME}/.zim/modules/custom/2/custom.zsh\"" } @test 'can define module with roots and custom options' { cat >"${HOME}"/.zimrc <init.zsh <<<"print \\\${CUSTOM1}"' --if '[[ -n \${CUSTOM1} ]]' zmodule custom --root 2 --on-pull '>init.zsh <<<"print custom2"' zmodule custom --root 3 --on-pull '>init.zsh <<<"print custom3"' --if-command cat --cmd 'cat {}/init.zsh' zmodule custom --root 1 -c 'print -R "\${(F)\$(<{}/init.zsh)}"' EOF cat >"${HOME}"/expected_init.zsh <init.zsh <<<\"print \\\${CUSTOM1}\"); (builtin cd -q 2; >init.zsh <<<\"print custom2\"); (builtin cd -q 3; >init.zsh <<<\"print custom3\") Root: 1 if: [[ -n \${CUSTOM1} ]] cmd: source \"\${HOME}/.zim/modules/custom/1/init.zsh\"; print -R \"\${(F)\$(<\"\${HOME}/.zim/modules/custom/1\"/init.zsh)}\" Root: 2 cmd: source \"\${HOME}/.zim/modules/custom/2/init.zsh\" Root: 3 if: (( \${+commands[cat]} )) cmd: cat \"\${HOME}/.zim/modules/custom/3\"/init.zsh" CUSTOM1=custom1 run zsh -ic 'exit' assert_success # shellcheck disable=SC2016 assert_output 'custom1 print ${CUSTOM1} custom2 print custom3' cat >"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <init.zsh <<<"print custom1"' zmodule ignoreprefix/custom1/ --root /1/ --on-pull '>1.zsh <<<"print custom1_1"' zmodule ignoreprefix/custom1/ --root /2/ --on-pull '>2.zsh <<<"print custom1_2"' zmodule ignoreurl/ --name /tmp/custom2/ --use mkdir --on-pull '>custom2.zsh <<<"print custom2"' zmodule https://ignoreurl/ --name /tmp/custom3/ --root 1/ --use mkdir --on-pull '>custom3.zsh <<<"print custom3_1"' EOF cat >"${HOME}"/expected_init.zsh <init.zsh <<<\"print custom1\"; (builtin cd -q 1; >1.zsh <<<\"print custom1_1\"); (builtin cd -q 2; >2.zsh <<<\"print custom1_2\") Root: . cmd: source \"\${HOME}/.zim/modules/custom1/init.zsh\" Root: 1 cmd: source \"\${HOME}/.zim/modules/custom1/1/1.zsh\" Root: 2 cmd: source \"\${HOME}/.zim/modules/custom1/2/2.zsh\" modules/tmp/custom2 From: mkdir On-pull: >custom2.zsh <<<\"print custom2\" cmd: source \"\${HOME}/.zim/modules/tmp/custom2/custom2.zsh\" modules/tmp/custom3 From: mkdir On-pull: (builtin cd -q 1; >custom3.zsh <<<\"print custom3_1\") Root: 1 cmd: source \"\${HOME}/.zim/modules/tmp/custom3/1/custom3.zsh\"" } @test 'can define external module with roots' { mkdir -p "${HOME}"/external/{1,2} touch "${HOME}"/external/{1,2}/external.zsh cat >"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <"${HOME}"/expected_init.zsh <"${HOME}"/expected_zdegit <"${HOME}"/.zshrc <"${HOME}"/.zimrc <init.zsh <<<"print init"; mkdir functions; >functions/custom <<<"print custom"' EOF cat >"${HOME}"/expected_init.zsh <init.zsh <<<\"print init\"; mkdir functions; >functions/custom <<<\"print custom\" fpath: \"${ZIM_HOME}/modules/custom/functions\" autoload: custom cmd: source \"${ZIM_HOME}/modules/custom/init.zsh\"" run zsh -ic 'custom' assert_success assert_output "init custom" } zimfw-1.20.0/test/test_zimrc.bats000066400000000000000000000202641512125321400167430ustar00rootroot00000000000000setup() { # shellcheck disable=SC2034 BATS_LIB_PATH="${BATS_TEST_DIRNAME}"/test_helper bats_load_library setup_all setup_all } @test 'cannot init with empty .zimrc' { touch "${HOME}"/.zimrc run zsh "${PWD}"/zimfw.zsh init assert_failure assert_output "No modules defined in ${HOME}/.zimrc" } @test 'can configure path to .zimrc' { export ZIM_CONFIG_FILE="${HOME}"/.config/zsh/zimrc mkdir -p "$(dirname "${ZIM_CONFIG_FILE}")" cat >"${ZIM_CONFIG_FILE}" <test.zsh <<<"print test"' EOF cat >"${HOME}"/expected_init.zsh <"${HOME}"/.zimrc <! {}/\${ztarget}; zcompile -R {}/\${ztarget}; fi" \ --source \${ztarget} } zmodule-eval 'zoxide init zsh' EOF cat >"${HOME}"/expected_init.zsh <! "\${HOME}/.zim/modules/custom/zoxide"/zoxide-init-zsh.zsh; zcompile -R "\${HOME}/.zim/modules/custom/zoxide"/zoxide-init-zsh.zsh; fi source "\${HOME}/.zim/modules/custom/zoxide/zoxide-init-zsh.zsh" fi EOF run zsh "${PWD}"/zimfw.zsh init assert_success assert_output ') modules/custom: Created' assert_dir_exists "${ZIM_HOME}"/modules/custom/zoxide assert_file_not_exists "${ZIM_HOME}"/modules/custom/zoxide/zoxide-init-zsh.zsh assert_files_equal "${ZIM_HOME}"/init.zsh "${HOME}"/expected_init.zsh run zsh "${PWD}"/zimfw.zsh list assert_success assert_output 'modules/custom' run zsh "${PWD}"/zimfw.zsh list -v assert_success assert_output "modules/custom From: mkdir Root: zoxide if: (( \${+commands[zoxide]} )) cmd: if [[ ! \"\${HOME}/.zim/modules/custom/zoxide\"/zoxide-init-zsh.zsh -nt \${commands[zoxide]} ]]; then zoxide init zsh >! \"\${HOME}/.zim/modules/custom/zoxide\"/zoxide-init-zsh.zsh; zcompile -R \"\${HOME}/.zim/modules/custom/zoxide\"/zoxide-init-zsh.zsh; fi; source \"\${HOME}/.zim/modules/custom/zoxide/zoxide-init-zsh.zsh\"" } @test 'can create default .zimrc' { cat >"${HOME}"/expected_init.zsh < 0 )) print "${@}" } _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" 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" fi } _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 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:-${ZDOTDIR:-${HOME}}/.zimrc} ]] 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}) # Keep fpath constant regardless of "if" root dirs, to avoid confusing compinit. # Move all from zfunctions and zcmds with "if" root dirs prefixes. for zroot_dir in ${_zroot_dirs}; do if (( ${+_zifs[${zroot_dir}]} )); then zpre=${zroot_dir}$'\0' zif_functions+=(${(M)zfunctions:#${zpre}*}) zif_cmds+=(${(M)zcmds:#${zpre}*}) zfunctions=(${zfunctions:#${zpre}*}) zcmds=(${zcmds:#${zpre}*}) fi done zpre=$'*\0' if (( ${#_zfpaths} )) print -R 'fpath=('${_zfpaths#${~zpre}}' ${fpath})' if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}} for zroot_dir in ${_zroot_dirs}; do zpre=${zroot_dir}$'\0' if (( ${+_zifs[${zroot_dir}]} )); then zroot_functions=(${${(M)zif_functions:#${zpre}*}#${zpre}}) zroot_cmds=(${${(M)zif_cmds:#${zpre}*}#${zpre}}) if (( ${#zroot_functions} || ${#zroot_cmds} )); then print -R 'if '${_zifs[${zroot_dir}]}'; then' if (( ${#zroot_functions} )) print -R ' autoload -Uz -- '${zroot_functions} if (( ${#zroot_cmds} )) print -R ${(F):- ${^zroot_cmds}} print fi fi else zroot_cmds=(${${(M)zcmds:#${zpre}*}#${zpre}}) if (( ${#zroot_cmds} )) print -R ${(F)zroot_cmds} fi done ) ${ztarget} } _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 command mv -f ${ztarget}{,.old} || return 1 fi _zimfw_mv =( print '# Do nothing. This file is deprecated.' ) ${ztarget} } _zimfw_build() { _zimfw_build_init && _zimfw_build_login_init && _zimfw_print "Done with build.${_zrestartmsg}" } _zimfw_source_zimrc() { zmodule() { local -r zusage="Usage: ${_zbold}${0}${_znormal} [${_zbold}-n${_znormal}|${_zbold}--name${_znormal} ] [${_zbold}-r${_znormal}|${_zbold}--root${_znormal} ] [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. Module absolute path or repository URL. The following are equiva- lent: ${_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} Set a custom module name. Default: the last component in . Slashes can be used inside to organize the module into subdirectories. The module will be installed at ${_zbold}${ZIM_HOME}/${_znormal}. ${_zbold}-r${_znormal}, ${_zbold}--root${_znormal} Relative path to the module root. Per-module options: ${_zbold}-b${_znormal}, ${_zbold}--branch${_znormal} Use specified branch when installing and updating the module. Overrides the tag option. Default: the repository default branch. ${_zbold}-t${_znormal}, ${_zbold}--tag${_znormal} Use specified tag when installing and updating the module. Over- rides the branch option. ${_zbold}-u${_znormal}, ${_zbold}--use${_znormal} Install and update the module using the defined tool. Default is either defined using ${_zbold}zstyle ':zim:zmodule' use '${_znormal}${_zbold}'${_znormal} or set to ${_zbold}'auto'${_znormal}. The tools available are: ${_zbold}'auto'${_znormal} tries to auto detect the tool to be used. When installing a new module, ${_zbold}'git'${_znormal} will be used if the git command is available, otherwise ${_zbold}'degit'${_znormal} will be used. ${_zbold}'git'${_znormal} uses the git command. Local changes are preserved on up- dates. ${_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 is only used to set the module name. Use the ${_zbold}-c${_znormal}, ${_zbold}--cmd${_znormal} option or ${_zbold}--on-pull${_znormal} option 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} 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} 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}${_zbold}]} ))'${_znormal}. ${_zbold}--if-ostype${_znormal} 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}${_zbold} ]]'${_znormal}. ${_zbold}--on-pull${_znormal} 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} 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} Will autoload specified function. Default: all valid names inside the ${_zbold}functions${_znormal} subdirectory, if any. ${_zbold}-s${_znormal}, ${_zbold}--source${_znormal} 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} subdirectory exists, else the largest of the files matching the glob ${_zbold}(init.zsh|${_znormal}${_zbold}.(zsh|plugin.zsh|zsh-theme|sh))${_znormal}, if any. The in the glob is resolved to the last component of the mod- ule name and the last component of the path to the module root. ${_zbold}-c${_znormal}, ${_zbold}--cmd${_znormal} 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 zname=modules/${zname} _znames+=(${zname}) if [[ ${zurl} == /* ]]; then _zpaths[${zname}]=${zurl%%/##} zurl= else _zpaths[${zname}]=${ZIM_HOME}/${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=${_zpaths[${zname}]}${zroot:+/${zroot}} _zroot_dirs+=(${zroot_dir}) # Set default values if (( ! ${+_ztools[${zname}]} )); then zstyle -s ':zim:zmodule' use "_ztools[${zname}]" || _ztools[${zname}]=auto 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_paths+=(${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 # Detect tool if auto and not external and not frozen module if [[ ${_ztools[${zname}]} == auto && -n ${_zurls[${zname}]} && _zfrozens[${zname}] -eq 0 ]]; then if [[ -e ${_zpaths[${zname}]} ]]; then if [[ -r ${_zpaths[${zname}]}/.git ]]; then _ztools[${zname}]=git elif [[ -r ${_zpaths[${zname}]}/.zdegit ]]; then _ztools[${zname}]=degit else _zimfw_print -u2 -lR "${_zwarn}${funcfiletrace[1]}:${_zbold}${zname}:${_znormalyellow} Could not auto detect tool, will default to ${_zbold}mkdir${_znormalyellow}. Use zmodule option ${_zbold}-u${_znormalyellow}|${_zbold}--use${_znormalyellow} to stop this warning.${_znormal}" _ztools[${zname}]=mkdir fi else if [[ ${+commands[git]} -ne 0 && -x ${commands[git]} ]]; then _ztools[${zname}]=git else _ztools[${zname}]=degit fi fi fi if (( ! ${_zdisabled_paths[(I)${zroot_dir}]} && _zeager )); 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=(${${(@qqq)zfpaths:a}/${HOME}/\${HOME}}) _zfpaths+=(${zpre}${^zfpaths}) _zfunctions+=(${zpre}${^zfunctions}) zcmds=(${zcmds//${HOME}/\${HOME}}) _zcmds+=(${zpre}${^zcmds}) fi } { local -ri _zeager=${1} local -i _zfailed=0 if [[ ! -e ${_zconfig} ]]; then _zimfw_print -u2 "${_zyellow}Config file not found, will create ${_zbold}${_zconfig}${_znormal}" command mkdir -p ${_zconfig:h} || return 1 print -Rn "# # This is not sourced during shell startup and is only used to configure zimfw. # # # Modules # # Sets sane Zsh built-in environment options. zmodule environment # Provides handy git aliases and functions. zmodule git # Applies correct bindkeys for input events. zmodule input # Sets a custom terminal title. zmodule termtitle # Utility aliases and functions. Adds colour to ls, grep and less. zmodule utility # <-- Normally new modules should be added here. Check each module documentation # for any caveats. # # Prompt # # Exposes how long the last command took to run to prompts. zmodule duration-info # Exposes git repository status information to prompts. zmodule git-info # A heavily reduced, ASCII-only version of the Spaceship and Starship prompts. zmodule asciiship # # Completion # # Additional completion definitions for Zsh. zmodule zsh-users/zsh-completions --fpath src # Enables and configures smart and extensive tab completion, must be sourced # after all modules that add completion definitions. zmodule completion # # Modules that must be initialized last # # Fish-like syntax highlighting for Zsh, must be sourced after completion. zmodule zsh-users/zsh-syntax-highlighting # Fish-like history search for Zsh, must be sourced after # zsh-users/zsh-syntax-highlighting. zmodule zsh-users/zsh-history-substring-search # Fish-like autosuggestions for Zsh. Add the following to your ~/.zshrc to boost # performance: ZSH_AUTOSUGGEST_MANUAL_REBIND=1 zmodule zsh-users/zsh-autosuggestions " >${_zconfig} || return 1 fi if ! source ${_zconfig} || (( _zfailed )); then print -u2 -R "${_zred}Failed to source ${_zbold}${_zconfig}${_znormal}" return 1 fi if (( ${#_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 paths prefixes local zpath zpre for zpath in ${_zdisabled_paths}; do zpre=${zpath}$'\0' _zfpaths=(${_zfpaths:#${zpre}*}) _zfunctions=(${_zfunctions:#${zpre}*}) _zcmds=(${_zcmds:#${zpre}*}) done } always { unfunction zmodule } } _zimfw_list_unused_paths() { local -i i=1 local zinstalled=(${ZIM_HOME}/modules/*(N/)) local -r zpaths=(${(v)_zpaths}) # Search into subdirectories while (( i <= ${#zinstalled} )); do if (( zpaths[(I)${zinstalled[i]}/*] )); then zinstalled+=(${zinstalled[i]}/*(N/)) zinstalled[i]=() else (( i++ )) fi done # Unused = all installed dirs not in zpaths _zunused_paths=(${zinstalled:|zpaths}) local zunused for zunused (${_zunused_paths}) _zimfw_print -R "${_zbold}${zunused##${ZIM_HOME}/}${_znormal}${1}" } _zimfw_check_dumpfile() { _zimfw_print -u2 "${_zyellow}Deprecated action. This is now handled by the completion module alone.${_znormal}" } _zimfw_check_version() { if (( ${1} )); then if (( ${2} )); then # background check if [[ -w ${_zversion_target:h} ]]; then print -R ${${${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs --sort=-v:refname \ https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &! fi else # foreground check local tags tags=$(command git ls-remote --tags --refs --sort=-v:refname https://github.com/zimfw/zimfw.git 'v*') || return 1 >! ${_zversion_target} <<<${${${(f)tags}##*v}[1]} || return 1 fi fi if [[ -f ${_zversion_target} ]]; then local -r zlatest_version=$(<${_zversion_target}) if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then _zimfw_print -u2 -R "${_zyellow}Latest zimfw version is ${_zbold}${zlatest_version}${_znormalyellow}. You're using version ${_zbold}${_zversion}${_znormalyellow}. Run ${_zbold}zimfw upgrade${_znormalyellow} to upgrade.${_znormal}" return 4 fi fi } _zimfw_clean_compiled() { # Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once. local -Ur zscriptdirs=(${ZIM_HOME:A} ${${(v)_zpaths##${ZIM_HOME}/*}:A}) 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_clean_dumpfile() { local zdumpfile zopt 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 -R "Done with clean-dumpfile.${_zrestartmsg}" } _zimfw_compile() { # Compile zimfw scripts local zroot_dir zfile for zroot_dir in ${_zroot_dirs:|_zdisabled_paths}; do if [[ ! -w ${zroot_dir} ]]; then _zimfw_print -R "${_zwarn}${_zbold}${zroot_dir}:${_znormalyellow} No write permission, unable to compile.${_znormal}" continue fi for zfile in ${zroot_dir}/(^*test*/)#*.zsh(|-theme)(N-.); do if [[ ! ${zfile}.zwc -nt ${zfile} ]]; then zcompile -R ${zfile} && _zimfw_print -R "${_zokay}${_zbold}${zfile}.zwc:${_znormal} Compiled" fi done done _zimfw_print 'Done with compile.' } _zimfw_info() { _zimfw_info_print_symlink ZIM_HOME ${ZIM_HOME} _zimfw_info_print_symlink 'zimfw config' ${_zconfig} _zimfw_info_print_symlink 'zimfw script' ${__ZIMFW_FILE} print -R 'zimfw version: '${_zversion}' (built at 2025-12-19 13:42:11 UTC, previous commit is 88af323)' local zparam for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZSH_VERSION; do print -R ${(r.22....:.)zparam}${(P)zparam} done } _zimfw_info_print_symlink() { print -Rn ${(r.22....:.)1}${2} if [[ -L ${2} ]] print -Rn ' -> '${2:A} print } _zimfw_uninstall() { if (( _zprintlevel <= 0 )); then command rm -rf ${_zunused_paths} || return 1 else local zunused_path print "Found ${_zbold}${#_zunused_paths}${_znormal} unused module(s)." for zunused_path in ${_zunused_paths}; do if read -q "?Uninstall ${zunused_path} [y/N]? "; then print command rm -rfv ${zunused_path} || return 1 else print fi done print 'Done with uninstall.' fi } _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 { if [[ ${+commands[curl]} -ne 0 && -x ${commands[curl]} ]]; then command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1 else local zopt 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}" fi return 1 fi fi command gunzip -f ${ztarget}.new.gz || return 1 # .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.${_zrestartmsg}" } always { command rm -f ${ztarget}.new{,.gz} } } _zimfw_run_list() { local -r zname=${1} local -r zpath=${_zpaths[${zname}]} local -r zroot_dirs=(${(M)_zroot_dirs:#${zpath}(|/*)}) print -nR ${_zbold}${zname}${_znormal} if [[ ! -e ${zpath} ]] print -n ' (not installed)' if [[ -z ${_zurls[${zname}]} ]] print -n ' (external)' if (( _zfrozens[${zname}] )) print -n ' (frozen)' if [[ ${_zdisabled_paths[(I)${zpath}]} -ne 0 && ${zroot_dirs} == (${zpath}) ]] print -n ' (disabled)' print if (( _zprintlevel > 1 )); then if [[ -z ${_zurls[${zname}]} ]]; then print -R ' From: '${zpath} elif (( ! _zfrozens[${zname}] )); then if [[ ${_ztools[${zname}]} == mkdir ]]; then print ' From: mkdir' 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 fi if [[ -n ${_zonpulls[${zname}]} ]] print -R " On-pull: ${_zonpulls[${zname}]}" fi local zroot_dir zindent zpre local -a zfpaths zfunctions zcmds for zroot_dir in ${zroot_dirs}; do if [[ ${zroot_dirs} == (${zpath}) ]]; then zindent=' ' else if [[ ${zroot_dir} == ${zpath} ]]; then print -n ' Root: .' else print -nR ' Root: '${zroot_dir##${zpath}/} fi if (( _zdisabled_paths[(I)${zroot_dir}] )) print -n ' (disabled)' print zindent=' ' fi if (( ${+_zifs[${zroot_dir}]} )) print -R ${zindent}'if: '${_zifs[${zroot_dir}]} zpre=${zroot_dir}$'\0' zfpaths=(${${(M)_zfpaths:#${zpre}*}#${zpre}}) zfunctions=(${${(M)_zfunctions:#${zpre}*}#${zpre}}) zcmds=(${${(M)_zcmds:#${zpre}*}#${zpre}}) if (( ${#zfpaths} )) print -R ${zindent}'fpath: '${zfpaths} if (( ${#zfunctions} )) print -R ${zindent}'autoload: '${zfunctions} if (( ${#zcmds} )) print -R ${zindent}'cmd: '${(j:; :)zcmds} done 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 -lR "${_zerror}${_zbold}${_zname}:${_znormalred} ${1}${_znormal}" ${2:+${(F):- ${(f)^2}}} } _zimfw_print_okay() { if (( _zprintlevel > ${2:-0} )) print -lR "${_zokay}${_zbold}${_zname}:${_znormal} ${1}" ${3:+${(F):- ${(f)^3}}} } _zimfw_print_warn() { _zimfw_print -u2 -R "${_zwarn}${_zbold}${_zname}:${_znormalyellow} ${1}${_znormal}" } _zimfw_pull_print_okay() { # Useb by tools, which run in a subshell if [[ -n ${ONPULL} ]]; then if ! ERR=$(builtin cd -q ${DIR} 2>&1 && builtin eval ${ONPULL} 2>&1); then _zimfw_print_error 'Error during on-pull' ${ERR} return 1 elif [[ ${_zprintlevel} -gt 1 && -n ${ERR} ]]; then # Overrides ${3} to include the on-pull output, to be used by _zimfw_print_okay below. builtin set ${1} ${2:-0} ${3:+${3}$'\n'}'On-pull output:'$'\n'${ERR} fi fi _zimfw_print_okay "${@}" } _zimfw_download_tarball() { if [[ ${URL} =~ ^([^:@/]+://)?([^@]+@)?([^:/]+)[:/]([^/]+/[^/]+)/?$ ]]; then readonly HOST=${match[3]} readonly REPO=${match[4]%.git} fi if [[ ${HOST} != github.com || -z ${REPO} ]]; then _zimfw_print_error "${URL} is not a valid 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." return 1 fi readonly HEADERS_TARGET=${DIR}/${TEMP}_headers { if [[ ${ACTION} != install ]]; then readonly INFO=("${(@f)"$(<${INFO_TARGET})"}") # 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 [[ -z ${INFO_HEADER} ]] return 0 if [[ ${+commands[curl]} -ne 0 && -x ${commands[curl]} ]]; then command curl -IfsL -H ${INFO_HEADER} ${TARBALL_URL} >${HEADERS_TARGET} else command wget --spider -qS --header=${INFO_HEADER} ${TARBALL_URL} 2>${HEADERS_TARGET} fi else if [[ ${+commands[curl]} -ne 0 && -x ${commands[curl]} ]]; then if ! ERR=$(command curl -fsSL ${INFO_HEADER:+-H} ${INFO_HEADER} -o ${TARBALL_TARGET} -D ${HEADERS_TARGET} ${TARBALL_URL} 2>&1); then _zimfw_print_error "Error downloading ${TARBALL_URL} with curl" ${ERR} return 1 fi else # wget returns 8 when 304 Not Modified, so we cannot use wget's error codes command wget -qS ${INFO_HEADER:+--header=${INFO_HEADER}} -O ${TARBALL_TARGET} ${TARBALL_URL} 2>${HEADERS_TARGET} fi fi while IFS= read -r HEADER; do HEADER=${${HEADER## ##}%%$'\r'##} if [[ ${HEADER} == HTTP/* ]]; then HTTP_CODE=${${(s: :)HEADER}[2]} elif [[ ${${(L)HEADER%%:*}%% ##} == etag ]]; then ETAG=${${HEADER#*:}## ##} fi done < ${HEADERS_TARGET} if (( HTTP_CODE == 304 )); then # Not Modified command rm -f ${TARBALL_TARGET} 2>/dev/null return 0 elif (( HTTP_CODE != 200 )); then _zimfw_print_error "Error downloading ${TARBALL_URL}, HTTP code ${HTTP_CODE}" return 1 fi if [[ -z ${ETAG} ]]; then _zimfw_print_error "Error downloading ${TARBALL_URL}, no ETag header found in response" return 1 fi if [[ ${ACTION} == check ]]; then command touch ${TARBALL_TARGET} # Update available else if ! print -lR "${URL}" "${REV}" "If-None-Match: ${ETAG}" >! ${INFO_TARGET} 2>/dev/null; then _zimfw_print_error "Error creating or updating ${INFO_TARGET}" return 1 fi fi } always { command rm -f ${HEADERS_TARGET} 2>/dev/null } } _zimfw_untar_tarball() { if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then _zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR} return 1 fi local zsubdir for zsubdir in ${1}/*(/); do if ! ERR=$(command mv -f ${zsubdir}/*(DN) ${1} 2>&1 && command rmdir ${zsubdir} 2>&1); then _zimfw_print_error "Error moving ${zsubdir}" ${ERR} return 1 fi done } _zimfw_tool_degit() { # This runs in a subshell readonly -i SUBMODULES=${6} readonly ACTION=${1} DIR=${2} URL=${3} REV=${5} ONPULL=${7} TEMP=.zdegit_${sysparams[pid]}_${RANDOM} 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 ;; install) { _zimfw_create_dir ${DIR} && _zimfw_download_tarball && _zimfw_untar_tarball ${DIR} && _zimfw_pull_print_okay Installed || return 1 } always { # return 1 does not change ${TRY_BLOCK_ERROR}, only changes ${?} (( TRY_BLOCK_ERROR = ? )) command rm -f ${TARBALL_TARGET} 2>/dev/null if (( TRY_BLOCK_ERROR )) command rm -rf ${DIR} 2>/dev/null } ;; check|update) readonly DIR_NEW=${DIR}${TEMP} { _zimfw_download_tarball || return 1 if [[ ${ACTION} == check ]]; then if [[ -e ${TARBALL_TARGET} ]]; then _zimfw_print_okay 'Update available' return 4 fi _zimfw_print_okay 'Already up to date' 1 return 0 else if [[ -e ${TARBALL_TARGET} ]]; then _zimfw_create_dir ${DIR_NEW} && _zimfw_untar_tarball ${DIR_NEW} || return 1 if [[ ${+commands[diff]} -ne 0 && -x ${commands[diff]} ]]; then LOG=$(command diff -x '.zdegit*' -x '*.zwc' -x '*.zwc.old' -qr ${DIR} ${DIR_NEW} 2>/dev/null) LOG=${${LOG//${DIR_NEW}/new}//${DIR}/old} fi if ! ERR=$({ command cp -f ${INFO_TARGET} ${DIR_NEW} && \ command rm -rf ${DIR} && command mv -f ${DIR_NEW} ${DIR} } 2>&1); then _zimfw_print_error "Error updating ${DIR}" ${ERR} return 1 fi _zimfw_pull_print_okay Updated 0 ${LOG} || return 1 else _zimfw_pull_print_okay 'Already up to date' || return 1 fi fi } always { command rm -f ${TARBALL_TARGET} 2>/dev/null command rm -rf ${DIR_NEW} 2>/dev/null } ;; esac # Check after successful install or update if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then _zimfw_print_warn "Module contains git submodules, which are not supported by zimfw's degit. Use zmodule option ${_zbold}--no-submodules${_znormalyellow} to stop this warning." fi } _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 if [[ ${TYPE} == branch ]]; then if [[ -z ${REV} ]]; then if REV=$(command git -C ${DIR} symbolic-ref --short refs/remotes/origin/HEAD 2>&1); then REV=${REV#origin/} else _zimfw_print_error 'Error during git symbolic-ref.'${premsg} ${REV} return 1 fi fi readonly AHEAD_AND_BEHIND=$(command git -C ${DIR} rev-list --count --left-right ${REV}...${REV}@{u} -- 2>/dev/null) readonly -i AHEAD=${AHEAD_AND_BEHIND[(w)1]} readonly -i BEHIND=${AHEAD_AND_BEHIND[(w)2]} if (( AHEAD && BEHIND )); then _zimfw_print_error "Diverged [ahead ${AHEAD}, behind ${BEHIND}]."${premsg} return 1 fi fi fi ;; install) if ERR=$(command git clone ${REV:+-b} ${REV} -q --config core.autocrlf=false ${${SUBMODULES:#0}:+--recursive} -- ${URL} ${DIR} 2>&1); then _zimfw_pull_print_okay Installed else _zimfw_print_error 'Error during git clone' ${ERR} return 1 fi ;; check|update) if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then _zimfw_print_error 'Error during git fetch' ${ERR} return 1 fi if [[ ${TYPE} == branch ]]; then if [[ -z ${REV} ]]; then # Get HEAD remote branch if ! ERR=$(command git -C ${DIR} remote set-head origin -a 2>&1); then _zimfw_print_error 'Error during git remote set-head' ${ERR} return 1 fi if REV=$(command git -C ${DIR} symbolic-ref --short refs/remotes/origin/HEAD 2>&1); then REV=${REV#origin/} else _zimfw_print_error 'Error during git symbolic-ref' ${REV} return 1 fi fi if [[ ${ACTION} == check ]]; then readonly -i BEHIND=$(command git -C ${DIR} rev-list --count ${REV}..${REV}@{u} -- 2>/dev/null) if (( BEHIND )); then _zimfw_print_okay "Update available [behind ${BEHIND}]" return 4 else _zimfw_print_okay 'Already up to date' 1 return 0 fi fi TO_REV=${REV}@{u} else if [[ ${REV} == $(command git -C ${DIR} describe --tags --exact-match 2>/dev/null) ]]; then if [[ ${ACTION} == check ]]; then _zimfw_print_okay 'Already up to date' 1 return 0 else _zimfw_pull_print_okay 'Already up to date' return ${?} fi fi if [[ ${ACTION} == check ]]; then _zimfw_print_okay 'Update available' return 4 fi TO_REV=${REV} fi if [[ -z ${NO_COLOR} && -t 1 ]]; 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 if ! ERR=$(command git -C ${DIR} checkout -q ${REV} -- 2>&1); then _zimfw_print_error 'Error during git checkout' ${ERR} return 1 fi if [[ ${TYPE} == branch ]]; then if ! OUT=$(command git -C ${DIR} merge --ff-only --no-progress -n 2>&1); then _zimfw_print_error 'Error during git merge' ${OUT} return 1 fi # keep just first line of OUT OUT=${OUT%%($'\n'|$'\r')*} else OUT="Updating to ${TYPE} ${REV}" fi if (( SUBMODULES )); then if ! ERR=$(command git -C ${DIR} submodule update --init --recursive -q -- 2>&1); then _zimfw_print_error 'Error during git submodule update' ${ERR} return 1 fi fi _zimfw_pull_print_okay ${OUT} 0 ${LOG} ;; esac } _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) ]] return 0 if [[ ${ACTION} == check ]]; then _zimfw_print_okay 'Skipping mkdir module' 1 return 0 fi 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 local -r zroot_dirs=(${(M)_zroot_dirs:#${DIR}(|/*)}) local zroot_dir for zroot_dir in ${zroot_dirs}; do _zimfw_create_dir ${zroot_dir} || return 1 done _zimfw_pull_print_okay Created || return 1 fi } _zimfw_run_tool() { local zaction=${1} local -r _zname=${2} if [[ -z ${_zurls[${_zname}]} ]]; then _zimfw_print_okay 'Skipping external module' 1 return 0 fi if (( _zfrozens[${_zname}] )); then _zimfw_print_okay 'Skipping frozen module' 1 return 0 fi local -r ztool=${_ztools[${_zname}]} if [[ ${ztool} != (degit|git|mkdir) ]]; then _zimfw_print_error "Unknown tool ${ztool}" return 1 fi set "${_zpaths[${_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 zpath_new=.${_zpaths[${_zname}]}_${sysparams[pid]}_${RANDOM} { _zimfw_tool_${ztool} install ${zpath_new} "${@:2}" || return 1 if ! ERR=$({ command rm -rf ${_zpaths[${_zname}]} && command mv -f ${zpath_new} ${_zpaths[${_zname}]} } 2>&1); then _zimfw_print_error "Error reinstalling ${_zpaths[${_zname}]}" ${ERR} return 1 fi } always { command rm -rf ${zpath_new} 2>/dev/null } return 0 else _zimfw_tool_${ztool} pre "${@}" || return 1 fi case ${zaction} in install) if [[ -e ${_zpaths[${_zname}]} ]]; then _zimfw_print_okay 'Skipping already installed module' 1 return 0 fi ;; check|update) if [[ ! -d ${_zpaths[${_zname}]} ]]; then _zimfw_print_error "Not installed. Run ${_zbold}zimfw install${_znormalred} to install." return 1 fi ;; *) _zimfw_print_error "Unknown action ${zaction}" return 1 ;; esac _zimfw_tool_${ztool} ${zaction} "${@}" } _zimfw_run_tool_action() { local -i zmaxprocs=0 if [[ ${1} == reinstall ]] zmaxprocs=1 _zimfw_source_zimrc 0 || return 1 zargs -n 2 -P ${zmaxprocs} -- "${_znames[@]}" -- _zimfw_run_tool ${1} return 0 } zimfw() { builtin emulate -L zsh -o EXTENDED_GLOB if [[ -z ${NO_COLOR} && -t 1 ]]; 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}x " _zokay="${_zgreen}) ${_znormal}" _zwarn="${_zyellow}! " local -r _zconfig=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zversion='1.20.0' local -r zusage="Usage: ${_zbold}${0}${_znormal} [option] 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}info${_znormal} Print zimfw and system info. ${_zbold}list${_znormal} List all modules defined in ${_zbold}${_zconfig}${_znormal}. Use ${_zbold}-v${_znormal} to also see their initialization details. ${_zbold}init${_znormal} Same as ${_zbold}install${_znormal}, but with output tailored for the terminal startup. ${_zbold}install${_znormal} Install new modules. 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}update${_znormal} Update current modules. 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}reinstall${_znormal} Reinstall modules that failed check. Prompts for confirmation, unless ${_zbold}-q${_znormal} is used. 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, unless ${_zbold}-q${_znormal} is used. Also does ${_zbold}build${_znormal}. Use ${_zbold}-v${_znormal} to also see its output. ${_zbold}check${_znormal} Check if updates for current modules are available. Use ${_zbold}-v${_znormal} to also see skipped and up to date 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}help${_znormal}, ${_zbold}--help${_znormal} Print this help. ${_zbold}version${_znormal}, ${_zbold}--version${_znormal} Print zimfw version. Options: ${_zbold}-q${_znormal} Quiet (yes to prompts and only output errors) ${_zbold}-v${_znormal} Verbose (output more details)" local -i _zprintlevel=1 if (( # > 2 )); then print -u2 -lR "${_zred}${0}: Too many options${_znormal}" '' ${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} return 2 ;; esac fi case ${1} in help|--help) print -R ${zusage} return ;; version|--version) print -R ${_zversion} return ;; esac if (( ! ${+ZIM_HOME} )); then print -u2 -R "${_zred}${0}: ${_zbold}ZIM_HOME${_znormalred} not defined${_znormal}" return 1 fi if [[ ! -e ${ZIM_HOME} ]]; then command mkdir -p ${ZIM_HOME} || return 1 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 .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 -Ua _znames _zroot_dirs _zdisabled_paths local -A _zfrozens _ztools _zpaths _zurls _ztypes _zrevs _zsubmodules _zonpulls _zifs local -a _zfpaths _zfunctions _zcmds _zunused_paths local _zrestartmsg=' Restart your terminal for changes to take effect.' autoload -Uz zargs case ${1} in build) _zimfw_source_zimrc 1 && _zimfw_build || return 1 (( _zprintlevel-- )) _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-dumpfile) _zimfw_clean_dumpfile ;; compile) _zimfw_source_zimrc 0 && _zimfw_compile ;; info) _zimfw_info ;; list) _zimfw_source_zimrc $(( _zprintlevel > 1 )) && \ zargs -n 1 -- "${_znames[@]}" -- _zimfw_run_list && \ _zimfw_list_unused_paths ' (unused)' ;; check) _zimfw_run_tool_action ${1} || return 1 (( _zprintlevel-- )) _zimfw_print -R "Done with ${1}. Run ${_zbold}zimfw update${_znormal} to update modules." # 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_source_zimrc 1 && _zimfw_build && _zimfw_compile ;; install|update|reinstall) _zimfw_run_tool_action ${1} || return 1 _zimfw_print -R "Done with ${1}.${_zrestartmsg}" (( _zprintlevel-- )) _zimfw_source_zimrc 1 && _zimfw_build && _zimfw_compile ;; uninstall) _zimfw_source_zimrc 0 && _zimfw_list_unused_paths && _zimfw_uninstall || return 1 (( _zprintlevel-- )) _zimfw_source_zimrc 1 && _zimfw_build ;; check-version) _zimfw_check_version 1 (( _zprintlevel-- )) _zimfw_print -R "Done with ${1}." # Only printed in verbose mode ;; upgrade) _zimfw_upgrade || return 1 (( _zprintlevel-- )) _zimfw_source_zimrc 0 && _zimfw_compile ;; *) print -u2 -lR "${_zred}${0}: Unknown action ${1}${_znormal}" '' ${zusage} return 2 ;; esac } zimfw "${@}"