1
0
Fork 0
mirror of synced 2024-06-17 14:21:09 -04:00

Compare commits

...

10 commits

Author SHA1 Message Date
Eric Nielsen 897afc9cf9
Reapply "Use ${HOME} in generated static init.zsh script"
This reverts commit 9a47fde0c8.
2024-06-17 07:29:19 -05:00
Eric Nielsen 76164d6217
Allow zimfw.zsh to exist outside ZIM_HOME
and change initialization so ZIM_HOME is required before sourcing the
script.
2024-06-14 20:17:07 -05:00
Eric Nielsen 9a47fde0c8
Revert "Use ${HOME} in generated static init.zsh script"
This reverts commit 06f8bc71a3.

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

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

See #535
2024-05-30 09:38:44 -05:00
Eric Nielsen cdd9258d5c
Don't expose the zmodule function outside zimfw
Don't want to maintain extra code to allow zmodule to run outside zimfw.
This has no added benefit and might confuse users. If you were calling
zmodule in the shell just to get the help message, hopefully you can
look that up in the documentation instead.
2024-05-30 09:21:16 -05:00
Eric Nielsen 4fcc85b2db
Update README.md with ZIM_CONFIG_FILE instructions
Also add git-info and duration-info modules to the basic templates for a
better user experience.
2024-05-26 12:44:49 -05:00
Eric Nielsen 4200e6cdb3
v1.13.1 2024-04-28 14:07:41 -05:00
Eric Nielsen c86223f473
Don't use tar --strip
as it's not compatible with BSD distributions.
Fixes #534
2024-04-28 14:06:24 -05:00
12 changed files with 161 additions and 94 deletions

View file

