diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index daff3eac..218ab4bc 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -9,6 +9,16 @@ # Changelog All notable changes to this project will be documented in this file. +* 26-11-2021 + - zinit packages can now be installed from local files or custom repositories. +zinit uses [zhdarma-continuum/zinit-packages](https://github.com/p/zdharma-continuum/zinit-packages) +by default. To use a custom repo you can set `ZINIT[PACKAGES_REPO]=github_org/repo`. +To install from a specific branch: `ZINIT[PACKAGES_BRANCH]=feature-branch`. For +repos that are not hosted on GitHub, you can instruct zinit to install packages +from the local filesystem like so: +`zinit pack"profile" for local/path/to/package.json` (the user needs to be set +to `local` and the path to `package.json` must be absolute) + * 22-11-2021 - We updated zinit's main branch from `master` to `main`. `zinit self-update` will try to update the branch locally. If it fails please try to: diff --git a/zinit-install.zsh b/zinit-install.zsh index d74b58c6..4cdc0add 100644 --- a/zinit-install.zsh +++ b/zinit-install.zsh @@ -123,8 +123,8 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || { builtin print -P "${ZINIT local user=$1 pkg=$2 plugin=$2 id_as=$3 dir=$4 profile=$5 \ local_path=${ZINIT[PLUGINS_DIR]}/${3//\//---} pkgjson \ - tmpfile=${$(mktemp):-${TMPDIR:-/tmp}/zsh.xYzAbc123} \ - URL=https://raw.githubusercontent.com/zdharma-continuum/zinit-packages/HEAD/$2/package.json + tmpfile=${$(mktemp):-${TMPDIR:-/tmp}/zsh.xYzAbc123} + local URL=https://raw.githubusercontent.com/${ZINIT[PACKAGES_REPO]}/${ZINIT[PACKAGES_BRANCH]}/${pkg}/package.json local pro_sep="{rst}, {profile}" epro_sep="{error}, {profile}" \ tool_sep="{rst}, {cmd}" \ @@ -133,16 +133,27 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || { builtin print -P "${ZINIT trap "rmdir ${(qqq)local_path} 2>/dev/null; return 1" INT TERM QUIT HUP trap "rmdir ${(qqq)local_path} 2>/dev/null" EXIT - if [[ $profile != ./* ]] { - if { ! .zinit-download-file-stdout $URL 0 1 2>/dev/null > $tmpfile } { - rm -f $tmpfile; .zinit-download-file-stdout $URL 1 1 2>/dev/null >1 $tmpfile + local localpkg + if [[ "$user" == "local" ]] && [[ "$pkg" =~ /package.json$ ]]; then + localpkg=1 + local pkgfile="/${pkg}" # re-add stripped / + [[ ! -r "$pkgfile" ]] && { + +zinit-message "{u-warn}Error{b-warn}:{error} file does not exist: {apo}\`{pid}$pkgfile{apo}\`{rst}" + return 1 + } + pkgjson="$(<${pkgfile})" + else + if [[ $profile != ./* ]] { + if { ! .zinit-download-file-stdout $URL 0 1 2>/dev/null > $tmpfile } { + rm -f $tmpfile; .zinit-download-file-stdout $URL 1 1 2>/dev/null >1 $tmpfile + } + } else { + tmpfile=${profile%:*} + profile=${${${(M)profile:#*:*}:+${profile#*:}}:-default} } - } else { - tmpfile=${profile%:*} - profile=${${${(M)profile:#*:*}:+${profile#*:}}:-default} - } - pkgjson="$(<$tmpfile)" + pkgjson="$(<$tmpfile)" + fi if [[ -z $pkgjson ]]; then +zinit-message "{u-warn}Error{b-warn}:{error} the package {apo}\`{pid}$id_as{apo}\`"\ @@ -180,6 +191,18 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || { builtin print -P "${ZINIT map=( "\"" "\\\"" "\\" "\\" ) eval "ICE[id-as]=\"${ICE[id-as]//(#m)[\"\\]/${map[$MATCH]}}\"" } + # DIRTYFIX the id-as ice is pretty much required for local packages + # without most snippets won't work as expected as their files end up being + # saved as "package.json" and then ziextract etc will fail to detect these + # NOTE that the id-as also dictates who the downloaded snippet file will + # be named + if [[ -n "$localpkg" ]] && [[ -z "${ICE[id-as]}" ]] { + # First we'll try using the name field of the package.json + # If that fails we default to: + # zinit-pack---local---path---to---plugin---dir + local pkgname=$(jq -r '.name // ""' <<< "$pkgjson" 2>/dev/null) + ICE[id-as]=${pkgname:-zinit-pack---local---${${pkg%%/package.json}//\//---}} + } } else { # Założenie: profil domyślny jest pierwszy w tablicy (patrz: inny kolor). +zinit-message "{u-warn}Error{b-warn}:{error} the profile {apo}\`{hi}$profile{apo}\`" \ diff --git a/zinit.zsh b/zinit.zsh index 0e2fe995..5c958f32 100644 --- a/zinit.zsh +++ b/zinit.zsh @@ -72,11 +72,13 @@ aliases|countdown|light-mode|is-snippet|git|verbose|cloneopts|\ pullopts|debug|null|binary|make|nocompile|notify|reset" # Can be customized. -: ${ZINIT[MODULE_DIR]:=${ZINIT[HOME_DIR]}/module} -: ${ZINIT[PLUGINS_DIR]:=${ZINIT[HOME_DIR]}/plugins} : ${ZINIT[COMPLETIONS_DIR]:=${ZINIT[HOME_DIR]}/completions} -: ${ZINIT[SNIPPETS_DIR]:=${ZINIT[HOME_DIR]}/snippets} +: ${ZINIT[MODULE_DIR]:=${ZINIT[HOME_DIR]}/module} +: ${ZINIT[PACKAGES_REPO]:=zdharma-continuum/zinit-packages} +: ${ZINIT[PACKAGES_BRANCH]:=HEAD} +: ${ZINIT[PLUGINS_DIR]:=${ZINIT[HOME_DIR]}/plugins} : ${ZINIT[SERVICES_DIR]:=${ZINIT[HOME_DIR]}/services} +: ${ZINIT[SNIPPETS_DIR]:=${ZINIT[HOME_DIR]}/snippets} typeset -g ZPFX : ${ZPFX:=${ZINIT[HOME_DIR]}/polaris} : ${ZINIT[ALIASES_OPT]::=${${options[aliases]:#off}:+1}}