diff --git a/install.sh b/install.sh index 281d30c68..17ff22bbc 100755 --- a/install.sh +++ b/install.sh @@ -18,11 +18,9 @@ need_cmd () { fetch_repo () { if [[ -d "$HOME/.SpaceVim" ]]; then git -C "$HOME/.SpaceVim" pull - ret=$? echo -e "${Blue}Successfully update SpaceVim${Color_off}" else git clone https://github.com/SpaceVim/SpaceVim.git "$HOME/.SpaceVim" - ret=$? echo -e "${Blue}Successfully clone SpaceVim${Color_off}" fi } @@ -30,7 +28,6 @@ fetch_repo () { install_vim () { if [[ -f "$HOME/.vimrc" ]]; then mv "$HOME/.vimrc" "$HOME/.vimrc_back" - ret=$? echo -e "${Blue}BackUp $HOME/.vimrc${Color_off}" fi @@ -39,7 +36,6 @@ install_vim () { echo -e "${Blue}Installed SpaceVim for vim${Color_off}" else mv "$HOME/.vim" "$HOME/.vim_back" - ret=$? echo -e "${Blue}BackUp $HOME/.vim${Color_off}" ln -s "$HOME/.SpaceVim" "$HOME/.vim" echo -e "${Blue}Installed SpaceVim for vim${Color_off}" @@ -56,7 +52,6 @@ install_neovim () { echo -e "${Blue}Installed SpaceVim for neovim${Color_off}" else mv "$HOME/.config/nvim" "$HOME/.config/nvim_back" - ret=$? echo -e "${Blue}BackUp $HOME/.config/nvim${Color_off}" ln -s "$HOME/.SpaceVim" "$HOME/.config/nvim" echo -e "${Blue}Installed SpaceVim for neovim${Color_off}" @@ -67,12 +62,83 @@ install_neovim () { fi } +uninstall_vim () { + if [[ -d "$HOME/.vim" ]]; then + if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then + rm "$HOME/.vim" + echo -e "${Blue}Uninstall SpaceVim for vim${Color_off}" + if [[ -d "$HOME/.vim_back" ]]; then + mv "$HOME/.vim_back" "$HOME/.vim" + echo -e "${Blue}Recover $HOME/.vim${Color_off}" + fi + fi + fi + if [[ -f "$HOME/.vimrc_back" ]]; then + mv "$HOME/.vimrc_back" "$HOME/.vimrc" + echo -e "${Blue}Recover $HOME/.vimrc${Color_off}" + fi +} + +uninstall_neovim () { + if [[ -d "$HOME/.config/nvim" ]]; then + if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then + rm "$HOME/.config/nvim" + echo -e "${Blue}Uninstall SpaceVim for neovim${Color_off}" + if [[ -d "$HOME/.config/nvim_back" ]]; then + mv "$HOME/.config/nvim_back" "$HOME/.config/nvim" + echo -e "${Blue}Recover $HOME/.config/nvim${Color_off}" + fi + fi + fi +} + +usage () { + echo "SpaceVim install script : V 0.1.0-dev" + echo " Install SpaceVim for vim and neovim" + echo " curl -sLf https://raw.githubusercontent.com/SpaceVim/SpaceVim/dev/install.sh | bash" + echo " Install SpaceVim for vim only or neovim only" + echo " curl -sLf https://raw.githubusercontent.com/SpaceVim/SpaceVim/dev/install.sh | bash -s -- install vim" + echo " or" + echo " curl -sLf https://raw.githubusercontent.com/SpaceVim/SpaceVim/dev/install.sh | bash -s -- install neovim" + echo " Uninstall SpaceVim" + echo " curl -sLf https://raw.githubusercontent.com/SpaceVim/SpaceVim/dev/install.sh | bash -s -- uninstall" +} + + +if [ $# -gt 0 ] +then + case $1 in + uninstall) + uninstall_vim + uninstall_neovim + exit 0 + ;; + install) + 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 + esac +fi +# if no argv, installer will install SpaceVim need_cmd 'git' - fetch_repo - install_vim - install_neovim - -