Skip to content

Instantly share code, notes, and snippets.

@lunacookies
Last active January 24, 2022 11:17
Show Gist options
  • Save lunacookies/64fcf8601b97e084ec5681c97f292b1a to your computer and use it in GitHub Desktop.
Save lunacookies/64fcf8601b97e084ec5681c97f292b1a to your computer and use it in GitHub Desktop.
Simple bash script for installing your Vim plugins the vanilla way
#!/usr/bin/env bash
# Enable extended globbing (we need it later)
shopt -s extglob
# What plugins we install
#
# Put the GitHub username<slash>repo name of each plugin you want in this array.
# e.g.
plugins=(
romainl/vim-cool
tpope/vim-surround
tpope/vim-unimpaired
wellle/targets.vim
)
# Remove any old plugins
rm -rf $HOME/.vim/pack
mkdir -p $HOME/.vim/pack/bundle/start
installplugin() {
# This removes the GitHub username and two common Vim plugin name
# prefix/suffixes
#
# We do this because I find it looks nicer and cleaner when doing a quick ls
# on your plugin collection
local plugin="$(echo "$1" | sed -e 's/.*[\/]//' -e 's/^vim-//' -e 's/\.vim//')"
local pluginpath="$HOME/.vim/pack/bundle/start/$plugin"
# * Don't clone the plugin's history (--depth=1) to make download faster
# * All Vim plugins I (and I think most people) use are on GitHub
git clone --depth=1 -q https://github.com/$1.git "$pluginpath"
# Remove git-related files to prevent nested git repositories
rm -rf "$pluginpath"/.git*
# Remove any non-essential files that are not needed for the plugin to run
rm -rf "$pluginpath"/README*
rm -f "$pluginpath"/*.@(md|mdown|mkdown|markdown)
rm -rf "$pluginpath"/test
# Print a line announcing installation of the plugin on top of any previous
# announcements. We do this to provide visual feedback to show the script is
# working, but does not take up space.
printf "\r\e[0KInstalled $plugin"
}
# The & is so that bash sets the installation as a background job, allowing for
# asynchronous installation (all plugins being installed at the same time).
for repo in ${plugins[@]}; do
installplugin "$repo" &
done
# This makes the script wait for all the background jobs from installing all the
# plugins above before continuing
wait
# Clear away all output from the script
printf "\r\e[0K"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment