Zsh 是什么 shell 俗称壳,c 语言编写的命令解析器程序,是用户使用 linux 的桥梁。Linux/Unix 提供了很多种 Shell。常用的 Shell 有这么几种,sh、bash、csh 等。可以通过以下命令,查看系统有几种 shell:
目前常用的 Linux 系统和 macOS X 系统的默认 Shell 都是 bash。但是真正强大的 Shell 是深藏不露的 zsh,史称『终极 Shell』,由于与 bash 相似,功能又有所加强,zsh 在 Linux 社区获得了关注。但因配置过于复杂,所以初期无人问津。直到国外有个程序员开发出了一个能够快速上手的 zsh 项目,叫做「Oh My Zsh」,Github 网址是:https://github.com/ohmyzsh/ohmyzsh
安装 zsh 2020.12.18 更新: 撸了个安装脚本,传送门 -> Github
查看系统中有无 zsh ,以及其版本
1 2 3 $ cat /etc/shells $ zsh --version $ echo $ZSH_VERSION
若系统中没有 zsh ,则需要安装
1 2 3 4 5 $ sudo apt-get install zsh $ sudo yum install zsh $ brew install zsh
修改默认 shell
1 2 3 4 5 $ chsh -s /bin/zsh $ chsh -s /usr/bin/zsh $ chsh -s $(which zsh)
安装 Oh My Zsh 一键安装,方式如下:
1 2 3 4 5 6 7 8 9 10 sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) " sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) " curl -Lo install.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh sh install.sh
美化、插件、配置
以下是自用配置,做个备份
修改主题
修改 ZSH_THEME="robbyrussell"
为 ZSH_THEME="ys"
修改显示方式 1 $ vim ~/.oh-my-zsh/themes/ys.zsh-theme
修改最下面部分为
1 2 3 4 5 6 7 8 9 10 PROMPT=" % {$terminfo [bold]$fg [blue]%} %( %{$fg [white]%}in \ %{$terminfo [bold]$fg [yellow]%}%~%{$reset_color %}\ ${hg_info} \${git_info} \ \ %{$fg [white]%}[%*] $exit_code % {$terminfo [bold]$fg [red]%}$ %{$reset_color %}"
或改为(2020.1.7):
1 2 3 4 5 6 7 8 9 10 11 12 PROMPT=" % {$terminfo [bold]$fg [blue]%} %( %{$fg [white]%}@ \ %{$fg [green]%}morooi's MacBook Pro \ %{$fg[white]%}in \ %{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ ${hg_info}\ ${git_info}\ \ %{$fg[white]%}[%*] $exit_code % {$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
插件:zsh-syntax-highlighting shell 命令的代码高亮,Github 地址:https://github.com/zsh-users/zsh-syntax-highlighting
安装:
Clone this repository in oh-my-zsh’s plugins directory:
1 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-syntax-highlighting
Activate the plugin in ~/.zshrc:
1 plugins=( [plugins...] zsh-syntax-highlighting)
Restart zsh (such as by opening a new instance of your terminal emulator).
插件:zsh-autosuggestions 在输入命令的过程中根据你的历史记录显示你可能想要输入的命令,按 tab 补全。
安装:
Clone this repository into $ZSH_CUSTOM/plugins
(by default ~/.oh-my-zsh/custom/plugins
)
1 git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-autosuggestions
Add the plugin to the list of plugins for Oh My Zsh to load (inside ~/.zshrc
):
1 plugins=(zsh-autosuggestions)
Start a new terminal session.
extract 用于解压任何压缩文件,不必根据压缩文件的后缀名来记忆压缩软件
z 用于目录间快速跳转
添加到 ~/.zshrc
若提示字体颜色显示不正常,执行 1 $ echo "export TERM=xterm-256color" >> ~/.zshrc
自用 .zshrc 文件备份 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 export ZSH="/Users/morooi/.oh-my-zsh" ZSH_THEME="ys" HIST_STAMPS="yyyy-mm-dd" plugins=(git zsh-completions z zsh-syntax-highlighting zsh-autosuggestions extract) source $ZSH /oh-my-zsh.shalias bs="brew search" alias bi="brew install" alias bu="brew rmtree" alias bup="brew upgrade" alias bci="brew install --cask" alias bcup="brew cu -a -f --cleanup" alias bcu="brew uninstall --cask" alias cleanbrewcache="rm -rf /Users/morooi/Library/Caches/Homebrew" export PATH="/usr/local/sbin:$PATH " export JAVA_HOME_8="/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home" export JAVA_HOME_11="/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home" export JAVA_HOME_13="/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home" export JAVA_HOME=$JAVA_HOME_13 alias jdk8="export JAVA_HOME=$JAVA_HOME_8 " alias jdk11="export JAVA_HOME=$JAVA_HOME_11 " alias jdk13="export JAVA_HOME=$JAVA_HOME_13 " export PATH="/usr/local/opt/node@12/bin:$PATH " __conda_setup="$('/usr/local/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null) " if [ $? -eq 0 ]; then eval "$__conda_setup " else if [ -f "/usr/local/miniconda3/etc/profile.d/conda.sh" ]; then . "/usr/local/miniconda3/etc/profile.d/conda.sh" else export PATH="/usr/local/miniconda3/bin:$PATH " fi fi unset __conda_setup