1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-09 09:40:04 +08:00

Improve install script

This commit is contained in:
wsdjeg 2018-01-27 19:23:47 +08:00
parent 69379d3f4a
commit d925fb1fde

View File

@ -8,7 +8,7 @@
# License: MIT license # License: MIT license
#============================================================================= #=============================================================================
# Init option {{{
# Reset # Reset
Color_off='\033[0m' # Text Reset Color_off='\033[0m' # Text Reset
Version='0.6.0' Version='0.6.0'
@ -21,13 +21,18 @@ Green='\033[0;32m'
#System name #System name
System="$(uname -s)" System="$(uname -s)"
# }}}
# need_cmd {{{
need_cmd () { need_cmd () {
if ! hash "$1" &>/dev/null; then if ! hash "$1" &>/dev/null; then
error "Need '$1' (command not fount)" error "Need '$1' (command not fount)"
exit 1 exit 1
fi fi
} }
# }}}
# success/info/error/warn {{{
msg() { msg() {
printf '%b\n' "$1" >&2 printf '%b\n' "$1" >&2
} }
@ -48,7 +53,9 @@ error() {
warn () { warn () {
msg "${Red}[✘]${Color_off} ${1}${2}" msg "${Red}[✘]${Color_off} ${1}${2}"
} }
# }}}
# fetch_repo {{{
fetch_repo () { fetch_repo () {
if [[ -d "$HOME/.SpaceVim" ]]; then if [[ -d "$HOME/.SpaceVim" ]]; then
info "Trying to update SpaceVim" info "Trying to update SpaceVim"
@ -60,7 +67,9 @@ fetch_repo () {
success "Successfully clone SpaceVim" success "Successfully clone SpaceVim"
fi fi
} }
# }}}
# install_vim {{{
install_vim () { install_vim () {
if [[ -f "$HOME/.vimrc" ]]; then if [[ -f "$HOME/.vimrc" ]]; then
mv "$HOME/.vimrc" "$HOME/.vimrc_back" mv "$HOME/.vimrc" "$HOME/.vimrc_back"
@ -81,7 +90,9 @@ install_vim () {
success "Installed SpaceVim for vim" success "Installed SpaceVim for vim"
fi fi
} }
# }}}
# install_package_manager {{{
install_package_manager () { install_package_manager () {
if [[ ! -d "$HOME/.cache/vimfiles/repos/github.com/Shougo/dein.vim" ]]; then if [[ ! -d "$HOME/.cache/vimfiles/repos/github.com/Shougo/dein.vim" ]]; then
info "Install dein.vim" info "Install dein.vim"
@ -89,7 +100,9 @@ install_package_manager () {
success "dein.vim installation done" success "dein.vim installation done"
fi fi
} }
# }}}
# install_neovim {{{
install_neovim () { install_neovim () {
if [[ -d "$HOME/.config/nvim" ]]; then if [[ -d "$HOME/.config/nvim" ]]; then
if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then
@ -105,7 +118,9 @@ install_neovim () {
success "Installed SpaceVim for neovim" success "Installed SpaceVim for neovim"
fi fi
} }
# }}}
# uninstall_vim {{{
uninstall_vim () { uninstall_vim () {
if [[ -d "$HOME/.vim" ]]; then if [[ -d "$HOME/.vim" ]]; then
if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then
@ -122,7 +137,9 @@ uninstall_vim () {
success "Recover from $HOME/.vimrc_back" success "Recover from $HOME/.vimrc_back"
fi fi
} }
# }}}
# uninstall_neovim {{{
uninstall_neovim () { uninstall_neovim () {
if [[ -d "$HOME/.config/nvim" ]]; then if [[ -d "$HOME/.config/nvim" ]]; then
if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then
@ -135,7 +152,9 @@ uninstall_neovim () {
fi fi
fi fi
} }
# }}}
# check_requirements {{{
check_requirements () { check_requirements () {
info "Checking Requirements for SpaceVim" info "Checking Requirements for SpaceVim"
if hash "git" &>/dev/null; then if hash "git" &>/dev/null; then
@ -171,7 +190,9 @@ check_requirements () {
info "Checking true colors support in terminal:" info "Checking true colors support in terminal:"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/JohnMorales/dotfiles/master/colors/24-bit-color.sh)" sh -c "$(curl -fsSL https://raw.githubusercontent.com/JohnMorales/dotfiles/master/colors/24-bit-color.sh)"
} }
# }}}
# usage {{{
usage () { usage () {
echo "SpaceVim install script : V ${Version}" echo "SpaceVim install script : V ${Version}"
echo "" echo ""
@ -201,9 +222,43 @@ usage () {
echo "" echo ""
echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --uninstall" echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --uninstall"
} }
# }}}
# install_done {{{
install_done () {
echo ""
echo "Almost done!"
echo "=============================================================================="
echo "== Open Vim and it will install the plugins automatically =="
echo "=============================================================================="
echo ""
echo "That's it. Thanks for installing SpaceVim. Enjoy!"
echo ""
}
# }}}
# welcome {{{
welcome () {
echo " /###### /## /##/## "
echo " /##__ ## | ## | #|__/ "
echo " | ## \__/ /###### /###### /####### /######| ## | ##/##/######/#### "
echo " | ###### /##__ ##|____ ##/##_____//##__ #| ## / ##| #| ##_ ##_ ##"
echo " \____ #| ## \ ## /######| ## | ########\ ## ##/| #| ## \ ## \ ##"
echo " /## \ #| ## | ##/##__ #| ## | ##_____/ \ ###/ | #| ## | ## | ##"
echo " | ######| #######| ######| ######| ####### \ #/ | #| ## | ## | ##"
echo " \______/| ##____/ \_______/\_______/\_______/ \_/ |__|__/ |__/ |__/"
echo " | ## "
echo " | ## "
echo " |__/ "
echo " version : 0.7.0-dev by : spacevim.org "
}
# }}}
# download_font {{{
download_font () { download_font () {
url="https://raw.githubusercontent.com/wsdjeg/DotFiles/master/local/share/fonts/$1" url="https://raw.githubusercontent.com/wsdjeg/DotFiles/master/local/share/fonts/$1"
path="$HOME/.local/share/fonts/$1" path="$HOME/.local/share/fonts/$1"
@ -217,6 +272,9 @@ download_font () {
fi fi
} }
# }}}
# install_fonts {{{
install_fonts () { install_fonts () {
if [[ ! -d "$HOME/.local/share/fonts" ]]; then if [[ ! -d "$HOME/.local/share/fonts" ]]; then
mkdir -p $HOME/.local/share/fonts mkdir -p $HOME/.local/share/fonts
@ -245,17 +303,13 @@ install_fonts () {
mkfontdir "$HOME/.local/share/fonts" mkfontdir "$HOME/.local/share/fonts"
mkfontscale "$HOME/.local/share/fonts" mkfontscale "$HOME/.local/share/fonts"
fi fi
echo "Done!"
echo ""
echo "Almost done!"
echo "=============================================================================="
echo "== Open Vim and it will install the plugins automatically =="
echo "=============================================================================="
echo ""
echo "That's it. Thanks for installing SpaceVim. Enjoy!"
echo ""
} }
# }}}
### main {{{
main () {
if [ $# -gt 0 ] if [ $# -gt 0 ]
then then
case $1 in case $1 in
@ -296,11 +350,20 @@ then
msg "${Version}" msg "${Version}"
exit 0 exit 0
esac esac
fi else
# if no argv, installer will install SpaceVim welcome
need_cmd 'git' need_cmd 'git'
fetch_repo fetch_repo
install_vim install_vim
install_neovim install_neovim
install_package_manager install_package_manager
install_fonts install_fonts
install_done
fi
}
# }}}
main $@
# vim:set foldenable foldmethod=marker: