From 7a14b6808c5a9fbf7fa4eb1de0b1230d71e3ef56 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Mon, 8 Feb 2021 09:39:23 -0500 Subject: [PATCH] Cleanup code --- README.md | 2 +- zpe.zsh => zpe.sh | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) rename zpe.zsh => zpe.sh (78%) diff --git a/README.md b/README.md index 8f7378d..277acaf 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A utility to ease the management of Zsh plugins. This is NOT a complete Zsh plug 1. Source the script in your `zshrc` 2. Add a list of the plugin repositories in `~/.config/zpe/repositories`. Use the full URL, either SSH or HTTP, comments can be added with a #. 3. Run `zpe-clone` to pull the repositories - 4. Source the plugin in your zshrc using the `zpe-source` command. For each plugin, locate the source-able file (usually contains the word init, or has the .plugin.zsh extension). Add it to your zshrc using the following syntax: `zpe-source /`. Make sure that this goes after sourcing the `zpe.zsh` script. + 4. Source the plugin in your zshrc using the `zpe-source` command. For each plugin, locate the source-able file (usually contains the word init, or has the .plugin.zsh extension). Add it to your zshrc using the following syntax: `zpe-source /`. Make sure that this goes after sourcing the `zpe.sh` script. ### Extra commands * `zpe-pull` updates the repositories diff --git a/zpe.zsh b/zpe.sh similarity index 78% rename from zpe.zsh rename to zpe.sh index a3a25a3..dc8cd00 100755 --- a/zpe.zsh +++ b/zpe.sh @@ -1,11 +1,12 @@ -#!/usr/bin/env zsh -# The ZPE Zsh plugin helper. Copyright 2020 Armaan Bhojwani, MIT License +#!/usr/bin/env bash +# ZPE Zsh plugin helper +# Copyright 2021 Armaan Bhojwani, MIT License # Set defaults zpe_config_dir="${HOME}/.config/zpe/" zpe_plugin_dir="${zpe_config_dir}/plugins/" zpe_tmp_dir="/tmp/zpe/" -zpe_log_dir="/tmp/zpe/logs" +zpe_log_dir="${zpe_tmp_dir}/logs" zpe-meta-pre() { # Create necesary directories, check dependencies @@ -20,7 +21,8 @@ zpe-meta-pre() { zpe-clone() { # Clone all the repos in the config file recursively into the plugin directory zpe-meta-pre - cat ${zpe_config_dir}repositories | xargs -P10 -I{} git -C ${zpe_plugin_dir} clone {} -q --depth 1 &> "${zpe_log_dir}"/$(date -Iseconds) + cat ${zpe_config_dir}repositories | xargs -P10 -I{} git -C ${zpe_plugin_dir} \ + clone {} -q --depth 1 &> "${zpe_log_dir}"/$(date -Iseconds) echo "All plugins are downloaded" } @@ -29,15 +31,18 @@ zpe-pull() { zpe-meta-pre local find_dirs=$(find "${zpe_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={} --work-tree={} pull &> "${zpe_log_dir}"/$(date -Iseconds) + echo $find_dirs | xargs -P10 -I {} git --git-dir={} --work-tree={} pull &> \ + "${zpe_log_dir}"/$(date -Iseconds) echo "All plugins are up to date" } zpe-clean() { # Remove cloned plugins not specified in the config file zpe-meta-pre - find ${zpe_plugin_dir} -maxdepth 1 -type d -exec git -C {} config --get remote.origin.url \; > "${zpe_tmp_dir}"installed-urls - comm -23 <(sort ${zpe_tmp_dir}installed-urls) <(sort "${zpe_config_dir}"repositories) > "${zpe_tmp_dir}"/diff + find ${zpe_plugin_dir} -maxdepth 1 -type d -exec git -C {} \ + config --get remote.origin.url \; > "${zpe_tmp_dir}"installed-urls + comm -23 <(sort ${zpe_tmp_dir}installed-urls) \ + <(sort "${zpe_config_dir}"repositories) > "${zpe_tmp_dir}"/diff echo -n "" > "${zpe_tmp_dir}"deletable while read line; do @@ -57,7 +62,7 @@ zpe-clean() { done < ${zpe_tmp_dir}deletable echo "Cleaned!" ;; - *|$'\n') + *) echo "Aborted" esac else -- 2.39.2