2013-07-30 02:25:12 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-08-26 20:02:03 +00:00
|
|
|
|
|
|
|
# Copyright 2014 Steve Francia
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2013-07-16 21:02:48 +00:00
|
|
|
############################ SETUP PARAMETERS
|
|
|
|
app_name='spf13-vim'
|
2014-02-10 08:55:33 +00:00
|
|
|
app_dir="$HOME/.spf13-vim-3"
|
2014-01-31 07:41:47 +00:00
|
|
|
[ -z "$git_uri" ] && git_uri='https://github.com/spf13/spf13-vim.git'
|
2013-07-16 21:02:48 +00:00
|
|
|
git_branch='3.0'
|
|
|
|
debug_mode='0'
|
2013-07-17 02:22:16 +00:00
|
|
|
fork_maintainer='0'
|
2014-01-31 07:37:49 +00:00
|
|
|
[ -z "$VUNDLE_URI" ] && VUNDLE_URI="https://github.com/gmarik/vundle.git"
|
2013-07-16 21:02:48 +00:00
|
|
|
|
|
|
|
############################ BASIC SETUP TOOLS
|
2013-07-30 02:25:12 +00:00
|
|
|
msg() {
|
2013-07-16 21:02:48 +00:00
|
|
|
printf '%b\n' "$1" >&2
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
success() {
|
|
|
|
if [ "$ret" -eq '0' ]; then
|
2013-08-01 01:17:35 +00:00
|
|
|
msg "\e[32m[✔]\e[0m ${1}${2}"
|
2013-07-16 21:02:48 +00:00
|
|
|
fi
|
2011-04-25 12:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
error() {
|
2013-08-01 01:17:35 +00:00
|
|
|
msg "\e[31m[✘]\e[0m ${1}${2}"
|
2011-04-25 12:21:28 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
debug() {
|
|
|
|
if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then
|
2014-02-02 21:17:17 +00:00
|
|
|
msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
|
2013-07-16 21:02:48 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
program_exists() {
|
2013-07-16 21:02:48 +00:00
|
|
|
local ret='0'
|
|
|
|
type $1 >/dev/null 2>&1 || { local ret='1'; }
|
|
|
|
|
|
|
|
# throw error on non-zero return value
|
2013-07-30 02:25:12 +00:00
|
|
|
if [ ! "$ret" -eq '0' ]; then
|
|
|
|
error "$2"
|
2013-07-16 21:02:48 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-08-21 03:21:20 +00:00
|
|
|
variable_set() {
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
error "You must have your HOME environmental variable set to continue."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-07-16 21:02:48 +00:00
|
|
|
############################ SETUP FUNCTIONS
|
2013-07-30 02:25:12 +00:00
|
|
|
lnif() {
|
|
|
|
if [ -e "$1" ]; then
|
2013-07-16 21:21:17 +00:00
|
|
|
ln -sf "$1" "$2"
|
2013-01-04 11:04:13 +00:00
|
|
|
fi
|
2013-07-17 02:22:16 +00:00
|
|
|
ret="$?"
|
|
|
|
debug
|
2012-09-27 18:00:35 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
do_backup() {
|
|
|
|
if [ -e "$2" ] || [ -e "$3" ] || [ -e "$4" ]; then
|
2013-07-17 02:22:16 +00:00
|
|
|
today=`date +%Y%m%d_%s`
|
|
|
|
for i in "$2" "$3" "$4"; do
|
|
|
|
[ -e "$i" ] && [ ! -L "$i" ] && mv "$i" "$i.$today";
|
|
|
|
done
|
|
|
|
ret="$?"
|
|
|
|
success "$1"
|
|
|
|
debug
|
|
|
|
fi
|
2013-07-16 21:02:48 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
upgrade_repo() {
|
2013-07-16 21:02:48 +00:00
|
|
|
msg "trying to update $1"
|
2011-04-25 12:21:28 +00:00
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
if [ "$1" = "$app_name" ]; then
|
2014-02-10 08:55:33 +00:00
|
|
|
cd "$app_dir" &&
|
2013-07-30 02:25:12 +00:00
|
|
|
git pull origin "$git_branch"
|
2013-07-16 21:02:48 +00:00
|
|
|
fi
|
2011-04-25 12:21:28 +00:00
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
if [ "$1" = "vundle" ]; then
|
|
|
|
cd "$HOME/.vim/bundle/vundle" &&
|
|
|
|
git pull origin master
|
2013-07-16 21:02:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
ret="$?"
|
|
|
|
success "$2"
|
|
|
|
debug
|
|
|
|
}
|
2012-09-27 18:00:35 +00:00
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
clone_repo() {
|
|
|
|
program_exists "git" "Sorry, we cannot continue without GIT, please install it first."
|
2011-11-20 05:18:03 +00:00
|
|
|
|
2014-02-10 08:55:33 +00:00
|
|
|
if [ ! -e "$app_dir" ]; then
|
|
|
|
git clone --recursive -b "$git_branch" "$git_uri" "$app_dir"
|
2013-07-30 02:25:12 +00:00
|
|
|
ret="$?"
|
|
|
|
success "$1"
|
|
|
|
debug
|
2013-07-16 21:02:48 +00:00
|
|
|
else
|
2013-07-30 02:25:12 +00:00
|
|
|
upgrade_repo "$app_name" "Successfully updated $app_name"
|
2013-07-16 21:02:48 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
clone_vundle() {
|
|
|
|
if [ ! -e "$HOME/.vim/bundle/vundle" ]; then
|
2014-01-31 07:37:49 +00:00
|
|
|
git clone $VUNDLE_URI "$HOME/.vim/bundle/vundle"
|
2013-07-16 21:02:48 +00:00
|
|
|
else
|
2013-07-30 02:25:12 +00:00
|
|
|
upgrade_repo "vundle" "Successfully updated vundle"
|
2013-07-16 21:02:48 +00:00
|
|
|
fi
|
2013-07-17 02:22:16 +00:00
|
|
|
ret="$?"
|
2013-07-16 21:02:48 +00:00
|
|
|
success "$1"
|
|
|
|
debug
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
create_symlinks() {
|
2014-02-10 08:55:33 +00:00
|
|
|
endpath="$app_dir"
|
2013-07-17 02:22:16 +00:00
|
|
|
|
2013-09-14 08:28:19 +00:00
|
|
|
if [ ! -d "$endpath/.vim/bundle" ]; then
|
|
|
|
mkdir -p "$endpath/.vim/bundle"
|
|
|
|
fi
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
lnif "$endpath/.vimrc" "$HOME/.vimrc"
|
|
|
|
lnif "$endpath/.vimrc.bundles" "$HOME/.vimrc.bundles"
|
2013-08-28 23:34:19 +00:00
|
|
|
lnif "$endpath/.vimrc.before" "$HOME/.vimrc.before"
|
2013-07-30 02:25:12 +00:00
|
|
|
lnif "$endpath/.vim" "$HOME/.vim"
|
2013-07-16 21:02:48 +00:00
|
|
|
|
2013-07-17 02:22:16 +00:00
|
|
|
# Useful for fork maintainers
|
|
|
|
touch "$HOME/.vimrc.local"
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
if [ -e "$endpath/.vimrc.fork" ]; then
|
|
|
|
ln -sf "$endpath/.vimrc.fork" "$HOME/.vimrc.fork"
|
|
|
|
elif [ "$fork_maintainer" -eq '1' ]; then
|
2013-08-28 23:34:19 +00:00
|
|
|
touch "$HOME/.vimrc.fork"
|
|
|
|
touch "$HOME/.vimrc.bundles.fork"
|
|
|
|
touch "$HOME/.vimrc.before.fork"
|
2013-07-17 02:22:16 +00:00
|
|
|
fi
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
if [ -e "$endpath/.vimrc.bundles.fork" ]; then
|
|
|
|
ln -sf "$endpath/.vimrc.bundles.fork" "$HOME/.vimrc.bundles.fork"
|
2013-07-17 02:22:16 +00:00
|
|
|
fi
|
2013-07-16 21:02:48 +00:00
|
|
|
|
2013-08-28 23:34:19 +00:00
|
|
|
if [ -e "$endpath/.vimrc.before.fork" ]; then
|
|
|
|
ln -sf "$endpath/.vimrc.before.fork" "$HOME/.vimrc.before.fork"
|
|
|
|
fi
|
|
|
|
|
2013-07-17 02:22:16 +00:00
|
|
|
ret="$?"
|
2013-07-16 21:02:48 +00:00
|
|
|
success "$1"
|
|
|
|
debug
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
setup_vundle() {
|
2013-07-16 21:02:48 +00:00
|
|
|
system_shell="$SHELL"
|
2013-07-17 02:22:16 +00:00
|
|
|
export SHELL='/bin/sh'
|
2014-03-21 15:14:12 +00:00
|
|
|
|
|
|
|
vim \
|
2014-05-03 19:51:54 +00:00
|
|
|
-u "$app_dir/.vimrc.bundles.default" \
|
2014-03-21 15:14:12 +00:00
|
|
|
"+set nomore" \
|
2014-05-04 10:48:34 +00:00
|
|
|
"+BundleInstall!" \
|
|
|
|
"+BundleClean" \
|
|
|
|
"+qall"
|
2014-03-21 15:14:12 +00:00
|
|
|
|
2013-07-16 21:02:48 +00:00
|
|
|
export SHELL="$system_shell"
|
|
|
|
|
|
|
|
success "$1"
|
|
|
|
debug
|
|
|
|
}
|
2012-09-27 22:06:24 +00:00
|
|
|
|
2013-07-16 21:02:48 +00:00
|
|
|
############################ MAIN()
|
2014-08-21 03:21:20 +00:00
|
|
|
variable_set "$HOME"
|
2013-07-30 02:25:12 +00:00
|
|
|
program_exists "vim" "To install $app_name you first need to install Vim."
|
2012-09-27 22:06:24 +00:00
|
|
|
|
2013-08-01 01:17:35 +00:00
|
|
|
do_backup "Your old vim stuff has a suffix now and looks like .vim.`date +%Y%m%d%S`" \
|
2013-07-30 02:25:12 +00:00
|
|
|
"$HOME/.vim" \
|
|
|
|
"$HOME/.vimrc" \
|
|
|
|
"$HOME/.gvimrc"
|
2013-07-17 02:22:16 +00:00
|
|
|
|
2013-08-01 01:17:35 +00:00
|
|
|
clone_repo "Successfully cloned $app_name"
|
2013-07-17 02:22:16 +00:00
|
|
|
|
2013-07-16 21:02:48 +00:00
|
|
|
create_symlinks "Setting up vim symlinks"
|
2013-07-17 02:22:16 +00:00
|
|
|
|
2013-07-30 02:25:12 +00:00
|
|
|
clone_vundle "Successfully cloned vundle"
|
|
|
|
|
|
|
|
setup_vundle "Now updating/installing plugins using Vundle"
|
2012-09-27 22:06:24 +00:00
|
|
|
|
2013-08-01 01:17:35 +00:00
|
|
|
msg "\nThanks for installing $app_name."
|
|
|
|
msg "© `date +%Y` http://vim.spf13.com/"
|