-
Notifications
You must be signed in to change notification settings - Fork 14
/
zsh_unplugged.plugin.zsh
35 lines (33 loc) 路 1.27 KB
/
zsh_unplugged.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# zunplugged: https://github.com/mattmc3/zsh_unplugged
# a simple, ultra-fast plugin handler
# clone a plugin, identify its init file, source it (with zsh-defer if available)
# and add it to your fpath
function plugin-load() {
local repo plugin_name plugin_dir initfile initfiles
ZPLUGINDIR=${ZPLUGINDIR:-${ZDOTDIR:-$HOME/.config/zsh}/plugins}
for repo in $@; do
plugin_name=${repo:t}
plugin_dir=$ZPLUGINDIR/$plugin_name
initfile=$plugin_dir/$plugin_name.plugin.zsh
if [[ ! -d $plugin_dir ]]; then
echo "Cloning $repo"
git clone -q --depth 1 --recursive --shallow-submodules https://github.com/$repo $plugin_dir
fi
if [[ ! -e $initfile ]]; then
initfiles=($plugin_dir/*.plugin.{z,}sh(N) $plugin_dir/*.{z,}sh{-theme,}(N))
[[ ${#initfiles[@]} -gt 0 ]] || { echo >&2 "Plugin has no init file '$repo'." && continue }
ln -s "${initfiles[1]}" "$initfile"
fi
fpath+=$plugin_dir
(( $+functions[zsh-defer] )) && zsh-defer . $initfile || . $initfile
done
}
# if you want to compile your plugins you may see performance gains
function plugin-compile() {
ZPLUGINDIR=${ZPLUGINDIR:-${ZDOTDIR:-$HOME/.config/zsh}/plugins}
autoload -U zrecompile
local f
for f in $ZPLUGINDIR/**/*.zsh{,-theme}(N); do
zrecompile -pq "$f"
done
}