1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 02:10:05 +08:00
SpaceVim/docs/install.sh

204 lines
5.4 KiB
Bash
Raw Normal View History

2017-01-04 00:20:25 +08:00
#!/usr/bin/env bash
2017-07-03 21:15:45 +08:00
#=============================================================================
# install.sh --- bootstrap script for SpaceVim
# Copyright (c) 2016-2017 Shidong Wang & Contributors
# Author: Shidong Wang < wsdjeg at 163.com >
# URL: https://spacevim.org
# License: MIT license
#=============================================================================
2017-01-21 01:09:25 +08:00
2017-01-04 00:20:25 +08:00
# Reset
Color_off='\033[0m' # Text Reset
2017-07-03 22:08:04 +08:00
Version='0.4.0-dev'
2017-01-04 00:20:25 +08:00
# Regular Colors
2017-07-03 21:15:45 +08:00
Red='\033[0;31m'
Blue='\033[0;34m'
Green='\033[0;32m'
2017-01-04 00:20:25 +08:00
need_cmd () {
2017-01-04 23:42:54 +08:00
if ! hash "$1" &>/dev/null; then
2017-07-03 21:15:45 +08:00
error "Need '$1' (command not fount)"
2017-01-04 23:42:54 +08:00
exit 1
2017-01-04 00:20:25 +08:00
fi
}
2017-07-03 21:15:45 +08:00
msg() {
printf '%b\n' "$1" >&2
}
success() {
2017-07-03 21:16:57 +08:00
msg "${Green}[✔]${Color_off} ${1}${2}"
2017-07-03 21:15:45 +08:00
}
info() {
msg "${Blue}==>${Color_off} ${1}${2}"
}
error() {
msg "${Red}[✘]${Color_off} ${1}${2}"
exit 1
}
2017-01-04 00:20:25 +08:00
fetch_repo () {
2017-01-04 23:42:54 +08:00
if [[ -d "$HOME/.SpaceVim" ]]; then
2017-07-03 21:15:45 +08:00
info "Trying to update SpaceVim"
2017-01-11 05:33:39 +08:00
git --git-dir "$HOME/.SpaceVim/.git" pull
2017-07-03 21:15:45 +08:00
success "Successfully update SpaceVim"
2017-01-04 00:20:25 +08:00
else
2017-07-03 21:15:45 +08:00
info "Trying to clone SpaceVim"
2017-01-04 23:42:54 +08:00
git clone https://github.com/SpaceVim/SpaceVim.git "$HOME/.SpaceVim"
2017-07-03 21:15:45 +08:00
success "Successfully clone SpaceVim"
2017-01-04 00:20:25 +08:00
fi
}
install_vim () {
2017-01-04 23:42:54 +08:00
if [[ -f "$HOME/.vimrc" ]]; then
mv "$HOME/.vimrc" "$HOME/.vimrc_back"
2017-07-03 23:53:55 +08:00
success "Backup $HOME/.vimrc to $HOME/.vimrc_back"
2017-01-04 00:20:25 +08:00
fi
2017-01-04 23:42:54 +08:00
if [[ -d "$HOME/.vim" ]]; then
if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then
2017-07-03 23:53:55 +08:00
success "Installed SpaceVim for vim"
2017-01-04 00:20:25 +08:00
else
2017-01-04 23:42:54 +08:00
mv "$HOME/.vim" "$HOME/.vim_back"
2017-07-03 23:53:55 +08:00
success "BackUp $HOME/.vim to $HOME/.vim_back"
2017-01-04 23:42:54 +08:00
ln -s "$HOME/.SpaceVim" "$HOME/.vim"
2017-07-03 23:53:55 +08:00
success "Installed SpaceVim for vim"
2017-01-04 00:20:25 +08:00
fi
else
2017-01-04 23:42:54 +08:00
ln -s "$HOME/.SpaceVim" "$HOME/.vim"
2017-07-03 23:53:55 +08:00
success "Installed SpaceVim for vim"
2017-01-04 00:20:25 +08:00
fi
}
install_neovim () {
2017-01-04 23:42:54 +08:00
if [[ -d "$HOME/.config/nvim" ]]; then
if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then
2017-07-03 23:53:55 +08:00
success "Installed SpaceVim for neovim"
2017-01-04 00:20:25 +08:00
else
2017-01-04 23:42:54 +08:00
mv "$HOME/.config/nvim" "$HOME/.config/nvim_back"
2017-07-03 23:53:55 +08:00
success "BackUp $HOME/.config/nvim to $HOME/.config/nvim_back"
2017-01-04 23:42:54 +08:00
ln -s "$HOME/.SpaceVim" "$HOME/.config/nvim"
2017-07-03 23:53:55 +08:00
success "Installed SpaceVim for neovim"
2017-01-04 00:20:25 +08:00
fi
else
2017-01-04 23:42:54 +08:00
ln -s "$HOME/.SpaceVim" "$HOME/.config/nvim"
2017-07-03 23:53:55 +08:00
success "Installed SpaceVim for neovim"
2017-01-04 00:20:25 +08:00
fi
}
2017-01-07 00:31:30 +08:00
uninstall_vim () {
if [[ -d "$HOME/.vim" ]]; then
if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then
rm "$HOME/.vim"
2017-07-03 23:53:55 +08:00
success "Uninstall SpaceVim for vim"
2017-01-07 00:31:30 +08:00
if [[ -d "$HOME/.vim_back" ]]; then
mv "$HOME/.vim_back" "$HOME/.vim"
2017-07-03 23:53:55 +08:00
success "Recover from $HOME/.vim_back"
2017-01-07 00:31:30 +08:00
fi
fi
fi
if [[ -f "$HOME/.vimrc_back" ]]; then
mv "$HOME/.vimrc_back" "$HOME/.vimrc"
2017-07-03 23:53:55 +08:00
success "Recover from $HOME/.vimrc_back"
2017-01-07 00:31:30 +08:00
fi
}
2017-01-04 00:20:25 +08:00
2017-01-07 00:31:30 +08:00
uninstall_neovim () {
if [[ -d "$HOME/.config/nvim" ]]; then
if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then
rm "$HOME/.config/nvim"
2017-07-03 23:53:55 +08:00
success "Uninstall SpaceVim for neovim"
2017-01-07 00:31:30 +08:00
if [[ -d "$HOME/.config/nvim_back" ]]; then
mv "$HOME/.config/nvim_back" "$HOME/.config/nvim"
2017-07-03 23:53:55 +08:00
success "Recover from $HOME/.config/nvim_back"
2017-01-07 00:31:30 +08:00
fi
fi
fi
}
2017-01-04 00:20:25 +08:00
2017-01-07 00:31:30 +08:00
usage () {
2017-07-03 22:08:04 +08:00
echo "SpaceVim install script : V ${Version}"
echo ""
2017-07-03 22:12:06 +08:00
echo "Usage : curl -sLf https://spacevim.org/install.sh | bash -s -- [option] [target]"
2017-07-03 22:08:04 +08:00
echo ""
echo " This is bootstrap script for SpaceVim."
echo ""
echo "OPTIONS"
echo ""
echo " -i, --install install spacevim for vim or neovim"
echo " -v, --version Show version information and exit"
echo " -u, --uninstall Uninstall SpaceVim"
echo ""
echo "EXAMPLE"
echo ""
2017-01-07 00:31:30 +08:00
echo " Install SpaceVim for vim and neovim"
2017-07-03 22:08:04 +08:00
echo ""
2017-01-07 12:17:46 +08:00
echo " curl -sLf https://spacevim.org/install.sh | bash"
2017-07-03 22:08:04 +08:00
echo ""
2017-01-07 00:31:30 +08:00
echo " Install SpaceVim for vim only or neovim only"
2017-07-03 22:08:04 +08:00
echo ""
echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --install vim"
echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --install neovim"
echo ""
2017-01-07 00:31:30 +08:00
echo " Uninstall SpaceVim"
2017-07-03 22:08:04 +08:00
echo ""
echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --uninstall"
2017-01-07 00:31:30 +08:00
}
2017-01-04 00:20:25 +08:00
2017-01-07 00:31:30 +08:00
if [ $# -gt 0 ]
then
case $1 in
2017-07-03 22:08:04 +08:00
--uninstall)
2017-07-03 23:53:55 +08:00
info "Trying to uninstall SpaceVim"
2017-01-07 00:31:30 +08:00
uninstall_vim
uninstall_neovim
exit 0
;;
2017-07-03 22:08:04 +08:00
--install)
2017-01-07 00:31:30 +08:00
need_cmd 'git'
fetch_repo
if [ $# -eq 2 ]
then
case $2 in
neovim)
install_neovim
exit 0
;;
vim)
install_vim
exit 0
esac
fi
install_vim
install_neovim
exit 0
;;
-h)
usage
exit 0
2017-07-03 22:08:04 +08:00
;;
--help)
usage
exit 0
;;
-v)
msg "${Version}"
exit 0
;;
--version)
msg "${Version}"
exit 0
2017-01-07 00:31:30 +08:00
esac
fi
# if no argv, installer will install SpaceVim
need_cmd 'git'
fetch_repo
install_vim
install_neovim