From 69ab64f6d8f5e214165172ac55592e5f9d01cb8d Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Thu, 13 Jun 2024 17:41:14 +0000 Subject: [PATCH] use zgen as a submodule --- .gitmodules | 3 + lib/zgen | 1 + lib/zgen/LICENSE | 23 ---- lib/zgen/README.md | 74 ------------- lib/zgen/_zgen | 30 ------ lib/zgen/zgen.zsh | 256 --------------------------------------------- 6 files changed, 4 insertions(+), 383 deletions(-) create mode 160000 lib/zgen delete mode 100644 lib/zgen/LICENSE delete mode 100644 lib/zgen/README.md delete mode 100644 lib/zgen/_zgen delete mode 100755 lib/zgen/zgen.zsh diff --git a/.gitmodules b/.gitmodules index f420b36..f20dc5b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -58,3 +58,6 @@ [submodule "dot-files/zsh_custom/plugins/zsh-completions"] path = dot-files/zsh_custom/plugins/zsh-completions url = https://github.com/zsh-users/zsh-completions +[submodule "lib/zgen"] + path = lib/zgen + url = https://github.com/tarjoilija/zgen diff --git a/lib/zgen b/lib/zgen new file mode 160000 index 0000000..0b669d2 --- /dev/null +++ b/lib/zgen @@ -0,0 +1 @@ +Subproject commit 0b669d2d0dcf788b4c81a7a30b4fa41dfbf7d1a7 diff --git a/lib/zgen/LICENSE b/lib/zgen/LICENSE deleted file mode 100644 index 343ea7a..0000000 --- a/lib/zgen/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) 2014, Eero-Antero Säisä -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/zgen/README.md b/lib/zgen/README.md deleted file mode 100644 index c14c1e7..0000000 --- a/lib/zgen/README.md +++ /dev/null @@ -1,74 +0,0 @@ -## zgen - -A lightweight plugin manager for ZSH inspired by Antigen. Our goal is to have a minimal overhead when starting up the shell because nobody likes waiting. The script generates a static init.zsh file which does nothing but sources your plugins and appends them to fpath. The downside is that you have to update your plugins manually. - -My current zgen setup takes 208ms to load where Antigen takes 1324ms with the same plugins. - -### Usage - -#### Load oh-my-zsh base - zgen oh-my-zsh - -#### Load oh-my-zsh plugins - zgen oh-my-zsh -This is a shortcut for `zgen load`. - -#### Load plugins and completions - zgen load [location] [branch] -Similar to `antigen bundle`. It tries to source any scripts from `location`. If none found, it adds `location` to `$fpath`. - -- `repo` - - github 'user/repository' or path to a local repository -- `location` - - relative path to a script/folder - - useful for repositories that don't have proper plugin support like `zsh-users/zsh-completions` -- `branch` - - for those who don't use the master branch - -#### Save all loaded scripts into an init script - zgen save -We do this so they'll get run each time you source zgen. - -#### Check for an init script - zgen saved -Returns 0 if an init script exists. - -#### Update zgen framework - zgen selfupdate - -#### Update all repositories and remove the init script - zgen update - -### Example .zshrc - -```zsh -# load zgen -source "${HOME}/proj/zgen/zgen.zsh" - -# check if there's no init script -if ! zgen saved; then - echo "Creating a zgen save" - - zgen oh-my-zsh - - # plugins - zgen oh-my-zsh plugins/git - zgen oh-my-zsh plugins/sudo - zgen oh-my-zsh plugins/command-not-found - zgen load zsh-users/zsh-syntax-highlighting - zgen load /path/to/super-secret-private-plugin - - # completions - zgen load zsh-users/zsh-completions src - - # theme - zgen oh-my-zsh themes/arrow - - # save all to init script - zgen save -fi -``` - -## Other resources - -The [awesome-zsh-plugins](https://github.com/unixorn/awesome-zsh-plugins) list contains many zgen-compatible zsh plugins & themes that you may find useful. diff --git a/lib/zgen/_zgen b/lib/zgen/_zgen deleted file mode 100644 index 2ca4412..0000000 --- a/lib/zgen/_zgen +++ /dev/null @@ -1,30 +0,0 @@ -#compdef zgen -# ------------------------------------------------------------------------------ -# Description -# ----------- -# -# Completion script for Zgen (https://github.com/tarjoilija/zgen) -# -# ------------------------------------------------------------------------------ -# Authors -# ------- -# -# * Martin Zeman (https://github.com/N4M3Z) -# -# ------------------------------------------------------------------------------ - -local -a _zgen_commands -_zgen_commands=( - "clone:clone plugin from repository" - "completions:deprecated, please use load instead" - "list:print init.zsh" - "load:clone and load plugin" - "oh-my-zsh:load oh-my-zsh base" - "reset:delete the init.zsh script" - "save:check for init.zsh script" - "selfupdate:update zgen framework from repository" - "update:update all repositories and remove the init script" -) - -_describe -t commands "zgen subcommand" _zgen_commands -return 0 diff --git a/lib/zgen/zgen.zsh b/lib/zgen/zgen.zsh deleted file mode 100755 index 2e5b574..0000000 --- a/lib/zgen/zgen.zsh +++ /dev/null @@ -1,256 +0,0 @@ -#!/bin/zsh -local ZGEN_SOURCE="$(cd "$(dirname "${0}")" && pwd -P)" - - -if [[ -z "${ZGEN_DIR}" ]]; then - ZGEN_DIR="${HOME}/.zgen" -fi - -if [[ -z "${ZGEN_INIT}" ]]; then - ZGEN_INIT="${ZGEN_DIR}/init.zsh" -fi - -if [[ -z "${ZGEN_LOADED}" ]]; then - ZGEN_LOADED=() -fi - -if [[ -z "${ZGEN_COMPLETIONS}" ]]; then - ZGEN_COMPLETIONS=() -fi - --zgen-encode-url () { - # Remove characters from a url that don't work well in a filename. - # Inspired by -anti-get-clone-dir() method from antigen. - echo "$1" | sed \ - -e 's./.-SLASH-.g' \ - -e 's.:.-COLON-.g' \ - -e 's.|.-PIPE-.g' -} - --zgen-get-clone-dir() { - local repo="${1}" - local branch="${2:-master}" - - if [[ -d "${repo}/.git" ]]; then - echo "${ZGEN_DIR}/local/$(basename ${repo})-${branch}" - else - # Repo directory will be location/reponame - local reponame="$(basename ${repo})" - # Need to encode incase it is a full url with characters that don't - # work well in a filename. - local location="$(-zgen-encode-url $(dirname ${repo}))" - repo="${location}/${reponame}" - echo "${ZGEN_DIR}/${repo}-${branch}" - fi -} - --zgen-get-clone-url() { - local repo="${1}" - - if [[ -d "${repo}/.git" ]]; then - echo "${repo}" - else - # Sourced from antigen url resolution logic. - # https://github.com/zsh-users/antigen/blob/master/antigen.zsh - # Expand short github url syntax: `username/reponame`. - if [[ $repo != git://* && - $repo != https://* && - $repo != http://* && - $repo != ssh://* && - $repo != git@github.com:*/* - ]]; then - repo="https://github.com/${repo%.git}.git" - fi - echo "${repo}" - fi -} - -zgen-clone() { - local repo="${1}" - local branch="${2:-master}" - local url="$(-zgen-get-clone-url ${repo})" - local dir="$(-zgen-get-clone-dir ${repo} ${branch})" - - if [[ ! -d "${dir}" ]]; then - mkdir -p "${dir}" - git clone --recursive -b "${branch}" "${url}" "${dir}" - fi -} - --zgen-add-to-fpath() { - local completion_path="${1}" - - # Add the directory to ZGEN_COMPLETIONS array if not present - if [[ ! "${ZGEN_COMPLETIONS[@]}" =~ ${completion_path} ]]; then - ZGEN_COMPLETIONS+=("${completion_path}") - fi -} - --zgen-source() { - local file="${1}" - - source "${file}" - - # Add to ZGEN_LOADED array if not present - if [[ ! "${ZGEN_LOADED[@]}" =~ "${file}" ]]; then - ZGEN_LOADED+=("${file}") - fi - - completion_path="$(dirname ${file})" - - -zgen-add-to-fpath "${completion_path}" -} - -zgen-init() { - if [[ -f "${ZGEN_INIT}" ]]; then - source "${ZGEN_INIT}" - fi -} - -zgen-reset() { - echo "zgen: Deleting ${ZGEN_INIT}" - if [[ -f "${ZGEN_INIT}" ]]; then - rm "${ZGEN_INIT}" - fi -} - -zgen-update() { - for repo in "${ZGEN_DIR}"/*/*; do - echo "Updating ${repo}" - (cd "${repo}" \ - && git pull \ - && git submodule update --recursive) - done - zgen-reset -} - -zgen-save() { - echo "zgen: Creating ${ZGEN_INIT}" - - echo "#" >! "${ZGEN_INIT}" - echo "# Generated by zgen." >> "${ZGEN_INIT}" - echo "# This file will be overwritten the next time you run zgen save" >> "${ZGEN_INIT}" - echo "#" >> "${ZGEN_INIT}" - for file in "${ZGEN_LOADED[@]}"; do - echo "source \"${(q)file}\"" >> "${ZGEN_INIT}" - done - - # Set up fpath - echo >> "${ZGEN_INIT}" - echo "#" >> "${ZGEN_INIT}" - echo "# Add our plugins and completions to fpath">> "${ZGEN_INIT}" - echo "#" >> "${ZGEN_INIT}" - echo "fpath=(${(q)ZGEN_COMPLETIONS[@]} \${fpath})" >> "${ZGEN_INIT}" - - echo "zgen: Creating ${ZGEN_DIR}/zcompdump" - compinit -d "${ZGEN_DIR}/zcompdump" -} - -zgen-completions() { - echo "zgen: 'completions' is deprecated, please use 'load' instead" - - zgen-load "${@}" -} - -zgen-load() { - local repo="${1}" - local file="${2}" - local branch="${3:-master}" - local dir="$(-zgen-get-clone-dir ${repo} ${branch})" - local location="${dir}/${file}" - - # clone repo if not present - if [[ ! -d "${dir}" ]]; then - zgen-clone "${repo}" "${branch}" - fi - - # source the file - if [[ -f "${location}" ]]; then - -zgen-source "${location}" - - # Prezto modules have init.zsh files - elif [[ -f "${location}/init.zsh" ]]; then - -zgen-source "${location}/init.zsh" - - elif [[ -f "${location}.zsh-theme" ]]; then - -zgen-source "${location}.zsh-theme" - - elif [[ -f "${location}.theme.zsh" ]]; then - -zgen-source "${location}.theme.zsh" - - elif [[ -f "${location}.zshplugin" ]]; then - -zgen-source "${location}.zshplugin" - - elif [[ -f "${location}.zsh.plugin" ]]; then - -zgen-source "${location}.zsh.plugin" - - # Classic oh-my-zsh plugins have foo.plugin.zsh - elif ls "${location}" | grep -l "\.plugin\.zsh" &> /dev/null; then - for script (${location}/*\.plugin\.zsh(N)) -zgen-source "${script}" - - elif ls "${location}" | grep -l "\.zsh" &> /dev/null; then - for script (${location}/*\.zsh(N)) -zgen-source "${script}" - - elif ls "${location}" | grep -l "\.sh" &> /dev/null; then - for script (${location}/*\.sh(N)) -zgen-source "${script}" - - # Completions - elif [[ -d "${location}" ]]; then - -zgen-add-to-fpath "${location}" - - else - echo "zgen: Failed to load ${dir}" - fi -} - -zgen-saved() { - [[ -f "${ZGEN_INIT}" ]] && return 0 || return 1 -} - -zgen-list() { - if [[ -f "${ZGEN_INIT}" ]]; then - cat "${ZGEN_INIT}" - else - echo "Zgen init.zsh missing, please use zgen save and then restart your shell." - fi -} - -zgen-selfupdate() { - if [[ -e "${ZGEN_SOURCE}/.git" ]]; then - (cd "${ZGEN_SOURCE}" \ - && git pull) - else - echo "zgen is not running from a git repository, so it is not possible to selfupdate" - return 1 - fi -} - -zgen-oh-my-zsh() { - local repo="robbyrussell/oh-my-zsh" - local file="${1:-oh-my-zsh.sh}" - - zgen-load "${repo}" "${file}" -} - -zgen() { - local cmd="${1}" - if [[ -z "${cmd}" ]]; then - echo "usage: zgen [clone|completions|list|load|oh-my-zsh|reset|save|selfupdate|update]" - return 1 - fi - - shift - - if functions "zgen-${cmd}" > /dev/null ; then - "zgen-${cmd}" "${@}" - else - echo "zgen: command not found: ${cmd}" - fi -} - -ZSH="$(-zgen-get-clone-dir robbyrussell/oh-my-zsh master)" -zgen-init -fpath=($ZGEN_SOURCE $fpath) - -autoload -U compinit -compinit -d "${ZGEN_DIR}/zcompdump"