1
0
Fork 0
mirror of synced 2024-06-01 14:51:11 -04:00

Compare commits

...

8 commits

Author SHA1 Message Date
Eric Nielsen 96f60da366
Improve zimfw's degit error message
Hopefully make it clearer when either the git or the degit tool is being
used.

See #535
2024-05-30 09:38:44 -05:00
Eric Nielsen cdd9258d5c
Don't expose the zmodule function outside zimfw
Don't want to maintain extra code to allow zmodule to run outside zimfw.
This has no added benefit and might confuse users. If you were calling
zmodule in the shell just to get the help message, hopefully you can
look that up in the documentation instead.
2024-05-30 09:21:16 -05:00
Eric Nielsen 4fcc85b2db
Update README.md with ZIM_CONFIG_FILE instructions
Also add git-info and duration-info modules to the basic templates for a
better user experience.
2024-05-26 12:44:49 -05:00
Eric Nielsen 4200e6cdb3
v1.13.1 2024-04-28 14:07:41 -05:00
Eric Nielsen c86223f473
Don't use tar --strip
as it's not compatible with BSD distributions.
Fixes #534
2024-04-28 14:06:24 -05:00
Eric Nielsen 39d2087ad4
v1.13.0 2024-02-16 21:06:36 -05:00
Eric Nielsen 2e9256a567
Add new mkdir tool to generate empty modules
This will allow creating modules that contain only externally generated
files. For example, this is how I currently use it to generate modules
for code that is supposed to be eval'ed:

    zmodule-eval() {
      local -r zcommand=${${=1}[1]} ztarget=${1//[^[:alnum:]]/-}.zsh
      zmodule custom-${zcommand} --use mkdir --if-command ${zcommand} \
          --cmd "if [[ ! {}/${ztarget} -nt \${commands[${zcommand}]} ]]; then ${1} >! {}/${ztarget}; zcompile -UR {}/${ztarget}; fi" \
          --source ${ztarget}
    }
    zmodule-eval 'starship init zsh'
    unfunction zmodule-eval
2024-02-16 20:41:29 -05:00
Eric Nielsen 8bec2f7549
Add --if-command option to zmodule 2024-01-22 21:36:17 -05:00
14 changed files with 241 additions and 122 deletions

View file

@ -7,7 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
_No unreleased changes._
### Changed
- Don't allow calling `zmodule` from the command line. Let it fail with "command
not found" instead. It's inteded to be used only in the .zimrc script.
## [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
@ -361,7 +379,8 @@ Take your time to review the updated [README.md] and the changes listed below.
[termtitle]: https://github.com/zimfw/termtitle
[s1ck94]: https://github.com/zimfw/s1ck94
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.12.1...HEAD
[Unreleased]: https://github.com/zimfw/zimfw/compare/v1.13.0...HEAD
[1.13.0]: https://github.com/zimfw/zimfw/compare/v1.12.1...v1.13.0
[1.12.1]: https://github.com/zimfw/zimfw/compare/v1.12.0...v1.12.1
[1.12.0]: https://github.com/zimfw/zimfw/compare/v1.11.3...v1.12.0
[1.11.3]: https://github.com/zimfw/zimfw/compare/v1.11.2...v1.11.3

View file

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

View file

@ -47,12 +47,14 @@ Installing Zim is easy. You can choose either the automatic or manual method bel
This will install a predefined set of modules and a theme for you.
* With `curl`:
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```zsh
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
* With `wget`:
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```zsh
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
Restart your terminal and you're done. Enjoy your Zsh IMproved! Take some time
to tweak your [`~/.zshrc`](#set-up-zshrc) file, and to also check the available
@ -82,7 +84,16 @@ Add the lines below to your `~/.zshrc` file, in the following order:
This is optional, and only required if you don't have `git` installed (yes,
Zim works even without `git`!)
2. To set where the directory used by Zim will be located:
2. To set where the `zimfw` plugin manager configuration file will be located:
```zsh
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
```
This is optional. The value of `ZIM_CONFIG_FILE` can be any path your user
has at least read access to. By default, the file must be at `~/.zimrc`, if
the `ZDOTDIR` environment variable is not defined. Otherwise, it must be at
`${ZDOTDIR}/.zimrc`.
3. To set where the directory used by Zim will be located:
```zsh
ZIM_HOME=~/.zim
```
@ -91,7 +102,7 @@ Add the lines below to your `~/.zshrc` file, in the following order:
`~/.cache/zim` if you also include the step below, that automatically
downloads the `zimfw` plugin manager.
3. To automatically download the `zimfw` plugin manager if missing:
4. To automatically download the `zimfw` plugin manager if missing:
```zsh
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
@ -110,11 +121,11 @@ Add the lines below to your `~/.zshrc` file, in the following order:
This is optional. If you choose to not include this step, you should manually
download the `zimfw.zsh` script once and keep it at `${ZIM_HOME}`.
4. To automatically install missing modules and update the static initialization
5. To automatically install missing modules and update the static initialization
script if missing or outdated:
```zsh
# Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
```
@ -122,7 +133,7 @@ Add the lines below to your `~/.zshrc` file, in the following order:
it, you must remember to manually run `zimfw install` every time after you
update your [`~/.zimrc`](#create-zimrc) file.
5. To source the static script, that will initialize your modules:
6. To source the static script, that will initialize your modules:
```zsh
# Initialize modules.
source ${ZIM_HOME}/init.zsh
@ -130,18 +141,31 @@ Add the lines below to your `~/.zshrc` file, in the following order:
#### Create `~/.zimrc`
You must create your `.zimrc` file at `~/.zimrc`, if the `ZDOTDIR` environment
variable is not defined. Otherwise, it must be at `${ZDOTDIR}/.zimrc`. It's
referred to as `~/.zimrc` in the documentation for the sake of simplicity.
This file configures the `zimfw` plugin manager. It's referred to as `~/.zimrc`
in the documentation for the sake of simplicity, but the actual location of the
file is defined following these rules:
You can start with just:
1. You can define the full path and name of the file with a `ZIM_CONFIG_FILE`
environment variable. For example:
```zsh
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
```
2. Or, if you defined a `ZDOTDIR` environment variable, then the file must be at
`${ZDOTDIR}/.zimrc`
3. Otherwise, it must be at at `~/.zimrc`, which is it's default location.
As for the contents of the file, you can start with just:
```zsh
zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions
```
If you also want one of our prompt [themes]:
```
```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship
zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions
@ -149,6 +173,8 @@ zmodule zsh-users/zsh-autosuggestions
If you want to use our [completion] module too, instead of using `compinit` directly:
```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship
zmodule zsh-users/zsh-completions --fpath src
zmodule completion
@ -227,7 +253,7 @@ zation will be done in the same order it's defined.
<url> Module absolute path or repository URL. The following URL formats
are equivalent: <b>foo</b>, <b>zimfw/foo</b>, <b>https://github.com/zimfw/foo.git</b>.
If an absolute path is given, the module is considered externally
installed, and won&apos;t be installed or updated by zimfw.
installed and won&apos;t be installed or updated by zimfw.
<b>-n</b>|<b>--name</b> &lt;module_name&gt; Set a custom module name. Default: the last component in &lt;url&gt;.
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
@ -239,13 +265,16 @@ Per-module options:
Overrides the tag option. Default: the repository default branch.
<b>-t</b>|<b>--tag</b> &lt;tag_name&gt; Use specified tag when installing and updating the module. Over-
rides the branch option.
<b>-u</b>|<b>--use</b> &lt;<b>git</b>|<b>degit</b>&gt; Install and update the module using the defined tool. Default is
either defined by <b>zstyle &apos;:zim:zmodule&apos; use &apos;</b>&lt;<b>git</b>|<b>degit</b>&gt;<b>&apos;</b>, or <b>git</b>
if none is provided.
<b>git</b> requires git itself. Local changes are preserved on updates.
<b>degit</b> requires curl or wget, and currently only works with GitHub
<b>-u</b>|<b>--use</b> &lt;tool_name&gt; Install and update the module using the defined tool. Default is
either defined by <b>zstyle &apos;:zim:zmodule&apos; use &apos;</b>&lt;tool_name&gt;<b>&apos;</b>, or <b>git</b>
if none is provided. The tools available are:
<b>git</b> uses the git command. Local changes are preserved on updates.
<b>degit</b> uses curl or wget, and currently only works with GitHub
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
<b>mkdir</b> creates an empty directory. The &lt;url&gt; is only used to set
the module name. Use the <b>-c</b>|<b>--cmd</b> or <b>--on-pull</b> options to execute
the desired command to generate the module files.
<b>--no-submodules</b> Don&apos;t install or update git submodules.
<b>-z</b>|<b>--frozen</b> Don&apos;t install or update the module.
@ -255,6 +284,9 @@ Per-module options:
Per-module-root options:
<b>--if</b> &lt;test&gt; Will only initialize module root if specified test returns a zero
exit status. The test is evaluated at every new terminal startup.
<b>--if-command</b> &lt;cmd_name&gt; Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to <b>--if &apos;(( ${+commands[</b>&lt;cmd_name&gt;<b>]} ))&apos;</b>.
<b>--on-pull</b> &lt;command&gt; Execute command after installing or updating the module. The com-
mand is executed in the module root directory.
<b>-d</b>|<b>--disabled</b> Don&apos;t initialize the module root or uninstall the module.

View file

@ -8,7 +8,7 @@ The initialization will be done in the same order it\'s defined.
<url> Module absolute path or repository URL. The following URL formats
are equivalent: <%= bold %>foo<%= normal %>, <%= bold %>zimfw/foo<%= normal %>, <%= bold %>https://github.com/zimfw/foo.git<%= normal %>.
If an absolute path is given, the module is considered externally
installed, and won\'t be installed or updated by zimfw.
installed and won\'t be installed or updated by zimfw.
<%= bold %>-n<%= normal %>|<%= bold %>--name<%= normal %> <module_name> Set a custom module name. Default: the last component in <url>.
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
@ -20,13 +20,16 @@ Per-module options:
Overrides the tag option. Default: the repository default branch.
<%= bold %>-t<%= normal %>|<%= bold %>--tag<%= normal %> <tag_name> Use specified tag when installing and updating the module. Over-
rides the branch option.
<%= bold %>-u<%= normal %>|<%= bold %>--use<%= normal %> <<%= bold %>git<%= normal %>|<%= bold %>degit<%= normal %>> Install and update the module using the defined tool. Default is
either defined by <%= bold %>zstyle \':zim:zmodule\' use \'<%= normal %><<%= bold %>git<%= normal %>|<%= bold %>degit<%= normal %>><%= bold %>\'<%= normal %>, or <%= bold %>git<%= normal %>
if none is provided.
<%= bold %>git<%= normal %> requires git itself. Local changes are preserved on updates.
<%= bold %>degit<%= normal %> requires curl or wget, and currently only works with GitHub
<%= bold %>-u<%= normal %>|<%= bold %>--use<%= normal %> <tool_name> Install and update the module using the defined tool. Default is
either defined by <%= bold %>zstyle \':zim:zmodule\' use \'<%= normal %><tool_name><%= bold %>\'<%= normal %>, or <%= bold %>git<%= normal %>
if none is provided. The tools available are:
<%= bold %>git<%= normal %> uses the git command. Local changes are preserved on updates.
<%= bold %>degit<%= normal %> uses curl or wget, and currently only works with GitHub
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
<%= bold %>mkdir<%= normal %> creates an empty directory. The <url> is only used to set
the module name. Use the <%= bold %>-c<%= normal %>|<%= bold %>--cmd<%= normal %> or <%= bold %>--on-pull<%= normal %> options to execute
the desired command to generate the module files.
<%= bold %>--no-submodules<%= normal %> Don\'t install or update git submodules.
<%= bold %>-z<%= normal %>|<%= bold %>--frozen<%= normal %> Don\'t install or update the module.
@ -36,6 +39,9 @@ Per-module options:
Per-module-root options:
<%= bold %>--if<%= normal %> <test> Will only initialize module root if specified test returns a zero
exit status. The test is evaluated at every new terminal startup.
<%= bold %>--if-command<%= normal %> <cmd_name> Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to <%= bold %>--if \'(( \${+commands[<%= normal %><cmd_name><%= bold %>]} ))\'<%= normal %>.
<%= bold %>--on-pull<%= normal %> <command> Execute command after installing or updating the module. The com-
mand is executed in the module root directory.
<%= bold %>-d<%= normal %>|<%= bold %>--disabled<%= normal %> Don\'t initialize the module root or uninstall the module.
@ -125,7 +131,7 @@ Per-call initialization options:
# Set values from options
while (( # > 0 )); do
case ${1} in
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|--if-command|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
if (( # < 2 )); then
print -u2 -lR $'<%= red %><%= error %>'${funcfiletrace[1]}$':<%= bold %>'${zname}$':<%= normalred %> Missing argument for zmodule option <%= bold %>'${1}$'<%= normal %>' '' ${zusage}
_zfailed=1
@ -165,6 +171,10 @@ Per-call initialization options:
shift
_zifs[${zroot_dir}]=${1}
;;
--if-command)
shift
_zifs[${zroot_dir}]="(( \${+commands[${1}]} ))"
;;
-f|--fpath)
shift
zarg=${1}

View file

@ -6,7 +6,6 @@ _zimfw_build_init() {
fi
_zimfw_mv =(
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})

View file

@ -1,20 +1,25 @@
_zimfw_source_zimrc() {
local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>'
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -R $'<%= red %>No modules defined in <%= bold %>'${ztarget}$'<%= normal %>'
return 1
fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre
for zroot_dir in ${_zdisabled_root_dirs}; do
zpre=${zroot_dir}$'\0'
_zfpaths=(${_zfpaths:#${zpre}*})
_zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*})
done
<%= render_all("src/functions/*.erb") %>
{
local -r ztarget=${ZIM_CONFIG_FILE:-<%= home %>/.zimrc} _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -R $'<%= red %>Failed to source <%= bold %>'${ztarget}$'<%= normal %>'
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -R $'<%= red %>No modules defined in <%= bold %>'${ztarget}$'<%= normal %>'
return 1
fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre
for zroot_dir in ${_zdisabled_root_dirs}; do
zpre=${zroot_dir}$'\0'
_zfpaths=(${_zfpaths:#${zpre}*})
_zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*})
done
} always {
unfunction zmodule
}
}

View file

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

View file

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

View file

@ -4,7 +4,7 @@ _zimfw_download_tarball() {
readonly REPO=${match[4]%.git}
fi
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
_zimfw_print_error "${URL} is not a valid GitHub URL. Will not try to ${_zaction}."
_zimfw_print_error ${URL}$' is not a valid URL. Will not try to '${_zaction}$'. The zimfw degit tool only supports GitHub URLs. Use zmodule option <%= bold %>--use git<%= normalred %> to use git instead.'
return 1
fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
@ -12,7 +12,7 @@ _zimfw_download_tarball() {
if [[ -r ${INFO_TARGET} ]]; then
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
if [[ ${URL} != ${INFO[1]} ]]; then
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
# Previous REV is in line 2, reserved for future use.
@ -71,17 +71,17 @@ _zimfw_download_tarball() {
}
_zimfw_untar_tarball() {
if ! ERR=$(command tar -C ${1} --strip=1 -xzf ${TARBALL_TARGET} 2>&1); then
if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then
_zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1
fi
}
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${ERR}
return 1
fi
local zsubdir
for zsubdir in ${1}/*(/); do
if ! ERR=$(command mv -f ${zsubdir}/*(DN) ${1} 2>&1 && command rmdir ${zsubdir} 2>&1); then
_zimfw_print_error "Error moving ${zsubdir}" ${ERR}
return 1
fi
done
}
_zimfw_tool_degit() {
@ -102,7 +102,7 @@ _zimfw_tool_degit() {
;;
check|update)
if [[ ! -r ${INFO_TARGET} ]]; then
_zimfw_print -u2 -R $'<%= clear_line %><%= yellow %><%= warn %><%= bold %>'${_zname}$':<%= normalyellow %> Module was not installed using zimfw\'s degit. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.<%= normal %>'
_zimfw_print_warn $'Module was not installed using zimfw\'s degit. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.'
return 0
fi
readonly DIR_NEW=${DIR}${TEMP}
@ -139,7 +139,7 @@ _zimfw_tool_degit() {
;;
esac
# Check after successful install or update
if [[ ${_zprintlevel} -gt 0 && ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
print -u2 -R $'<%= clear_line %><%= yellow %><%= warn %><%= bold %>'${_zname}$':<%= normalyellow %> Module contains git submodules, which are not supported by zimfw\'s degit. Use zmodule option <%= bold %>--no-submodules<%= normalyellow %> to disable this warning.<%= normal %>'
if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
_zimfw_print_warn $'Module contains git submodules, which are not supported by zimfw\'s degit. Use zmodule option <%= bold %>--no-submodules<%= normalyellow %> to disable this warning.'
fi
}

View file

@ -14,11 +14,11 @@ _zimfw_tool_git() {
;;
check|update)
if [[ ! -r ${DIR}/.git ]]; then
_zimfw_print -u2 -R $'<%= clear_line %><%= yellow %><%= warn %><%= bold %>'${_zname}$':<%= normalyellow %> Module was not installed using git. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.<%= normal %>'
_zimfw_print_warn 'Module was not installed using git. Will not try to '${_zaction}$'. Use zmodule option <%= bold %>-z<%= normalyellow %>|<%= bold %>--frozen<%= normalyellow %> to disable this warning.'
return 0
fi
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
_zimfw_print_error "The git URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then

View file

@ -0,0 +1,14 @@
_zimfw_tool_mkdir() {
# This runs in a subshell
readonly -i SUBMODULES=${5}
readonly DIR=${1} TYPE=${3} REV=${4} ONPULL=${6}
if [[ -n ${REV} ]]; then
_zimfw_print_warn $'The zmodule option <%= bold %>-'${TYPE[1]}$'<%= normalyellow %>|<%= bold %>--'${TYPE}$'<%= normalyellow %> has no effect when using the mkdir tool'
fi
if (( ! SUBMODULES )); then
_zimfw_print_warn $'The zmodule option <%= bold %>--no-submodules<%= normalyellow %> has no effect when using the mkdir tool'
fi
if [[ ! -d ${DIR} || -n ${ONPULL} ]]; then
_zimfw_create_dir ${DIR} && _zimfw_pull_print_okay Created || return 1
fi
}

View file

@ -34,7 +34,7 @@ _zimfw_run_tool() {
esac
local -r ztool=${_ztools[${_zname}]}
case ${ztool} in
degit|git)
degit|git|mkdir)
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
;;
*)

View file

@ -4,7 +4,7 @@ class Zim
:bold, :normal, :red, :normalred, :yellow, :normalyellow, :clear_line, :ellipsis, :okay, :warn, :error
def initialize
@version = "1.12.1"
@version = "1.13.1"
@home = "${ZDOTDIR:-${HOME}}"
@min_zsh_version = "5.2"
# Matches {ssh,http,https,git}://{user@,}host/org/repo and {user@,}host:org/repo
@ -42,8 +42,4 @@ zim = Zim.new
<%= zim.render_commented("LICENSE") %>
<%= zim.render_all("src/stage2/*.erb") %>
if [[ ${functrace[1]} == zmodule:* ]]; then
zmodule "${@}"
else
zimfw "${@}"
fi
zimfw "${@}"

137
zimfw.zsh
View file

@ -4,7 +4,7 @@
# MIT License
#
# Copyright (c) 2015-2016 Matt Hamilton and contributors
# Copyright (c) 2016-2023 Eric Nielsen, Matt Hamilton and contributors
# Copyright (c) 2016-2024 Eric Nielsen, Matt Hamilton and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@ -58,7 +58,6 @@ _zimfw_build_init() {
fi
_zimfw_mv =(
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})
@ -110,6 +109,7 @@ _zimfw_build() {
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
}
_zimfw_source_zimrc() {
zmodule() {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc}
local -r zusage=$'Usage: \E[1m'${0}$'\E[0m <url> [\E[1m-n\E[0m|\E[1m--name\E[0m <module_name>] [\E[1m-r\E[0m|\E[1m--root\E[0m <path>] [options]
@ -120,7 +120,7 @@ The initialization will be done in the same order it\'s defined.
<url> Module absolute path or repository URL. The following URL formats
are equivalent: \E[1mfoo\E[0m, \E[1mzimfw/foo\E[0m, \E[1mhttps://github.com/zimfw/foo.git\E[0m.
If an absolute path is given, the module is considered externally
installed, and won\'t be installed or updated by zimfw.
installed and won\'t be installed or updated by zimfw.
\E[1m-n\E[0m|\E[1m--name\E[0m <module_name> Set a custom module name. Default: the last component in <url>.
Slashes can be used inside the name to organize the module into
subdirectories. The module will be installed at
@ -132,13 +132,16 @@ Per-module options:
Overrides the tag option. Default: the repository default branch.
\E[1m-t\E[0m|\E[1m--tag\E[0m <tag_name> Use specified tag when installing and updating the module. Over-
rides the branch option.
\E[1m-u\E[0m|\E[1m--use\E[0m <\E[1mgit\E[0m|\E[1mdegit\E[0m> Install and update the module using the defined tool. Default is
either defined by \E[1mzstyle \':zim:zmodule\' use \'\E[0m<\E[1mgit\E[0m|\E[1mdegit\E[0m>\E[1m\'\E[0m, or \E[1mgit\E[0m
if none is provided.
\E[1mgit\E[0m requires git itself. Local changes are preserved on updates.
\E[1mdegit\E[0m requires curl or wget, and currently only works with GitHub
\E[1m-u\E[0m|\E[1m--use\E[0m <tool_name> Install and update the module using the defined tool. Default is
either defined by \E[1mzstyle \':zim:zmodule\' use \'\E[0m<tool_name>\E[1m\'\E[0m, or \E[1mgit\E[0m
if none is provided. The tools available are:
\E[1mgit\E[0m uses the git command. Local changes are preserved on updates.
\E[1mdegit\E[0m uses curl or wget, and currently only works with GitHub
URLs. Modules install faster and take less disk space. Local
changes are lost on updates. Git submodules are not supported.
\E[1mmkdir\E[0m creates an empty directory. The <url> is only used to set
the module name. Use the \E[1m-c\E[0m|\E[1m--cmd\E[0m or \E[1m--on-pull\E[0m options to execute
the desired command to generate the module files.
\E[1m--no-submodules\E[0m Don\'t install or update git submodules.
\E[1m-z\E[0m|\E[1m--frozen\E[0m Don\'t install or update the module.
@ -148,6 +151,9 @@ Per-module options:
Per-module-root options:
\E[1m--if\E[0m <test> Will only initialize module root if specified test returns a zero
exit status. The test is evaluated at every new terminal startup.
\E[1m--if-command\E[0m <cmd_name> Will only initialize module root if specified external command is
available. This is evaluated at every new terminal startup.
Equivalent to \E[1m--if \'(( \${+commands[\E[0m<cmd_name>\E[1m]} ))\'\E[0m.
\E[1m--on-pull\E[0m <command> Execute command after installing or updating the module. The com-
mand is executed in the module root directory.
\E[1m-d\E[0m|\E[1m--disabled\E[0m Don\'t initialize the module root or uninstall the module.
@ -237,7 +243,7 @@ Per-call initialization options:
# Set values from options
while (( # > 0 )); do
case ${1} in
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
-b|--branch|-t|--tag|-u|--use|--on-pull|--if|--if-command|-f|--fpath|-a|--autoload|-s|--source|-c|--cmd)
if (( # < 2 )); then
print -u2 -lR $'\E[31mx '${funcfiletrace[1]}$':\E[1m'${zname}$':\E[0;31m Missing argument for zmodule option \E[1m'${1}$'\E[0m' '' ${zusage}
_zfailed=1
@ -277,6 +283,10 @@ Per-call initialization options:
shift
_zifs[${zroot_dir}]=${1}
;;
--if-command)
shift
_zifs[${zroot_dir}]="(( \${+commands[${1}]} ))"
;;
-f|--fpath)
shift
zarg=${1}
@ -341,25 +351,28 @@ Per-call initialization options:
fi
}
_zimfw_source_zimrc() {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m'
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m'
return 1
fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre
for zroot_dir in ${_zdisabled_root_dirs}; do
zpre=${zroot_dir}$'\0'
_zfpaths=(${_zfpaths:#${zpre}*})
_zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*})
done
{
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1}
local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then
print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m'
return 1
fi
if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m'
return 1
fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre
for zroot_dir in ${_zdisabled_root_dirs}; do
zpre=${zroot_dir}$'\0'
_zfpaths=(${_zfpaths:#${zpre}*})
_zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*})
done
} always {
unfunction zmodule
}
}
_zimfw_list_unuseds() {
@ -444,7 +457,7 @@ _zimfw_compile() {
}
_zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2023-09-16 18:25:16 UTC, previous commit is 26151d2)'
print -R 'zimfw version: '${_zversion}' (built at 2024-05-30 14:34:14 UTC, previous commit is cdd9258)'
local zparam
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do
print -R ${(r.22....:.)zparam}${(P)zparam}
@ -529,6 +542,13 @@ _zimfw_run_list() {
fi
}
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${ERR}
return 1
fi
}
_zimfw_print_error() {
print -u2 -lR $'\E[2K\r\E[31mx \E[1m'${_zname}$':\E[0;31m '${1}$'\E[0m' ${2:+${(F):- ${(f)^2}}}
}
@ -537,6 +557,10 @@ _zimfw_print_okay() {
if (( _zprintlevel > ${2:-0} )) print -lR $'\E[2K\r\E[32m)\E[0m \E[1m'${_zname}$':\E[0m '${1} ${3:+${(F):- ${(f)^3}}}
}
_zimfw_print_warn() {
_zimfw_print -u2 -R $'\E[2K\r\E[33m! \E[1m'${_zname}$':\E[0;33m '${1}$'\E[0m'
}
_zimfw_pull_print_okay() {
# Useb by tools, which run in a subshell
if [[ -n ${ONPULL} ]]; then
@ -557,7 +581,7 @@ _zimfw_download_tarball() {
readonly REPO=${match[4]%.git}
fi
if [[ ${HOST} != github.com || -z ${REPO} ]]; then
_zimfw_print_error "${URL} is not a valid GitHub URL. Will not try to ${_zaction}."
_zimfw_print_error ${URL}$' is not a valid URL. Will not try to '${_zaction}$'. The zimfw degit tool only supports GitHub URLs. Use zmodule option \E[1m--use git\E[0;31m to use git instead.'
return 1
fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
@ -565,7 +589,7 @@ _zimfw_download_tarball() {
if [[ -r ${INFO_TARGET} ]]; then
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
if [[ ${URL} != ${INFO[1]} ]]; then
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
_zimfw_print_error "The zimfw degit URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
# Previous REV is in line 2, reserved for future use.
@ -624,17 +648,17 @@ _zimfw_download_tarball() {
}
_zimfw_untar_tarball() {
if ! ERR=$(command tar -C ${1} --strip=1 -xzf ${TARBALL_TARGET} 2>&1); then
if ! ERR=$(command tar -C ${1} -xzf ${TARBALL_TARGET} 2>&1); then
_zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1
fi
}
_zimfw_create_dir() {
if ! ERR=$(command mkdir -p ${1} 2>&1); then
_zimfw_print_error "Error creating ${1}" ${ERR}
return 1
fi
local zsubdir
for zsubdir in ${1}/*(/); do
if ! ERR=$(command mv -f ${zsubdir}/*(DN) ${1} 2>&1 && command rmdir ${zsubdir} 2>&1); then
_zimfw_print_error "Error moving ${zsubdir}" ${ERR}
return 1
fi
done
}
_zimfw_tool_degit() {
@ -655,7 +679,7 @@ _zimfw_tool_degit() {
;;
check|update)
if [[ ! -r ${INFO_TARGET} ]]; then
_zimfw_print -u2 -R $'\E[2K\r\E[33m! \E[1m'${_zname}$':\E[0;33m Module was not installed using zimfw\'s degit. Will not try to '${_zaction}$'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.\E[0m'
_zimfw_print_warn $'Module was not installed using zimfw\'s degit. Will not try to '${_zaction}$'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.'
return 0
fi
readonly DIR_NEW=${DIR}${TEMP}
@ -692,8 +716,8 @@ _zimfw_tool_degit() {
;;
esac
# Check after successful install or update
if [[ ${_zprintlevel} -gt 0 && ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
print -u2 -R $'\E[2K\r\E[33m! \E[1m'${_zname}$':\E[0;33m Module contains git submodules, which are not supported by zimfw\'s degit. Use zmodule option \E[1m--no-submodules\E[0;33m to disable this warning.\E[0m'
if [[ ${SUBMODULES} -ne 0 && -e ${DIR}/.gitmodules ]]; then
_zimfw_print_warn $'Module contains git submodules, which are not supported by zimfw\'s degit. Use zmodule option \E[1m--no-submodules\E[0;33m to disable this warning.'
fi
}
@ -713,11 +737,11 @@ _zimfw_tool_git() {
;;
check|update)
if [[ ! -r ${DIR}/.git ]]; then
_zimfw_print -u2 -R $'\E[2K\r\E[33m! \E[1m'${_zname}$':\E[0;33m Module was not installed using git. Will not try to '${_zaction}$'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.\E[0m'
_zimfw_print_warn 'Module was not installed using git. Will not try to '${_zaction}$'. Use zmodule option \E[1m-z\E[0;33m|\E[1m--frozen\E[0;33m to disable this warning.'
return 0
fi
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then
_zimfw_print_error "URL does not match. Expected ${URL}. Will not try to ${_zaction}."
_zimfw_print_error "The git URL does not match. Expected ${URL}. Will not try to ${_zaction}."
return 1
fi
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
@ -791,6 +815,21 @@ _zimfw_tool_git() {
esac
}
_zimfw_tool_mkdir() {
# This runs in a subshell
readonly -i SUBMODULES=${5}
readonly DIR=${1} TYPE=${3} REV=${4} ONPULL=${6}
if [[ -n ${REV} ]]; then
_zimfw_print_warn $'The zmodule option \E[1m-'${TYPE[1]}$'\E[0;33m|\E[1m--'${TYPE}$'\E[0;33m has no effect when using the mkdir tool'
fi
if (( ! SUBMODULES )); then
_zimfw_print_warn $'The zmodule option \E[1m--no-submodules\E[0;33m has no effect when using the mkdir tool'
fi
if [[ ! -d ${DIR} || -n ${ONPULL} ]]; then
_zimfw_create_dir ${DIR} && _zimfw_pull_print_okay Created || return 1
fi
}
_zimfw_run_tool() {
local -r _zname=${1}
if [[ -z ${_zurls[${_zname}]} ]]; then
@ -827,7 +866,7 @@ _zimfw_run_tool() {
esac
local -r ztool=${_ztools[${_zname}]}
case ${ztool} in
degit|git)
degit|git|mkdir)
_zimfw_tool_${ztool} "${_zdirs[${_zname}]}" "${_zurls[${_zname}]}" "${_ztypes[${_zname}]}" "${_zrevs[${_zname}]}" "${_zsubmodules[${_zname}]}" "${_zonpulls[${_zname}]}"
;;
*)
@ -845,7 +884,7 @@ _zimfw_run_tool_action() {
zimfw() {
builtin emulate -L zsh -o EXTENDED_GLOB
local -r _zversion='1.12.1' _zversion_target=${ZIM_HOME}/.latest_version zusage=$'Usage: \E[1m'${0}$'\E[0m <action> [\E[1m-q\E[0m|\E[1m-v\E[0m]
local -r _zversion='1.13.1' _zversion_target=${ZIM_HOME}/.latest_version zusage=$'Usage: \E[1m'${0}$'\E[0m <action> [\E[1m-q\E[0m|\E[1m-v\E[0m]
Actions:
\E[1mbuild\E[0m Build \E[1m'${ZIM_HOME}$'/init.zsh\E[0m and \E[1m'${ZIM_HOME}$'/login_init.zsh\E[0m.
@ -949,8 +988,4 @@ Options:
esac
}
if [[ ${functrace[1]} == zmodule:* ]]; then
zmodule "${@}"
else
zimfw "${@}"
fi
zimfw "${@}"