shell的类型有很多种,linux下默认的是bash,虽然bash的功能已经很强大,但对于以懒惰为美德的程序员来说,bash的提示功能不够强大,界面也不够炫,并非理想工具。
而zsh的功能极其强大,只是配置过于复杂,起初只有极客才在用。后来,有个穷极无聊的程序员可能是实在看不下去广大猿友一直只能使用单调的bash, 于是他创建了一个名为oh-my-zsh的开源项目
今天,且随我一起探索zsh和oh-my-zsh安装使用吧…
正式安装之前,可以在终端输入以下命令,查看系统现有的shell:
cat /etc/shells我的现有shell有如下几个:
# /etc/shells: valid login shells /bin/sh /bin/dash /bin/bash /bin/rbash可以在终端,输入以下命令查看终端目前使用的shell:
echo $SHELL我的输出为:
/bin/bash在终端直接输入以下命令,进行安装zsh:
sudo apt install zsh安装完毕后,输入以下命令可以查看zsh的版本:
zsh --version我的版本是:zsh 5.1.1 (x86_64-ubuntu-linux-gnu
当然也可以再次查看系统的shell,命令如下:
cat /etc/shells我的shell有如下几个:
# /etc/shells: valid login shells /bin/sh /bin/dash /bin/bash /bin/rbash /bin/zsh /usr/bin/zsh输入以下命令设置zsh为终端默认shell:
chsh -s $(which zsh)然后进行重启:
reboot第一次进入终端,会有如下提示信息:
This is the Z Shell configuration function for new users, zsh-newuser-install. You are seeing this message because you have no zsh startup files (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory ~). This function can help you with a few settings that should make your use of the shell easier. You can: (q) Quit and do nothing. The function will be run again next time. (0) Exit, creating the file ~/.zshrc containing just a comment. That will prevent this function being run again. (1) Continue to the main menu. (2) Populate your ~/.zshrc with the configuration recommended by the system administrator and exit (you will need to edit the file by hand, if so desired). --- Type one of the keys in parentheses ---直接键入2即可,会自动填充推荐的配置到~/.zshrc中,需要提醒的一点是,~/.zshrc之后将完全代替~/.bashrc,当设置环境变量时尤其需要注意!
完成后,终端状态如下图所示:
使用以下任一条命令,即可完成oh-my-zsh的下载安装一条龙服务:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" or sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"当前步骤安装完毕后,终端如下图所示:
输入以下命令,通过vim打开~/.zshrc配置文件:
sudo vim ~/.zshrc找到其中的ZSH_THEME选项,将robbyrussell更改为agnoster,注意不要加空格!
ZSH_THEME="agnoster"而后保存退出~/.zshrc配置文件,然后输入以下命令生效主题:
source ~/.zshrc当前步骤安装完毕后,终端如下图所示:
可看到有乱码出现,这是因为字体不支持的原因,下载Powerline字体字体即可解决!
[agnoster-pyenv主题](https://gist.github.com/loganasherjones/bd9b7614f80b96cf700fd60e9e256f41):可以显示pyenv的python版本,直接下载文件,然后更改名字为agnoster-pyenv.zsh-theme,然后放置到/home/clay/.oh-my-zsh/themes目录,像上面一面更改~/.zshrc中的ZSH_THEME即可!
克隆Powerline项目最近一次commit的一个分支,注意--depth=1用法:
git clone https://github.com/powerline/fonts.git --depth=1然后安装Powerline字体:
cd fonts ./install.sh安装完毕后,清理安装包:
cd .. rm -rf fonts在终端右击依次选择:配置文件 -> 配置文件首选项 -> 自定义字体 -> Ubuntu Mono derivative Powerline Regular,如下图所示:
在终端,输入如下命令
echo "\ue0b0 \u00b1 \ue0a0 \u27a6 \u2718 \u26a1 \u2699"正常显示,如下图所示:
输入以下命令,可以查看oh-my-zsh自带插件:
ls $ZSH/plugins/自带插件详细介绍:
Plugins自带插件启用方法:
STEP #1:在~/.zshrc的plugins中加入插件名。【插件与插件之间空格隔开】STEP #2:执行source ~/.zshrc。自带插件推荐:
跟踪最常访问的目录 - z网页搜索插件 - web-search plugin解压压缩包插件 - extract语法高亮插件 - zsh-syntax-highlighting:
STEP #1:git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlightingSTEP #2:在~/.zshrc的plugins中加入插件名:zsh-syntax-highlightingSTEP #3:source ~/.zshrc命令补全插件 - zsh-autosuggestions
STEP #1:git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestionsSTEP #2:在~/.zshrc的plugins中加入插件名:zsh-autosuggestionsSTEP #3:source ~/.zshrc