写这个的原因是因为老是装新的虚拟机,每次都要重新配,考虑到之后还会装N次,于是就有了这个脚本。
包括插件:zsh-autosuggestions、zsh-Syntax-highlighting、autojump。
并加载原有bash_aliases,具体看下面代码。
注意:
1.脚本运行安装完oh-my-zsh后,需要手工exit之后才可以继续后续插件的安装。(也可以删除oh-my-zsh官方安装脚本中启动zsh的命令即可不需要输入exit)
2.autojump生效需要手工修改~/.zshrc,在plugins下方增加行autojump,保存退出logoff之后即可生效。
最新和历史版本放在:https://gist.github.com/thinkycx/2e21c3572a8d1fde21aad07a58fcf940
bash脚本:
PS:引用字符串记得用"$stringname",引用home目录需要用"$HOME"而不是~。
- #!/bin/bash
- # author: thinkycx
- # date: 2018-04-30
- # usage: install zsh for one script
- sudo apt-get update -y
- sudo apt-get install git -y
- sudo apt-get install curl -y
- sudo apt-get install zsh -y
- # https://github.com/robbyrussell/oh-my-zsh
- # git config --global --unset http.proxy
- # git config --global --unset https.proxy
- # 终端配置(弃用)
- # http://www.cnblogs.com/yangshiyu/p/6941555.html
- # preferences font ubuntu mono13
- # local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
- # PROMPT='${ret_status}%{$fg[cyan]%}%~%{$reset_color%}$(git_prompt_info)%{$fg[green]%}$ %{$fg[white]%}'
- # ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}(%{$fg[red]%}"
- # ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
- # ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%})"
- #ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
- # need to exit manually
- echo "[!] ENTER exit manually!"
- sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
- bash_aliases=$(cat ~/.zshrc | grep "~/.bash_aliases")
- if [ -z "$bash_aliases" ];then
- echo "[*] add ~/.bash_aliases in ~/.zshrc"
- cat <<EOF >>~/.zshrc
- # add ~/.bash_aliases
- if [ -f ~/.bash_aliases ]; then
- . ~/.bash_aliases
- fi
- EOF
- else
- echo "[*] ~/.bash_aliases exists in ~/.zshrc"
- fi
- # install zsh-autosuggestions
- if [ ! -d "$HOME/.zsh/zsh-autosuggestions" ]; then
- git clone git://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
- echo "source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
- else
- echo "[*] ~/.zsh/zsh-autosuggestions exists..."
- fi
- # install zsh-Syntax-highlighting
- if [ ! -d "$HOME/.zsh/zsh-Syntax-highlighting" ]; then
- git clone https://github.com/zsh-users/zsh-Syntax-highlighting.git ~/.zsh/zsh-Syntax-highlighting
- echo "source ~/.zsh/zsh-Syntax-highlighting/zsh-Syntax-highlighting.zsh" >> ~/.zshrc
- else
- echo "[*] ~/.zsh/zsh-Syntax-highlighting exists...."
- fi
- sudo apt-get install autojump
- echo "[!] need to add autojump in ~/.zshrc plugin and logoff manually!"
- # change zsh to default shell
- sudo chsh -s /bin/zsh
- echo "[*] ENJOY!"
- /bin/zsh
- # uninstall
- # rm -rf ~/.oh-my-zsh