zsh 介绍
zsh 是 shell 语言类型,兼容 bash,提供强大的命令行功能,比如 tab 补全,自动纠错功能等。缺点就是配置太麻烦,好在有一个叫做 oh-my-zsh
的开源项目,很好的弥补了这一缺陷,只需要修修改改配置文件,就能很顺手。
安装 zsh
安装方式我使用: brew install zsh
。
替换 bash 的方式: chsh -s /bin/zsh
。关闭终端,再次打开即为 zsh。
注意:之前我们使用 bash,我们为了使用 brew 安装的软件,修改了 ~/.bash_prorile
文件,新的 zsh 自己也有配置文件,是 ~/.zshrc
,需要将配置拷贝到 ~/.zshrc
中。
或者在安装完 oh-my-zsh 后,执行 echo export PATH='/usr/local/bin:$PATH' >> ~/.zshrc
。
oh-my-zsh
由于 zsh 的配置是很复杂的,所以有这个一个开源项目 oh-my-zsh ,帮助我们简化 zsh 的配置。
官网有自动安装的方法,我选择的是: curl -L http://install.ohmyz.sh | sh
。
安装完成后,重启终端就能看到界面的变化了。zsh 的配置文件是 ~/.zshrc
,配色对应的是 ZSH_THEME
.
zshrc
zshrc 是 zsh 的配置文件,我会在此添加一些 alias 设置。比如:
alias st='open -a "Sublime Text"'
oh-my-zsh 插件
oh-my-zsh 的强大之处还在于提供了完善的插件系统。相关的文件存储在 ~/.oh-my-zsh/plugins
中,默认提供了 100 多种。。。
默认提供的插件是 git,需要添加的话,修改 ~/.zshrc
中 plugins=(git autojump)
即可。
自动跳转
z 和 autojump 。是两个可以实现自动跳转的插件,都是可以通过 brew 下载的。
我目前使用的是 autojump
,通过 brew install autojump
下载,并且在 ~/.zshrc
中修改 plugins=(git autojump)
。重启终端。
使用就可以使用 j 来代替 cd 命令了,并可以添加自定义目录,具体使用说明参考 autojump 的文档或者 autojump --help
。
fasd
fasd , 功能上和 z, autojump 差不多,功能和速度上更优。它会按照访问的频率记录下文件,帮助用户快速访问。
安装还是通过 brew: brew install fasd
,安装之后,我安装官网的步骤,执行了: eval "$(fasd --init auto)"
, 且在 zshrc 中开启对应的配置: plugins=(git fasd)
, 重启终端即可使用。
asd comes with some useful aliases by default:
alias a='fasd -a' # any
alias s='fasd -si' # show / search / select
alias d='fasd -d' # directory
alias f='fasd -f' # file
alias sd='fasd -sid' # interactive directory selection
alias sf='fasd -sif' # interactive file selection
alias z='fasd_cd -d' # cd, same functionality as j in autojump
alias zz='fasd_cd -d -i' # cd with interactive selection
Example:
f foo # list frecent files matching foo
a foo bar # list frecent files and directories matching foo and bar
f js$ # list frecent files that ends in js
f -e vim foo # run vim on the most frecent file matching foo
mplayer `f bar` # run mplayer on the most frecent file matching bar
z foo # cd into the most frecent directory matching foo
open `sf pdf` # interactively select a file matching pdf and launch `open`
参考资料
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

上一篇: brew 介绍
下一篇: 彻底找到 Tomcat 启动速度慢的元凶
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论