From 6c44c6aa3a7d8329f1904cd96c1ee6f0dd5720f0 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Tue, 21 May 2013 00:01:35 -0700 Subject: [PATCH] Improve install script to handle Bundles Can now specify vim plugin bundles as short forms. Eg.: - tpope/vim-pathogen - goes to github.com/tpope/vim-pathogen.git - vimwiki - goes to github.com/vim-scripts/vimwiki.git - any other form is not modified and passed straight through Can also specify the transport mechanism to use when installing bundles. This has no impact when updating bundles, since these will use the remote url specified in the git repo. Can also specify not to update existing bundles with a command line switch. --- install | 119 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 100 insertions(+), 19 deletions(-) diff --git a/install b/install index f44d280..3f33916 100755 --- a/install +++ b/install @@ -1,5 +1,11 @@ #!/bin/bash +####################################################################### +# Default settings +####################################################################### +# Use git by default +BUNDLE_TRANSPORT="git" + ####################################################################### # Helper functions ####################################################################### @@ -95,13 +101,16 @@ vim_update_bundle() # If the bundle already exists, update it (if possible) if [[ -d "$HOME/.vim/bundle/$BUNDLE" ]] then + # Don't update the bundle if BUNDLE_NO_UPDATE is set if [[ -d "$HOME/.vim/bundle/$BUNDLE/.git" ]] then - echo "Updating bundle $BUNDLE..." - pushd "$HOME/.vim/bundle/$BUNDLE" >/dev/null - git pull - popd >/dev/null - echo + if [[ -z $BUNDLE_NO_UPDATE ]]; then + echo "Updating bundle $BUNDLE..." + pushd "$HOME/.vim/bundle/$BUNDLE" >/dev/null + git pull + popd >/dev/null + echo + fi else echo "$BUNDLE is not a Git repository. Skipping update." fi @@ -114,6 +123,85 @@ vim_update_bundle() fi } +# Wrapper to vim_update_bundle +# Let's you specify the bundle repo in a short form if it resides on GitHub +# (and perhaps one of the repos in vim-scripts). You can still specify a full +# URL if necessary. However, that will not allow you to dynamically choose a +# transport layer at runtime +Bundle() +{ + # Get the prefix ready + if [[ "$BUNDLE_TRANSPORT" == "ssh" ]]; then + # If the user specifies to use ssh as the transport + URL="git@github.com:" + elif [[ "$BUNDLE_TRANSPORT" == "https" ]]; then + # Use https as the transport + URL="https://github.com/" + elif [[ "$BUNDLE_TRANSPORT" == "git" ]]; then + # Use git as the transport + URL="git://github.com/" + else + echo "Invalid transport layer! Aborting!!!" + exit 1 + fi + + # Check the bundle format + if [[ $(echo $1 | grep "^[A-Za-z0-9-]\+\/[A-Za-z0-9._-]\+$") == $1 ]]; then + # Username/repo combo + URL="${URL}${1}.git" + elif [[ $(echo $1 | grep "^[A-Za-z0-9._-]\+$") == $1 ]]; then + # Bare repo name - must be from the vim-scripts user + URL="${URL}vim-scripts/${1}.git" + else + # I don't care, I'm specifying the URL directly + URL=$1 + fi + + vim_update_bundle "$URL" +} + +####################################################################### +# Verify command line switches +####################################################################### +while getopts "nht:" OPTION +do + case "$OPTION" in + n) + echo "Skipping bundle updates" + BUNDLE_NO_UPDATE=1 + ;; + + t) + echo "Using transport $OPTARG" + BUNDLE_TRANSPORT=$OPTARG + ;; + + h) + echo ' +This script installs the dotfiles into various locations using symbolic +links. + +Options: +-------- + -n Will not update existing bundles, but will install new + bundles. + + -t