]> git.armaanb.net Git - zpe.git/commitdiff
add zpe-clean, zpe-source
authorArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Fri, 13 Nov 2020 16:06:43 +0000 (11:06 -0500)
committerArmaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me>
Fri, 13 Nov 2020 16:06:43 +0000 (11:06 -0500)
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
zpe.zsh

index da0195a7aee04bb332ddc3848e1979a0f12c7619..b78358068e9bc9dee2a0da25627a9c7acbdc91e6 100644 (file)
--- 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 <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  
diff --git a/zpe.zsh b/zpe.zsh
index 7fad5bafabb2d0edefae98b7e5c6c763f48e3d3c..b6c9cadc45b6cf0d7ccbe9674b866a8bb5ca3305 100755 (executable)
--- 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
+}