From c7e9ad402a7d41735bc89f7e41e6406c63cbad8f Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me> Date: Fri, 13 Nov 2020 11:06:43 -0500 Subject: [PATCH] add zpe-clean, zpe-source This is actually in a decently usable state now! It could definitely be made more efficient, and it does need some more work, but all of the core functionality is working at this point --- README.md | 6 +++--- zpe.zsh | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index da0195a..b783580 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # 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 /`. 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 diff --git a/zpe.zsh b/zpe.zsh index 7fad5ba..b6c9cad 100755 --- a/zpe.zsh +++ b/zpe.zsh @@ -1,33 +1,50 @@ #!/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 +} -- 2.39.2