#!/usr/bin/env bash # package_dirs records directories of all installed packages. It is used # to help clean unused packages. package_dirs=() update_package () { name=$1 remote_url=$2 load_type=$3 package_dir="$HOME/.vim/pack/vendor/$load_type/$name" package_dirs+=($package_dir) if [ ! -d $package_dir ]; then echo "$name : Installing ... " mkdir -p $package_dir git clone --depth 1 $remote_url $package_dir && echo "$name : Done" || echo "$name : FAIL" else cd $package_dir echo "$name : Updating ... " git pull && echo "$name : Done" || echo "$name : FAIL" fi } clean () { for load_type in 'opt' 'start'; do for package_name in $(ls $HOME/.vim/pack/vendor/$load_type); do package_dir=$HOME/.vim/pack/vendor/$load_type/$package_name if [[ ! " ${package_dirs[*]} " =~ " ${package_dir} " ]]; then read -r -p "rm -rf $package_dir? [y/N]: " response response=${response,,} if [[ "$response" =~ ^(yes|y)$ ]]; then rm -rf $package_dir fi fi done done } update_package "nnn.vim" "git@github.com:mcchrish/nnn.vim.git" "opt" clean