# zpe
-A darn stupid zsh plugin manager
+A utility to ease the management of zsh plugins. This is NOT a complete zsh plugin manager, I reccomend [znap](https://github.com/marlonrichert/zsh-snap/) if you are looking for one. This script just takes the edge off of manually managing them, if you don't want to deal with one of the full-fledged plugin managers.
## Usage
-Just put a list of git repos (full url, either ssh or http) in `~/.config/zpe/repositories`, and then
+Just put a list of git repos (full url, either ssh or http) in `~/.config/zpe/repositories`, and then put `source /path/to/zpe.zsh` in your zshrc. Install plugins using `zpe-clone`, update them using `zpe-pull` and remove unused ones using `zpe-clean`. You must manually source the plugins in your zshrc, however this is made easier using the `zpe-source` command. For each plugin, locate the source-able file (usually contains the word init, or has the .plugin.zsh extension) and add it to your zshrc using the following syntax: `zpe-source <plugin name>/<source-able file name>`. Make sure that this goes after sourcing the `zpe.zsh` script.
## Motivation
-All of the other available plugin managers try to get way to fancy. I just need something to automatically clone git repositories and source the files for me. Thats it!
+All of the other available plugin managers try to get way to fancy. I just need something to automatically clone git repositories, and make my system nice and portable. I set myself a code limit of 100 sloc to try and stop feature creep. The script is intentionally very extensible and feature-minimal.
## License
Copyright Armaan Bhojwani
#!/usr/bin/env zsh
-# The ZPE plugin manager. Copyright 2020 Armaan Bhojwani, MIT License
+# The ZPE plugin helper. Copyright 2020 Armaan Bhojwani, MIT License
-zpe-pre() {
- config_dir=$HOME/.config/zpe/
- plugin_dir=$HOME/.config/zpe/plugins/
+config_dir=$HOME/.config/zpe/
+plugin_dir=$HOME/.config/zpe/plugins/
+zpe-meta-pre() {
[[ -d "$config_dir" ]] || mkdir -p "$config_dir"
touch "$config_dir"repositories
[[ -d "$plugin_dir" ]] || mkdir -p "$plugin_dir"
[[ -x git ]] && echo "please install git"
[[ -x find ]] && echo "please install find"
+ [[ -x diff ]] && echo "please install diff"
}
zpe-clone() {
+ zpe-meta-pre
while read line; do
- git -C $plugin_dir clone $line
+ git -C "$plugin_dir" clone $line --depth=1 2> /dev/null
done < "${config_dir}repositories"
+ echo "all plugins are downloaded"
}
zpe-pull() {
- find_dirs=$(find "$plugin_dir" -name ".git" -type d)
+ zpe-meta-pre
+ local find_dirs=$(find "$plugin_dir" -name ".git" -type d)
echo $find_dirs | xargs -P10 -I{} git --git-dir={} config pull.ff only
- echo $find_dirs | xargs -P10 -I{} git --git-dir={} pull
+ echo $find_dirs | xargs -P10 -I{} git --git-dir={} pull > /dev/null
+ echo "all plugins are up to date"
}
-main() {
- zpe-pre
- zpe-clone
- zpe-pull
+zpe-clean() {
+ [[ -d /tmp/zpe ]] || mkdir /tmp/zpe/
+ find $plugin_dir -maxdepth 1 -type d -exec git -C {} config --get remote.origin.url \; > /tmp/zpe/installed-urls
+ comm -23 <(sort /tmp/zpe/installed-urls) <(sort "$config_dir"repositories) >> /tmp/zpe/diff
+
+ for d in "$plugin_dir"*; do
+ while read line; do
+ grep -l $line "$d"/.git/config >> /tmp/zpe/deletable
+ done < /tmp/zpe/diff
+ done
+
+ while read line2; do
+ xargs rm -rf <<< $(echo $line2 | sed 's/\/.git\/config//g')
+ done < /tmp/zpe/deletable
}
-main
+zpe-source() {
+ source "$plugin_dir"/$1
+}