作为一个资深程序猿,在linux、windows和mac下都进行过相当长的一段开发时间,是时候总结一下mac下的一些高效工作Tips了。
第一个要按照的工具是 Homebrew 。
还有它的好兄弟 Homebrew-Cask :
$ brew tap caskroom/cask
用他们可以很方便的安装其他的工具和软件。
用mac开发的话,终端和命令行是每天都要面对的东东,一个好用的终端和shell必不可少。
终端这里推荐 iTerm2 ,除了配色好看之外,还具有一些不错的特性:
窗口管理(这几个命令是通用的):
行内光标快速移动(跟Emace保持一致):
mac系统自带了zsh:
arganzhengs-MacBook-Pro:~ argan$ cat /etc/shells # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using # one of these shells. /bin/bash /bin/csh /bin/ksh /bin/sh /bin/tcsh /bin/zsh
但是一般不是最新版:
arganzhengs-MacBook-Pro:~ argan$ zsh --version zsh 5.0.8 (x86_64-apple-darwin15.0)
可通过 Homebrew 来安装最新版:
$ brew install zsh
mac默认是使用bash: $ echo $SHELL /bin/bash
可以使用如下命令将当前用户的默认shell改成zsh:
$ chsh -s /usr/local/bin/zsh Changing shell for argan. Password for argan: chsh: /usr/local/bin/zsh: non-standard shell
出错了,因为 /usr/local/bin/zsh 不在 /etc/shells 文件中,要把它加进去,或者直接使用/bin/zsh就可以了。
zsh功能强大是公认的,但是由于配置过于复杂,初期无人问津,直到有一天,国外有个穷极无聊的程序员开发出了一个能够让你快速上手的zsh项目,叫做 oh my zsh ,一下子讲zsh的配置简化了很多。
安装就一条简单的命令搞定:
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" Cloning Oh My Zsh... Cloning into '/Users/argan/.oh-my-zsh'... remote: Counting objects: 823, done. remote: Compressing objects: 100% (693/693), done. remote: Total 823 (delta 20), reused 683 (delta 9), pack-reused 0 Receiving objects: 100% (823/823), 559.90 KiB | 184.00 KiB/s, done. Resolving deltas: 100% (20/20), done. Checking connectivity... done. Looking for an existing zsh config... Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh Using the Oh My Zsh template file and adding it to ~/.zshrc Time to change your default shell to zsh! Changing shell for argan. Password for argan: chsh: no changes made __ __ ____ / /_ ____ ___ __ __ ____ _____/ /_ / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ / /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / \____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ /____/ ....is now installed! Please look over the ~/.zshrc file to select plugins, themes, and options. p.s. Follow us at https://twitter.com/ohmyzsh. p.p.s. Get stickers and t-shirts at http://shop.planetargon.com. ➜ arganzheng.github.com git:(master) ✗
按照成功还会自动给你切换默认的shell,真是贴心。
zsh有很多不错的功能,比如: kill
不过 oh my zsh 项目更强大的地方在于它提供了完善的插件体系。相关的文件在~/.oh-my-zsh/plugins目录下,默认提供了100多种,大家可以根据自己的实际学习和工作环境采用,想了解每个插件的功能,只要打开相关目录下的 zsh 文件看一下就知道了。
插件也是在 .zshrc 里配置,找到plugins关键字,你就可以加载自己的插件了。系统默认只是启用了 git,你可以在后面追加内容,例如启用插件 git, autojumps osx, 需要在配置文件中加入如下内容:
plugins=(git autojump osx)
说明autojump插件需要先安装才能使用:
➜ ~ brew install autojump ==> Downloading https://homebrew.bintray.com/bottles/autojump-22.3.0.el_capitan.bottle.tar.gz ######################################################################## 100.0% ==> Pouring autojump-22.3.0.el_capitan.bottle.tar.gz ==> Caveats Add the following line to your ~/.bash_profile or ~/.zshrc file (and remember to source the file to update your current session): [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh If you use the Fish shell then add the following line to your ~/.config/fish/config.fish: [ -f /usr/local/share/autojump/autojump.fish ]; and . /usr/local/share/autojump/autojump.fish zsh completion has been installed to: /usr/local/share/zsh/site-functions ==> Summary :beer: /usr/local/Cellar/autojump/22.3.0: 17 files, 163.8K
记得按照安装后的提示,把下面的配置信息加入~/.zshrc中:
[[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
我来评几句
登录后评论已发表评论数()