【bash】一键安装zsh脚本

前端之家收集整理的这篇文章主要介绍了【bash】一键安装zsh脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

写这个的原因是因为老是装新的虚拟机,每次都要重新配,考虑到之后还会装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"而不是~。

  1. #!/bin/bash
  2. # author: thinkycx
  3. # date: 2018-04-30
  4. # usage: install zsh for one script
  5.  
  6. sudo apt-get update -y
  7. sudo apt-get install git -y
  8. sudo apt-get install curl -y
  9. sudo apt-get install zsh -y
  10. # https://github.com/robbyrussell/oh-my-zsh
  11. # git config --global --unset http.proxy
  12. # git config --global --unset https.proxy
  13.  
  14. # 终端配置(弃用)
  15. # http://www.cnblogs.com/yangshiyu/p/6941555.html
  16. # preferences font ubuntu mono13
  17. # local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
  18. # PROMPT='${ret_status}%{$fg[cyan]%}%~%{$reset_color%}$(git_prompt_info)%{$fg[green]%}$ %{$fg[white]%}'
  19.  
  20. # ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}(%{$fg[red]%}"
  21. # ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
  22. # ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%})"
  23. #ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
  24.  
  25. # need to exit manually
  26. echo "[!] ENTER exit manually!"
  27. sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  28.  
  29.  
  30. bash_aliases=$(cat ~/.zshrc | grep "~/.bash_aliases")
  31. if [ -z "$bash_aliases" ];then
  32. echo "[*] add ~/.bash_aliases in ~/.zshrc"
  33. cat <<EOF >>~/.zshrc
  34.  
  35. # add ~/.bash_aliases
  36. if [ -f ~/.bash_aliases ]; then
  37. . ~/.bash_aliases
  38. fi
  39. EOF
  40. else
  41. echo "[*] ~/.bash_aliases exists in ~/.zshrc"
  42. fi
  43.  
  44. # install zsh-autosuggestions
  45. if [ ! -d "$HOME/.zsh/zsh-autosuggestions" ]; then
  46. git clone git://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
  47. echo "source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
  48. else
  49. echo "[*] ~/.zsh/zsh-autosuggestions exists..."
  50. fi
  51.  
  52. # install zsh-Syntax-highlighting
  53. if [ ! -d "$HOME/.zsh/zsh-Syntax-highlighting" ]; then
  54. git clone https://github.com/zsh-users/zsh-Syntax-highlighting.git ~/.zsh/zsh-Syntax-highlighting
  55. echo "source ~/.zsh/zsh-Syntax-highlighting/zsh-Syntax-highlighting.zsh" >> ~/.zshrc
  56. else
  57. echo "[*] ~/.zsh/zsh-Syntax-highlighting exists...."
  58. fi
  59.  
  60. sudo apt-get install autojump
  61. echo "[!] need to add autojump in ~/.zshrc plugin and logoff manually!"
  62.  
  63.  
  64. # change zsh to default shell
  65. sudo chsh -s /bin/zsh
  66. echo "[*] ENJOY!"
  67.  
  68. /bin/zsh
  69.  
  70.  
  71. # uninstall
  72. # rm -rf ~/.oh-my-zsh

猜你在找的Bash相关文章