Open DrgnFireYellow opened 1 year ago
If you're willing to include some arcane black magic, you can support Oh My Zsh by using split/join syntax and then passing the repo as ohmyzsh/ohmyzsh/path/to/plugin/dir
. For example:
$ # Here's how split/join would work to pull out the user/repo part:
$ plugin="ohmyzsh/ohmyzsh/plugins/extract"
$ repo="${(@j:/:)${(@s:/:)plugin}[1,2]}"
$ echo $repo
ohmyzsh/ohmyzsh
So with just a bit of that magic, and with a couple extra flourishes to support updating plugins and also fixing a bug that causes double loading plugins, your micro-plugin manager becomes:
function zlugin_reload() {
# Initializes downloaded plugins
local -a inits=(${ZDOTDIR:-~}/.zlugin/$1/*.{plugin.zsh,zsh-theme,zsh,sh}(N))
(( $#inits )) && source $inits[1]
}
function zlugin() {
# Downloads a plugin and reloads
# Syntax: zlugin [string: github repository of a plugin]
local repo="${(@j:/:)${(@s:/:)1}[1,2]}"
[[ -d ${ZDOTDIR:-~}/.zlugin/$repo ]] ||
git clone "https://github.com/$repo.git" ${ZDOTDIR:-~}/.zlugin/$repo &>> ${ZDOTDIR:-~}/zlugin.log
zlugin_reload $1
}
function update_zlugin() {
# Updates to the latest version of zlugin
# NOTE: The update will not take effect until you restart your shell
echo "Updating repos"
local repo; for repo in ${ZDOTDIR:-~}/.zlugin/*(/); echo "Updating $repo" && git -C $repo pull
echo "Updating zlugin"
curl -s https://raw.githubusercontent.com/DrgnFireYellow/zlugin/main/zlugin.zsh > ${ZDOTDIR:-~}/.zlugin/zlugin.zsh
echo "Update complete!"
}
I tested with this .zshrc, and it's pretty solid:
# sub-plugins supported
zlugin belak/zsh-utils/history
zlugin belak/zsh-utils/completion
zlugin belak/zsh-utils/utility
zlugin ohmyzsh/ohmyzsh/plugins/extract
zlugin ohmyzsh/ohmyzsh/plugins/magic-enter
# *.sh bash plugins supported
zlugin rupa/z
# zsh-themes supported
zlugin dracula/zsh
# zlugin sindresorhus/pure
# double-load bug is fixed
zlugin zsh-users/zsh-syntax-highlighting
zlugin zsh-users/zsh-autosuggestions
zlugin zsh-users/zsh-history-substring-search
I went on this journey once and it was a ton of fun. Nice project.
I believe that a good Quality of Life improvement to zlugin would be to allow the user to use oh my zsh underneath zlugin. The command used for this would be
zlugin_omz
.