diff options
Diffstat (limited to 'zsh/zscripts/zplug.zsh')
-rwxr-xr-x | zsh/zscripts/zplug.zsh | 83 |
1 files changed, 49 insertions, 34 deletions
diff --git a/zsh/zscripts/zplug.zsh b/zsh/zscripts/zplug.zsh index e1fa3c6..6b86104 100755 --- a/zsh/zscripts/zplug.zsh +++ b/zsh/zscripts/zplug.zsh @@ -1,28 +1,28 @@ #!/usr/bin/env zsh -local zplugs="${ZDOTDIR:-~/.}${ZDOTDIR+/}zplugs" -local zplugins="${ZDATADIR:-.local/share/zsh}/zplugins" - -unsetopt nomatch # Disable error message when no file can be found +local zplugs="${ZDOTDIR:-~/.}${ZDOTDIR:+/}zplugs" # Declare videos using `local` to keep variables away from interactive shell +local zplugins="${ZPLUGINSDIR:-/usr/local/share/zsh/zplugins}" +[[ $EUID != 0 ]] && local sudo=${SUDO-sudo} function __zplugInstall() { touch "$zplugs" - local pluglist=( `cat "$zplugs"` ) + local pluglist=( `grep -v '#' "$zplugs"` ) + local confirm plug shift - for plug in "$@"; do - pluglist[$((${#pluglist[@]}+1))]=$plug - done + for plug in "$@"; do; pluglist+=(${plug}); done - mkdir -p "$zplugins" + $sudo mkdir -p "$zplugins" for plug in ${pluglist[@]}; do [ -d "$zplugins/$(basename -s'.git' "$plug")" ] && continue - if ! `git -C "$zplugins" clone "$plug" "$(basename -s'.git' "$plug")"`; then - vared -p "Remove \"$plug\"? [y|n]: " -c confirm - [ "$confirm" =~ (y|yes) ] && pluglist=(${pluglist#$plug}) \ - && echo "Repo Deleted" \ - || echo "Repo Kept" - confirm="" + if ! `$sudo git -C "$zplugins" clone "$plug" "$(basename -s'.git' "$plug")"`; then + # Runs if git has an error + printf "Remove \"$plug\"? [y|n]: " + read confirm + case $confirm in + y|yes) pluglist=(${pluglist#$plug}) && echo "Repo Deleted" ;; + *) echo "Repo Kept" ;; + esac fi echo done @@ -31,18 +31,22 @@ function __zplugInstall() { } function __zplugUninstall() { - mkdir -p "$zplugins" - local pluglist=( `cat "$zplugs"` ) + local pluglist=( `cat "$zplugs"` ) pluglistbn=() + local confirm i plug plugids plugig + [ -z "$pluglist" ] && echo "No packages are installed!" && return + + $sudo mkdir -p "$zplugins" echo "Listing all packages in $zplugins ..." - local pluglistbn=() for i in {1..${#pluglist[@]}}; do pluglistbn[$i]="$(basename -s'.git' "${pluglist[$i]}")" printf '%3d) %s\n' $i "${pluglistbn[$i]}" done echo - vared -p "Choose zsh plugin(s) to remove: " -c plugids + printf "Choose zsh plugin(s) to remove: " + read plugids + [ -z "$plugids" ] && echo "No plugins selected\nAborting" && return echo "\nListing selected plugins:" for plugid in $=plugids; do @@ -50,20 +54,19 @@ function __zplugUninstall() { echo "Error: input \"$plugid\" is not a valid plugin identifier" return fi - printf " " - echo "${pluglistbn[$plugid]}" + echo "\t${pluglistbn[$plugid]}" done - echo - vared -p "Really remove all of these plugins? [y|n]: " -c confirm + printf "\nReally remove all of these plugins? [y|n]: " + read confirm case $confirm in y|yes) ;; n|no) echo "Aborted" && return ;; *) echo "Input not understood\nAborted" && return ;; esac for plugid in $=plugids; do - printf " " - rm -vrf "$zplugins/${pluglistbn[$plugid]}" + printf '\t' + $sudo rm -vrf "$zplugins/${pluglistbn[$plugid]}" pluglist[$plugid]="" done for plug in ${pluglist[@]}; do echo "$plug"; done | sort -u > "$zplugs" @@ -71,11 +74,12 @@ function __zplugUninstall() { } function __zplugUpgrade() { - mkdir -p "$zplugins" + local plugdir + $sudo mkdir -p "$zplugins" echo "Upgrading all packages...\n" for plugdir in "$zplugins"/*; do; basename "$plugdir" - git -C "$plugdir" pull; + $sudo git -C "$plugdir" pull; echo done echo "Done" @@ -90,13 +94,23 @@ function __zplugList() { function __zplugHelp() { echo "Usage: zplug [install/add/i|uninstall/remove/r|upgrade/update/u|list/l|help/h] - zplug install, add, i [packages] : Add any packages listed to $zplugs file and install all plugins - zplug uninstall, remove, r : Interactively remove packages. Removes package from config file as well - zplug upgrade, update, u : Update all installed packages - zplug list, l : List all installed packages - zplug help, h : Show this help menu + install, add, i [packages] : Install plugins from config file & add any new plugins + uninstall, remove, r : Interactively remove plugins + upgrade, update, u : Update all installed plugins + list, l : List all installed plugins + help, h : Show this help menu + + All plugins are listed in $zplugs + All plugins are installed in $zplugins + + To install a plugin, just put it in the zplug file and run \"zplug install\" + or just run \"zplug install [plugin]\" where [plugin] is a link to download the + plugin using git + + For instance, \"https://github.com/zdharma-continuum/fast-syntax-highlighting\" is + a valid plugin link for the fast-syntax-highlighting plugin. - To use zplug, just put \"zplugInitialize\" as the last line of your zshrc!" + To use your plugins, just put \"zplugInitialize\" as the last line of your zshrc!" } function zplug() { @@ -112,5 +126,6 @@ function zplug() { } function zplugInitialize() { - for plugin in "$zplugins"/*/*.zsh; do source "$plugin"; done + local plugin + for plugin in "$zplugins"/*/*.zsh; do source "$plugin"; done 2>/dev/null } |