Skip to content

Commit

Permalink
implement some plugin manager standards
Browse files Browse the repository at this point in the history
  • Loading branch information
mpostaire committed Dec 9, 2022
1 parent 4081344 commit 462f0b7
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions ztupide.zsh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env zsh

# credit: https://github.com/mattmc3/zsh_unplugged
# credits: https://github.com/mattmc3/zsh_unplugged, https://github.com/agkozak/zcomet

_ztupide_zcompile() {
local f
for f in ${1}/**/*.zsh{,-theme}(N); do
[[ ! "${f}".zwc -nt "${f}" && -r "${f}" && -w "${f:h}" ]] && zcompile $f
[[ ! "${f}".zwc -nt "${f}" && -r "${f}" && -w "${f:h}" ]] && builtin zcompile $f
done
}

Expand All @@ -27,22 +27,41 @@ _ztupide_load() {
ln -sf "${initfiles[1]}" "${initfile}"
fi

fpath+=${plugdir}
if [[ -d ${plugdir}/functions ]]; then
fpath+=${plugdir}/functions
else
fpath+=${plugdir}
fi
if [[ -d ${plugdir}/bin ]]; then
path+=${plugdir}/bin
fi
zsh_loaded_plugins+=(${repo})

if (( ${1} && $+functions[zsh-defer] )); then
zsh-defer . ${initfile}
zsh-defer -c "ZERO=${initfile} . ${initfile}"
if [[ "${3}" != 0 ]]; then
local cb
for cb in ${@:3}; do zsh-defer -c "${cb}"; done
fi
else
. ${initfile}
ZERO=${initfile} . ${initfile}
if [[ "${3}" != 0 ]]; then
local cb
for cb in ${@:3}; do eval "${cb}"; done
fi
fi
}

_ztupide_cleanup_plugin() {
(( ${+functions[${1}_plugin_unload]} )) && ${1}_plugin_unload

# remove plugin from loaded plugins, fpath and path
zsh_loaded_plugins=("${zsh_loaded_plugins[@]:#*${1}}")
fpath=("${fpath[@]:#${ZTUPIDE_PLUGIN_PATH}/${1}}")
fpath=("${fpath[@]:#${ZTUPIDE_PLUGIN_PATH}/${1}/functions}")
path=("${path[@]:#${ZTUPIDE_PLUGIN_PATH}/${1}/bin}")
}

_ztupide_unload() {
[ -z "${1}" ] && print "plugin unload error: none specified" && return 1

Expand All @@ -55,11 +74,13 @@ _ztupide_unload() {
fi

if [ -d "${plugin_path}"/.git ]; then
_ztupide_cleanup_plugin "${plugin_name}"
rm -rf "${plugin_path}"
print "plugin ${plugin_name} removed"
else
read "ans?${plugin_name} is a local plugin. Do you want to unload it (y/N)? "
if [[ "${ans}" =~ ^[Yy]$ ]]; then
_ztupide_cleanup_plugin "${plugin_name}"
rm -rf "${plugin_path}"
print "plugin ${plugin_name} removed"
fi
Expand Down Expand Up @@ -105,16 +126,21 @@ _ztupide_autoupdate() {
}

_ztupide_init() {
_ztupide_path=${1:a}
typeset -g _ztupide_path=${1:a}
# https://github.com/agkozak/Zsh-100-Commits-Club/blob/master/Zsh-Plugin-Standard.adoc#9-global-parameter-holding-the-plugin-managers-capabilities
typeset -g PMSPEC=0fbuiPs
typeset -g _ztupide_loaded_theme
typeset -gUa zsh_loaded_plugins

ZTUPIDE_PLUGIN_PATH=${ZTUPIDE_PLUGIN_PATH:-${ZDOTDIR:-$HOME/.zsh}/plugins}
ZTUPIDE_DISABLE_ASYNC=${ZTUPIDE_DISABLE_ASYNC:-1}
typeset -g ZTUPIDE_PLUGIN_PATH=${ZTUPIDE_PLUGIN_PATH:-${ZDOTDIR:-$HOME/.zsh}/plugins}
typeset -g ZTUPIDE_DISABLE_ASYNC=${ZTUPIDE_DISABLE_ASYNC:-1}

# use zsh-defer if ZTUPIDE_DISABLE_ASYNC is 1 to enable '--async' option with the 'ztupide load' command
if (( ${ZTUPIDE_DISABLE_ASYNC} )); then
_ztupide_load 0 romkatv/zsh-defer
fi
(( ${ZTUPIDE_DISABLE_ASYNC} )) && _ztupide_load 0 romkatv/zsh-defer

typeset -g ZPFX
: ${ZPFX:=${_ztupide_path:h}/polaris}
[[ ! -d ${ZPFX} ]] && mkdir -p ${ZPFX}

# zcompile this file if it has changed (this ensures that ztupide.zsh is compiled on its first load)
_ztupide_zcompile ${_ztupide_path:h}
Expand Down

0 comments on commit 462f0b7

Please sign in to comment.