@ -7,13 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
_No unreleased changes._ ### Changed
- 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.
- Allow zimfw.zsh to exist anywhere else, not only inside `ZIM_HOME`. This
enables installing the zimfw.zsh script independently with a package manager.
### 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 ## [1.13.0] - 2024-02-17
### Added ### Added
- `--if-command` option to zmodule. This option is equivalent to - `--if-command` option to `zmodule`. This option is equivalent to
`--if "(( \${+commands[${1}]} ))"`. `--if "(( \${+commands[${1}]} ))"`.
- `mkdir` tool option in `zmodule` that creates an empty directory. This allows - `mkdir` tool option in `zmodule` that creates an empty directory. This allows
creating modules that contain only externally generated files. creating modules that contain only externally generated files.

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. This will install a predefined set of modules and a theme for you.
* With `curl`: * With `curl`:
```zsh
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
* With `wget`: * With `wget`:
```zsh
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
```
Restart your terminal and you're done. Enjoy your Zsh IMproved! Take some time Restart your terminal and you're done. Enjoy your Zsh IMproved! Take some time
to tweak your [`~/.zshrc`](#set-up-zshrc) file, and to also check the available to tweak your [`~/.zshrc`](#set-up-zshrc) file, and to also check the available
@ -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, This is optional, and only required if you don't have `git` installed (yes,
Zim works even without `git`!) 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 ```zsh
ZIM_HOME=~/.zim 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 `~/.cache/zim` if you also include the step below, that automatically
downloads the `zimfw` plugin manager. 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 ```zsh
# Download zimfw plugin manager if missing. # Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then 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 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}`. 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: script if missing or outdated:
```zsh ```zsh
# Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated. # 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 source ${ZIM_HOME}/zimfw.zsh init -q
fi 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 it, you must remember to manually run `zimfw install` every time after you
update your [`~/.zimrc`](#create-zimrc) file. 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 ```zsh
# Initialize modules. # Initialize modules.
source ${ZIM_HOME}/init.zsh source ${ZIM_HOME}/init.zsh
@ -130,18 +141,31 @@ Add the lines below to your `~/.zshrc` file, in the following order:
#### Create `~/.zimrc` #### Create `~/.zimrc`
You must create your `.zimrc` file at `~/.zimrc`, if the `ZDOTDIR` environment This file configures the `zimfw` plugin manager. It's referred to as `~/.zimrc`
variable is not defined. Otherwise, it must be at `${ZDOTDIR}/.zimrc`. It's in the documentation for the sake of simplicity, but the actual location of the
referred to as `~/.zimrc` in the documentation for the sake of simplicity. 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 ```zsh
zmodule zsh-users/zsh-syntax-highlighting zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions zmodule zsh-users/zsh-autosuggestions
``` ```
If you also want one of our prompt [themes]: If you also want one of our prompt [themes]:
``` ```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship zmodule asciiship
zmodule zsh-users/zsh-syntax-highlighting zmodule zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-autosuggestions 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: If you want to use our [completion] module too, instead of using `compinit` directly:
```zsh ```zsh
zmodule git-info
zmodule duration-info
zmodule asciiship zmodule asciiship
zmodule zsh-users/zsh-completions --fpath src zmodule zsh-users/zsh-completions --fpath src
zmodule completion zmodule completion

View file

@ -189,11 +189,11 @@ Per-call initialization options:
shift shift
zarg=${1} zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg} if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zcmds+=("source ${(q-)zarg:a}") zcmds+=('source '${(qqq)zarg:a})
;; ;;
-c|--cmd) -c|--cmd)
shift shift
zcmds+=(${1//{}/${(q-)zroot_dir:a}}) zcmds+=(${1//{}/${(qqq)zroot_dir:a}})
;; ;;
-d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;; -d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;;
*) *)
@ -221,11 +221,11 @@ Per-call initialization options:
local -ra prezto_scripts=(${zroot_dir}/init.zsh(N)) local -ra prezto_scripts=(${zroot_dir}/init.zsh(N))
if (( ${#zfpaths} && ${#prezto_scripts} )); then if (( ${#zfpaths} && ${#prezto_scripts} )); then
# this follows the prezto module format, no need to check for other scripts # this follows the prezto module format, no need to check for other scripts
zcmds=('source '${(q-)^prezto_scripts:a}) zcmds=('source '${(qqq)^prezto_scripts:a})
else else
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) # 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])) local -ra zscripts=(${zroot_dir}/(init.zsh|(${zname:t}|${zroot_dir:t}).(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds=('source '${(q-)^zscripts:a}) zcmds=('source '${(qqq)^zscripts:a})
fi fi
fi fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
@ -235,6 +235,7 @@ Per-call initialization options:
local -r zpre=${zroot_dir}$'\0' local -r zpre=${zroot_dir}$'\0'
_zfpaths+=(${zpre}${^zfpaths}) _zfpaths+=(${zpre}${^zfpaths})
_zfunctions+=(${zpre}${^zfunctions}) _zfunctions+=(${zpre}${^zfunctions})
zcmds=(${zcmds//${HOME}/\${HOME}})
_zcmds+=(${zpre}${^zcmds}) _zcmds+=(${zpre}${^zcmds})
fi fi
} }

View file

@ -4,5 +4,9 @@ autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then
fi fi
autoload -Uz zargs autoload -Uz zargs
if (( ! ${+ZIM_HOME} )); then
print -u2 -R $'<%= red %>'${0}$': ZIM_HOME not defined<%= normal %>'
return 1
fi
# Define zimfw location # Define zimfw location
if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:h} typeset -g __ZIMFW_PATH=${0:h}

View file

@ -7,6 +7,6 @@ _zimfw_mv() {
if [[ -e ${2} ]]; then if [[ -e ${2} ]]; then
command mv -f ${2}{,.old} || return 1 command mv -f ${2}{,.old} || return 1
fi fi
command mv -f ${1} ${2} && _zimfw_print -R $'<%= okay %><%= bold %>'${2}$':<%= normal %> Updated.'${_zrestartmsg} command mv -f ${1} ${2} && command chmod a+r ${2} && _zimfw_print -R $'<%= okay %><%= bold %>'${2}$':<%= normal %> Updated.'${_zrestartmsg}
fi fi
} }

View file

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

View file

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

View file

@ -1,5 +1,5 @@
_zimfw_upgrade() { _zimfw_upgrade() {
local -r ztarget=${ZIM_HOME}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz local -r ztarget=${__ZIMFW_PATH}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
{ {
if (( ${+commands[curl]} )); then if (( ${+commands[curl]} )); then
command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1 command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1

View file

@ -4,7 +4,7 @@ _zimfw_download_tarball() {
readonly REPO=${match[4]%.git} readonly REPO=${match[4]%.git}
fi fi
if [[ ${HOST} != github.com || -z ${REPO} ]]; then 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 return 1
fi fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
@ -12,7 +12,7 @@ _zimfw_download_tarball() {
if [[ -r ${INFO_TARGET} ]]; then if [[ -r ${INFO_TARGET} ]]; then
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}") readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
if [[ ${URL} != ${INFO[1]} ]]; then 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 return 1
fi fi
# Previous REV is in line 2, reserved for future use. # Previous REV is in line 2, reserved for future use.
@ -71,10 +71,17 @@ _zimfw_download_tarball() {
} }
_zimfw_untar_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} _zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1 return 1
fi 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() { _zimfw_tool_degit() {

View file

@ -18,7 +18,7 @@ _zimfw_tool_git() {
return 0 return 0
fi fi
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then 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 return 1
fi fi
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then

View file

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

View file

@ -30,8 +30,12 @@ autoload -Uz is-at-least && if ! is-at-least 5.2; then
fi fi
autoload -Uz zargs autoload -Uz zargs
if (( ! ${+ZIM_HOME} )); then
print -u2 -R $'\E[31m'${0}$': ZIM_HOME not defined\E[0m'
return 1
fi
# Define zimfw location # Define zimfw location
if (( ! ${+ZIM_HOME} )) typeset -g ZIM_HOME=${0:h} typeset -g __ZIMFW_PATH=${0:h}
_zimfw_print() { _zimfw_print() {
if (( _zprintlevel > 0 )) print "${@}" if (( _zprintlevel > 0 )) print "${@}"
@ -46,7 +50,7 @@ _zimfw_mv() {
if [[ -e ${2} ]]; then if [[ -e ${2} ]]; then
command mv -f ${2}{,.old} || return 1 command mv -f ${2}{,.old} || return 1
fi fi
command mv -f ${1} ${2} && _zimfw_print -R $'\E[32m)\E[0m \E[1m'${2}$':\E[0m Updated.'${_zrestartmsg} command mv -f ${1} ${2} && command chmod a+r ${2} && _zimfw_print -R $'\E[32m)\E[0m \E[1m'${2}$':\E[0m Updated.'${_zrestartmsg}
fi fi
} }
@ -57,8 +61,7 @@ _zimfw_build_init() {
command mv -f ${ztarget}{,.old} || return 1 command mv -f ${ztarget}{,.old} || return 1
fi fi
_zimfw_mv =( _zimfw_mv =(
print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" print -R 'zimfw() { source '${${(qqq)__ZIMFW_PATH}/${HOME}/\${HOME}}'/zimfw.zsh "${@}" }'
print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }"
local zroot_dir zpre local zroot_dir zpre
local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zif_functions zif_cmds zroot_functions zroot_cmds
local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds})
@ -74,7 +77,7 @@ _zimfw_build_init() {
fi fi
done done
zpre=$'*\0' zpre=$'*\0'
if (( ${#_zfpaths} )) print -R 'fpath=('${(q-)${_zfpaths#${~zpre}}:a}' ${fpath})' if (( ${#_zfpaths} )) print -R 'fpath=('${${(qqq)${_zfpaths#${~zpre}}:a}/${HOME}/\${HOME}}' ${fpath})'
if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}} if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}}
for zroot_dir in ${_zroot_dirs}; do for zroot_dir in ${_zroot_dirs}; do
zpre=${zroot_dir}$'\0' zpre=${zroot_dir}$'\0'
@ -110,6 +113,7 @@ _zimfw_build() {
_zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.' _zimfw_build_init && _zimfw_build_login_init && _zimfw_print 'Done with build.'
} }
_zimfw_source_zimrc() {
zmodule() { zmodule() {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} 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] 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]
@ -301,11 +305,11 @@ Per-call initialization options:
shift shift
zarg=${1} zarg=${1}
if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg} if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg}
zcmds+=("source ${(q-)zarg:a}") zcmds+=('source '${(qqq)zarg:a})
;; ;;
-c|--cmd) -c|--cmd)
shift shift
zcmds+=(${1//{}/${(q-)zroot_dir:a}}) zcmds+=(${1//{}/${(qqq)zroot_dir:a}})
;; ;;
-d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;; -d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;;
*) *)
@ -333,11 +337,11 @@ Per-call initialization options:
local -ra prezto_scripts=(${zroot_dir}/init.zsh(N)) local -ra prezto_scripts=(${zroot_dir}/init.zsh(N))
if (( ${#zfpaths} && ${#prezto_scripts} )); then if (( ${#zfpaths} && ${#prezto_scripts} )); then
# this follows the prezto module format, no need to check for other scripts # this follows the prezto module format, no need to check for other scripts
zcmds=('source '${(q-)^prezto_scripts:a}) zcmds=('source '${(qqq)^prezto_scripts:a})
else else
# get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) # 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])) local -ra zscripts=(${zroot_dir}/(init.zsh|(${zname:t}|${zroot_dir:t}).(zsh|plugin.zsh|zsh-theme|sh))(NOL[1]))
zcmds=('source '${(q-)^zscripts:a}) zcmds=('source '${(qqq)^zscripts:a})
fi fi
fi fi
if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then
@ -347,29 +351,33 @@ Per-call initialization options:
local -r zpre=${zroot_dir}$'\0' local -r zpre=${zroot_dir}$'\0'
_zfpaths+=(${zpre}${^zfpaths}) _zfpaths+=(${zpre}${^zfpaths})
_zfunctions+=(${zpre}${^zfunctions}) _zfunctions+=(${zpre}${^zfunctions})
zcmds=(${zcmds//${HOME}/\${HOME}})
_zcmds+=(${zpre}${^zcmds}) _zcmds+=(${zpre}${^zcmds})
fi fi
} }
_zimfw_source_zimrc() { {
local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1} local -r ztarget=${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} _zflags=${1}
local -i _zfailed=0 local -i _zfailed=0
if ! source ${ztarget} || (( _zfailed )); then if ! source ${ztarget} || (( _zfailed )); then
print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m' print -u2 -R $'\E[31mFailed to source \E[1m'${ztarget}$'\E[0m'
return 1 return 1
fi fi
if (( _zflags & 1 && ${#_znames} == 0 )); then if (( _zflags & 1 && ${#_znames} == 0 )); then
print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m' print -u2 -R $'\E[31mNo modules defined in \E[1m'${ztarget}$'\E[0m'
return 1 return 1
fi fi
# Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes # Remove all from _zfpaths, _zfunctions and _zcmds with disabled root dirs prefixes
local zroot_dir zpre local zroot_dir zpre
for zroot_dir in ${_zdisabled_root_dirs}; do for zroot_dir in ${_zdisabled_root_dirs}; do
zpre=${zroot_dir}$'\0' zpre=${zroot_dir}$'\0'
_zfpaths=(${_zfpaths:#${zpre}*}) _zfpaths=(${_zfpaths:#${zpre}*})
_zfunctions=(${_zfunctions:#${zpre}*}) _zfunctions=(${_zfunctions:#${zpre}*})
_zcmds=(${_zcmds:#${zpre}*}) _zcmds=(${_zcmds:#${zpre}*})
done done
} always {
unfunction zmodule
}
} }
_zimfw_list_unuseds() { _zimfw_list_unuseds() {
@ -454,7 +462,7 @@ _zimfw_compile() {
} }
_zimfw_info() { _zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2024-02-17 02:05:06 UTC, previous commit is 9de3984)' print -R 'zimfw version: '${_zversion}' (built at 2024-06-17 12:21:22 UTC, previous commit is 76164d6)'
local zparam local zparam
for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do for zparam in LANG ${(Mk)parameters:#LC_*} OSTYPE TERM TERM_PROGRAM TERM_PROGRAM_VERSION ZIM_HOME ZSH_VERSION; do
print -R ${(r.22....:.)zparam}${(P)zparam} print -R ${(r.22....:.)zparam}${(P)zparam}
@ -474,7 +482,7 @@ _zimfw_uninstall() {
} }
_zimfw_upgrade() { _zimfw_upgrade() {
local -r ztarget=${ZIM_HOME}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz local -r ztarget=${__ZIMFW_PATH}/zimfw.zsh zurl=https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh.gz
{ {
if (( ${+commands[curl]} )); then if (( ${+commands[curl]} )); then
command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1 command curl -fsSL -o ${ztarget}.new.gz ${zurl} || return 1
@ -578,7 +586,7 @@ _zimfw_download_tarball() {
readonly REPO=${match[4]%.git} readonly REPO=${match[4]%.git}
fi fi
if [[ ${HOST} != github.com || -z ${REPO} ]]; then 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 return 1
fi fi
readonly HEADERS_TARGET=${DIR}/${TEMP}_headers readonly HEADERS_TARGET=${DIR}/${TEMP}_headers
@ -586,7 +594,7 @@ _zimfw_download_tarball() {
if [[ -r ${INFO_TARGET} ]]; then if [[ -r ${INFO_TARGET} ]]; then
readonly INFO=("${(@f)"$(<${INFO_TARGET})"}") readonly INFO=("${(@f)"$(<${INFO_TARGET})"}")
if [[ ${URL} != ${INFO[1]} ]]; then 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 return 1
fi fi
# Previous REV is in line 2, reserved for future use. # Previous REV is in line 2, reserved for future use.
@ -645,10 +653,17 @@ _zimfw_download_tarball() {
} }
_zimfw_untar_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} _zimfw_print_error "Error extracting ${TARBALL_TARGET}" ${ERR}
return 1 return 1
fi 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() { _zimfw_tool_degit() {
@ -731,7 +746,7 @@ _zimfw_tool_git() {
return 0 return 0
fi fi
if [[ ${URL} != $(command git -C ${DIR} config --get remote.origin.url) ]]; then 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 return 1
fi fi
if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then if ! ERR=$(command git -C ${DIR} fetch -pqt origin 2>&1); then
@ -874,7 +889,7 @@ _zimfw_run_tool_action() {
zimfw() { zimfw() {
builtin emulate -L zsh -o EXTENDED_GLOB builtin emulate -L zsh -o EXTENDED_GLOB
local -r _zversion='1.13.0' _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.14.0-SNAPSHOT' _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: Actions:
\E[1mbuild\E[0m Build \E[1m'${ZIM_HOME}$'/init.zsh\E[0m and \E[1m'${ZIM_HOME}$'/login_init.zsh\E[0m. \E[1mbuild\E[0m Build \E[1m'${ZIM_HOME}$'/init.zsh\E[0m and \E[1m'${ZIM_HOME}$'/login_init.zsh\E[0m.
@ -978,8 +993,4 @@ Options:
esac esac
} }
if [[ ${functrace[1]} == zmodule:* ]]; then zimfw "${@}"
zmodule "${@}"
else
zimfw "${@}"
fi