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.
vimbundler
nirenjan 2013-05-21 00:01:35 -07:00
parent bf4a150e14
commit 6c44c6aa3a
1 changed files with 100 additions and 19 deletions

119
install
View File

@ -1,5 +1,11 @@
#!/bin/bash #!/bin/bash
#######################################################################
# Default settings
#######################################################################
# Use git by default
BUNDLE_TRANSPORT="git"
####################################################################### #######################################################################
# Helper functions # Helper functions
####################################################################### #######################################################################
@ -95,13 +101,16 @@ vim_update_bundle()
# If the bundle already exists, update it (if possible) # If the bundle already exists, update it (if possible)
if [[ -d "$HOME/.vim/bundle/$BUNDLE" ]] if [[ -d "$HOME/.vim/bundle/$BUNDLE" ]]
then then
# Don't update the bundle if BUNDLE_NO_UPDATE is set
if [[ -d "$HOME/.vim/bundle/$BUNDLE/.git" ]] if [[ -d "$HOME/.vim/bundle/$BUNDLE/.git" ]]
then then
echo "Updating bundle $BUNDLE..." if [[ -z $BUNDLE_NO_UPDATE ]]; then
pushd "$HOME/.vim/bundle/$BUNDLE" >/dev/null echo "Updating bundle $BUNDLE..."
git pull pushd "$HOME/.vim/bundle/$BUNDLE" >/dev/null
popd >/dev/null git pull
echo popd >/dev/null
echo
fi
else else
echo "$BUNDLE is not a Git repository. Skipping update." echo "$BUNDLE is not a Git repository. Skipping update."
fi fi
@ -114,6 +123,85 @@ vim_update_bundle()
fi 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<option> Specify the transport for downloading bundles. Can be
one of git, https or ssh. ssh transport requires you to
have set up the necessary keys at GitHub
-h Displays this help message
'
exit 0
;;
\?)
exit 1
break
;;
esac
done
####################################################################### #######################################################################
# Install dotfiles # Install dotfiles
####################################################################### #######################################################################
@ -195,25 +283,18 @@ lnfile vim/ftplugin/ruby.vim ~/.vim/ftplugin/
# Install pathogen # Install pathogen
if [[ ! -f ~/.vim/autoload/pathogen.vim ]] if [[ ! -f ~/.vim/autoload/pathogen.vim ]]
then then
echo "Installing vim-pathogen" echo "Deleting legacy pathogen file. This is now maintained as a Bundle."
curl -Sso ~/.vim/autoload/pathogen.vim \ rm -f ~/.vim/autoload/pathogen.vim
https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
fi fi
####################################################################### #######################################################################
# Install/update Vim bundles # Install/update Vim bundles
####################################################################### #######################################################################
# tmux config file syntax Bundle tpope/vim-pathogen # pathogen
vim_update_bundle https://github.com/zaiste/tmux.vim.git Bundle zaiste/tmux.vim # tmux config file syntax
Bundle altercation/vim-colors-solarized # Solarized
# Solarized Bundle vimwiki # Vimwiki
vim_update_bundle https://github.com/altercation/vim-colors-solarized.git Bundle msanders/snipmate.vim # snipMate
# Vimwiki
vim_update_bundle https://github.com/vim-scripts/vimwiki.git
# snipMate
vim_update_bundle https://github.com/msanders/snipmate.vim.git
####################################################################### #######################################################################
# Install tmux & screen config files # Install tmux & screen config files