spf13-vim/bootstrap.sh

190 lines
4.6 KiB
Bash
Raw Normal View History

2013-07-30 02:25:12 +00:00
#!/usr/bin/env bash
# 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.
############################ SETUP PARAMETERS
app_name='spf13-vim'
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'
git_branch='3.0'
debug_mode='0'
fork_maintainer='0'
[ -z "$VUNDLE_URI" ] && VUNDLE_URI="https://github.com/gmarik/vundle.git"
############################ BASIC SETUP TOOLS
2013-07-30 02:25:12 +00:00
msg() {
printf '%b\n' "$1" >&2
}
2013-07-30 02:25:12 +00:00
success() {
if [ "$ret" -eq '0' ]; then
msg "\33[32m[✔]\33[0m ${1}${2}"
fi
}
2013-07-30 02:25:12 +00:00
error() {
msg "\33[31m[✘]\33[0m ${1}${2}"
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."
fi
}
2013-07-30 02:25:12 +00:00
program_exists() {
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 "You must have '$1' installed to continue."
fi
}
variable_set() {
if [ -z "$1" ]; then
error "You must have your HOME environmental variable set to continue."
fi
}
2013-07-30 02:25:12 +00:00
lnif() {
if [ -e "$1" ]; then
ln -sf "$1" "$2"
fi
ret="$?"
debug
}
############################ SETUP FUNCTIONS
2013-07-30 02:25:12 +00:00
do_backup() {
2014-06-26 03:42:22 +00:00
if [ -e "$1" ] || [ -e "$2" ] || [ -e "$3" ]; then
msg "Attempting to back up your original vim configuration."
today=`date +%Y%m%d_%s`
2014-06-26 03:42:22 +00:00
for i in "$1" "$2" "$3"; do
[ -e "$i" ] && [ ! -L "$i" ] && mv -v "$i" "$i.$today";
done
ret="$?"
2014-06-26 03:42:22 +00:00
success "Your original vim configuration has been backed up."
debug
fi
}
2014-06-25 08:31:06 +00:00
sync_repo() {
local repo_path="$1"
local repo_uri="$2"
local repo_branch="$3"
local repo_name="$4"
msg "Trying to update $repo_name"
if [ ! -e "$repo_path" ]; then
git clone -b "$repo_branch" "$repo_uri" "$repo_path"
2013-07-30 02:25:12 +00:00
ret="$?"
success "Successfully cloned $repo_name."
else
cd "$repo_path" && git pull origin "$repo_branch"
ret="$?"
success "Successfully updated $repo_name"
fi
debug
}
2013-07-30 02:25:12 +00:00
create_symlinks() {
2014-06-26 03:44:53 +00:00
endpath="$1"
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"
lnif "$endpath/.vimrc.before" "$HOME/.vimrc.before"
2013-07-30 02:25:12 +00:00
lnif "$endpath/.vim" "$HOME/.vim"
touch "$HOME/.vimrc.local"
ret="$?"
2014-06-26 03:44:53 +00:00
success "Setting up vim symlinks."
debug
}
setup_fork_mode() {
local source_path="$2"
local target_path="$3"
if [ "$1" -eq '1' ]; then
touch "$target_path/.vimrc.fork"
touch "$target_path/.vimrc.bundles.fork"
touch "$target_path/.vimrc.before.fork"
lnif "$source_path/.vimrc.fork" "$target_path/.vimrc.fork"
lnif "$source_path/.vimrc.bundles.fork" "$target_path/.vimrc.bundles.fork"
lnif "$source_path/.vimrc.before.fork" "$target_path/.vimrc.before.fork"
ret="$?"
success "Created fork maintainer files."
debug
fi
}
2013-07-30 02:25:12 +00:00
setup_vundle() {
local system_shell="$SHELL"
export SHELL='/bin/sh'
2014-06-25 08:28:39 +00:00
2014-03-21 15:14:12 +00:00
vim \
-u "$1" \
2014-03-21 15:14:12 +00:00
"+set nomore" \
2014-05-04 10:48:34 +00:00
"+BundleInstall!" \
"+BundleClean" \
"+qall"
2014-06-25 08:28:39 +00:00
export SHELL="$system_shell"
success "Now updating/installing plugins using Vundle"
debug
}
2012-09-27 22:06:24 +00:00
############################ MAIN()
variable_set "$HOME"
program_exists "vim"
program_exists "git"
2012-09-27 22:06:24 +00:00
2014-06-26 03:42:22 +00:00
do_backup "$HOME/.vim" \
"$HOME/.vimrc" \
"$HOME/.gvimrc"
sync_repo "$app_dir" \
"$git_uri" \
"$git_branch" \
"$app_name"
2014-06-26 03:44:53 +00:00
create_symlinks "$app_dir"
setup_fork_mode "$fork_maintainer" "$app_dir" "$HOME"
sync_repo "$HOME/.vim/bundle/vundle" \
"$VUNDLE_URI" \
"master" \
"vundle"
setup_vundle "$app_dir/.vimrc.bundles.default"
2012-09-27 22:06:24 +00:00
msg "\nThanks for installing $app_name."
msg "© `date +%Y` http://vim.spf13.com/"