1 Star 0 Fork 0

toalexjin / vim-kit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
update 3.78 KB
一键复制 编辑 原始数据 按行查看 历史
toalexjin 提交于 2015-04-13 16:27 . Invoke 'eval =xxxx' in shell functions
#!/bin/bash
vimprofile=~/.vimrc
gitdir=~/git
vimkitdir="$gitdir/vim-kit"
vimkitfile="$gitdir/vim-kit/vimrc.vim"
plugindir="$gitdir/vim-plugins"
failure() {
for ((i=1;i<=$#;i++))
do
echo "${!i}" 1>&2
done
echo $'\nFailed!'
exit 1
}
run_cmd() {
echo "$1"
if ! eval "$1"
then
failure
fi
}
# Usage: "get_current_branch <branch_name>"
get_current_branch() {
eval "$1='`git branch --no-color | awk '{if ($1=="*") print $2}'`'"
if [ -z "${!1}" ]
then
failure "Curent branch name is unknown. Check 'git branch --no-color'."
fi
}
github_pull() {
local parentdir="$1"
local author="$2"
local project="$3"
if [ ! -d "$parentdir" ]
then
run_cmd "mkdir -p '$parentdir'"
fi
if [ -d "$parentdir/$project" ]
then
run_cmd "cd '$parentdir/$project'"
run_cmd "git pull"
else
run_cmd "cd '$parentdir'"
run_cmd "git clone 'https://github.com/${author}/${project}.git'"
fi
}
# Check if ctags has been installed or not
if ! which git > /dev/null 2>&1
then
failure '"git" is not installed.'
fi
# Check if ctags has been installed or not
if ! which ctags > /dev/null 2>&1
then
failure 'Please run "sudo yum install ctags" or "apt-get install ctags" first.'
fi
# update vim-kit first!
run_cmd "cd '$vimkitdir'"
get_current_branch currentname
if [ "$currentname" == "master" -a `git status -s | wc -l` -eq 0 ]
then
run_cmd "git pull"
fi
if [ ! -f "$vimkitfile" ]
then
failure "Could not find file '$vimkitfile'."
fi
# Get a list of VIM plugins
v1=`cat "$vimkitfile" | sed -nr '/^[ \t]*Plugin[ \t]+.*/p' | awk '{print $2}' | awk 'BEGIN{FS=","} {print $1}'`
v1="${v1//\// }"
v1="${v1//\'/ }"
plugins=($v1)
if ((${#plugins[@]} == 0 || ${#plugins[@]} % 2 != 0))
then
failure "The plugin list in file '$vimkitfile' is incorrect."
fi
# Create folder ~/git/vim-plugins
if [ ! -d "$plugindir" ]
then
run_cmd "mkdir -p '$plugindir'"
fi
for ((i=0;i<${#plugins[@]};i+=2))
do
github_pull "$plugindir" "${plugins[i]}" "${plugins[i+1]}"
done
# run helptags for each plugin.
for ((i=0;i<${#plugins[@]};i+=2))
do
docdir="$plugindir/${plugins[i+1]}/doc"
if [ -d "$docdir" ]
then
run_cmd "vim --noplugin -n -c 'helptags $docdir | q' > /dev/null 2>&1"
fi
done
# Build gocode and move gocode binary to $HOME/bin
if [ -n "$GOROOT" -a -x "$GOROOT/bin/go" ]
then
export GOPATH="$plugindir/go"
# Update golang.org/x/tools first because other go modules depend on it.
github_pull "$GOPATH/src/golang.org/x" "golang" "tools"
run_cmd "go install golang.org/x/tools/cmd/oracle"
run_cmd "go install golang.org/x/tools/cmd/goimports"
run_cmd "go install golang.org/x/tools/cmd/gorename"
# 9fans.net/go is used by godef
github_pull "$GOPATH/src/9fans.net" "9fans" "go"
# Update all go modules
gomods=()
gomods+=(jstemmer gotags '')
gomods+=(kisielk gotool '')
gomods+=(kisielk errcheck '')
gomods+=(nsf gocode '')
gomods+=(golang lint 'golint')
gomods+=(rogpeppe godef)
for ((i=0;i<${#gomods[@]};i+=3))
do
github_pull "$GOPATH/src/github.com/${gomods[i]}" "${gomods[i]}" "${gomods[i+1]}"
if [ -z "${gomods[i+2]}" ]
then
run_cmd "go install github.com/${gomods[i]}/${gomods[i+1]}"
else
run_cmd "go install github.com/${gomods[i]}/${gomods[i+1]}/${gomods[i+2]}"
fi
done
if [ ! -d ~/bin ]
then
run_cmd "mkdir ~/bin"
fi
run_cmd "cp -Rf $GOPATH/bin/* ~/bin/."
# Check if ~/bin is in $PATH
if ! which gotags > /dev/null 2>&1
then
failure 'Please add "export PATH=$PATH:~/bin" to ~/.bash_profile, re-log into system and try again.'
fi
fi
# ln -s ~/git/vim-kit/vimrc.vim ~/.vimrc
if [ -L "$vimprofile" -o -f "$vimprofile" ]
then
if [ ! "$vimkitfile" -ef "$vimprofile" ]
then
run_cmd "mv -f '$vimprofile' '$vimprofile.old'"
run_cmd "ln -s '$vimkitfile' '$vimprofile'"
fi
else
run_cmd "ln -s '$vimkitfile' '$vimprofile'"
fi
# Success
echo -e "\nDone! Everything has been installed/updated to latest!\n"
VimL
1
https://gitee.com/toalexjin/vim-kit.git
git@gitee.com:toalexjin/vim-kit.git
toalexjin
vim-kit
vim-kit
master

搜索帮助