ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 2\. 常用工具 本节介绍一些常用的,跟开发没有直接关系的第三方应用及其设置。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#homebrew)[Homebrew](http://brew.sh/) 包管理工具,官方称之为`The missing package manager for OS X`。 安装步骤见官网。 有了 brew 以后,要下载工具,比如 MySQL、Gradle、Maven、Node.js 等工具,就不需要去网上下载了,只要一行命令就能搞定: ```source-shell brew install mysql gradle maven node ``` PS:安装 brew 的时候会自动下载和安装 Apple 的 Command Line Tools。 brew 的替代品有 [MacPorts](https://www.macports.org/),现在基本没人用它。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#homebrew-cask)[Homebrew Cask](https://caskroom.github.io/) brew-cask 允许你使用命令行安装 OS X 应用。比如你可以这样安装 Chrome:`brew cask install google-chrome`。还有 Evernote、Skype、Sublime Text、VirtualBox 等都可以用 brew-cask 安装。 brew-cask 是社区驱动的,如果你发现 brew-cask 上的应用不是最新版本,或者缺少你某个应用,你可以自己提交 pull request。 安装步骤见官网。 应用也可以通过 App Store 安装,而且有些应用只能通过 App Store 安装,比如 Xcode 等一些 Apple 的应用。App Store 没有对应的命令行工具,还需要 Apple ID。倒是更新起来很方便。 几乎所有常用的应用都可以通过 brew-cask 安装,而且是从应用的官网上下载,所以你要安装新的应用时,建议用 brew-cask 安装。如果你不知道应用在 brew-cask 中的 ID,可以先用`brew cask search`命令搜索。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#iterm2)[iTerm2](https://www.iterm2.com/) iTerm2 是最常用的终端应用,是 Terminal 应用的替代品。提供了诸如`Split Panes`等[一群实用特性](https://www.iterm2.com/features.html)。它默认的黑色背景让我毫不犹豫的抛弃了 Terminal。 安装: ```source-shell brew cask install iterm2 ``` 感谢 brew-cask,我们可以通过命令行自动安装 iTerm2 了。 在终端里,除了可以用`⌃E`等快捷键(详见[其他快捷键](https://github.com/macdao/ocds-guide-to-setting-up-mac#%E5%85%B6%E4%BB%96%E5%BF%AB%E6%8D%B7%E9%94%AE))之外,还可以使用`⌥B`、`⌥F`等快捷键(具体可以参考[这里](http://ss64.com/bash/syntax-keyboard.html))。前提是这样设置一下: 选择`Iterm`菜单 > `Preferences` > `Profiles`,选择你在使用的 Profile(默认是`Default`),在`Keys`标签页中把`Left option (⌥) key acts as`和`Right option (⌥) key acts as`都设置成`+ESC`。 在打开新的窗口/标签页的时候,默认情况下新窗口总是 HOME 目录,还需要我每次敲命令才能进入工作目录。如果想要这个新窗口在打开的时候就自动进入工作目录,需要如下设置: 选择`Iterm`菜单 > `Preferences` > `Profiles`,选择你在使用的 Profile(默认是Default),在`General`标签页中的`Working Directory`部分中选择`Reuse previous seesion's directory`。 至此,Terminal 应用已经出色的完成了其历史使命。后面命令行就交给 iTerm2 啦。 在 iTerm2 中双击会自动选中对应的词,三击会选中对应的整行。选中的内容会自动进入剪贴板,不需要再按`⌘C`复制。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#oh-my-zsh)[Oh My Zsh](http://ohmyz.sh/) 默认的 Bash 是黑白的,没有色彩。而 Oh My Zsh 可以带你进入彩色时代。Oh My Zsh 同时提供一套插件和工具,可以简化命令行操作。后面我们会看到很多介绍,你会看到我爱死这家伙了。 安装方法见官网。 目前我使用的插件有:`git z sublime history rbenv bundler rake` Oh My Zsh 使用了 Z shell(zsh),一个和 Bash 相似的 Shell,而非 Bash。 在 Z shell 中,`~/.zshrc`是最重要的配置文件。Oh My Zsh 在安装的时候会把当前环境的`$PATH`写入`~/.zshrc`中。这并不是我期望的行为,因为使用了 brew,我们基本不再需要去定制`$PATH`,而 Oh My Zsh 提供的默认`$PATH`值`$HOME/bin:/usr/local/bin:$PATH`是非常合适的一个值,它把`$HOME/bin`加入了`$PATH`,可以让我们把自己用的脚本放到`$HOME/bin`下。 所以建议把`~/.zshrc`重置: ```source-shell cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc ``` > [2016年6月17号的一次提交](https://github.com/robbyrussell/oh-my-zsh/commit/551abfcbb48a0c001eadef80abc3276af4e9ad26)后,`zshrc.zsh-template`就不再修改`$PATH`了。请找到`# export PATH=$HOME/bin:/usr/local/bin:$PATH`这一行,把前面的`#`去掉。 Oh My Zsh 还有很多[有价值的插件](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins-Overview)。 替代品有 [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish)。基于 [Fishshell](http://fishshell.com/) 。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#stow)[Stow](http://www.gnu.org/software/stow/) GNU stow 是管理符号链接(symlink)的一个小公举。主要用于 symlink 你的 [dotfiles](http://dotfiles.github.io/) 如 emacs,git,fish/zsh 的配置文件。安装只需要 ~~~ brew install stow ~~~ 安装了 stow 之后,我们可以开始 symlink 一些 dotfiles 了。完整使用 stow 和 dotfiles 的流程可以参考 [https://github.com/jcouyang/dotfiles](https://github.com/jcouyang/dotfiles) 当你的 dotfiles 都妥妥的 symlink 到 `~/dotfiles` 后,push 到 github 上就再也不怕换电脑了。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#git-%E5%B8%B8%E7%94%A8%E5%88%AB%E5%90%8D)Git 常用别名 几乎每个人都会使用一些方法比如 Git 别名来提高效率,几乎所有人都会把使用`git st`来代替`git status`。然而这需要手动设置,每个人也都不完全一样。 Oh My Zsh 提供了一套系统别名(alias),来达到相同的功能。比如`gst`作为`git status`的别名。而且 Git 插件是 Oh My Zsh 默认启用的,相当于你使用了 Oh My Zsh,你就拥有了一套高效率的别名,而且还是全球通用的。是不是棒棒哒?下面是一些我常用的别名: | Alias | Command | | --- | --- | | gapa | `git add --patch` | | gc! | `git commit -v --amend` | | gcl | `git clone --recursive` | | gclean | `git reset --hard && git clean -dfx` | | gcm | `git checkout master` | | gcmsg | `git commit -m` | | gco | `git checkout` | | gd | `git diff` | | gdca | `git diff --cached` | | glola | `git log --graph --pretty = format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all` | | gp | `git push` | | grbc | `git rebase --continue` | | gst | `git status` | | gup | `git pull --rebase` | | gwip | `git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit -m "--wip--"` | 完整列表请参考:[https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git](https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git) ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#scroll-reverser)Scroll Reverser 当你在浏览一个很长的网页时,你看完了当前显示的内容,想要看后续的内容,你可以在 Trackpad 上双指上滑,或者鼠标滚轮向上滚动。这是被称作“自然”的滚动方向。 然而在 Windows 里鼠标滚动的行为是相反的:鼠标滚轮向下滚动才会让浏览器显示后续的内容,向上滚动会达到页面的顶部。你可以在 OS X 的系统偏好设置里修改(选择`System Preferences` > `Trackpad`,在`Scroll & Zoom`标签页中不选中`Scroll direction: natural`),但是这样会同时改变鼠标滚轮的方向和 Trackpad 的方向。 要想只改变鼠标滚轮的方向,而保持 Trackpad 依旧是“自然”的,我们需要 Scroll Reverser: ```source-shell brew cask install scroll-reverser ``` PS:这货会让三指点击失效 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#shiftit)ShiftIt 原生 OS X 下只能手动调整窗口大小,所以我们需要窗口管理工具。我用过很多窗口管理工具,可惜大部分工具都存在快捷键冲突的问题(对我来说主要是 IntelliJ IDEA)。ShiftIt 是少见的没有冲突的窗口管理工具: ```source-shell brew cask install shiftit ``` PS:ShiftIt的旧版本需要安装 X11,最新版本已经修正了这个问题。 替代者有 SizeUp,主要快捷键和 ShiftIt 相同。 当然如果喜欢 hacking,[Slate](https://github.com/jigish/slate) 是个不错的 hackable 的窗口管理工具。配置可以参照 [http://thume.ca/howto/2012/11/19/using-slate/](http://thume.ca/howto/2012/11/19/using-slate/) ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#sublime-text-2)Sublime Text 2 安装: ```source-shell brew cask install sublime-text ``` 在命令行中指定使用 Sublime Text 打开某文件,是一个非常常用的功能,一般我们会按照 [OS X Command Line](https://www.sublimetext.com/docs/2/osx_command_line.html) 中所说执行 `ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl` 来增加`subl`链接。但是如果你用 brew-cask 安装的话,恭喜你,你不需要运行这个命令,因为 brew-cask 自动帮你做了这件事情。而且你卸载 Sublime Text 的时候 brew-cask 会自动删掉这个链接。 同时 Oh My Zsh 也提供了 Sublime Text 插件,叫做`sublime`。参考:[https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/sublime](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/sublime),这个插件和通过 brew-cask 安装的 Sublime Text 完美兼容。 替代品有 Atom、TextMate、Sublime Text 3 等,跟 Sublime Text 2 一样,用 brew-cask 安装的话命令行工具会被自动加入`$PATH`。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#macdown)MacDown MacDown 是 Markdown 编辑器。由于 Mou 一直不支持代码高亮,我就转向了 MacDown。完美支持 [GFM](https://help.github.com/articles/github-flavored-markdown/)。 我特别喜欢 [Markdown](https://daringfireball.net/projects/markdown/),我用 Makdown 来写文章(包括本文),写幻灯片([reveal.js](https://github.com/hakimel/reveal.js/))。Markdown 可以让我专注于内容本身,而无需花精力在排版和样式上。 安装: ```source-shell brew cask install macdown ``` ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#z)z 在打开终端后,你是怎么进入项目的工作目录?是`cd xxx`,`⌃R`还是用别名? [z](https://github.com/rupa/z) 工具可以帮你快速进入目录。比如在我的 Mac 上运行`z cask`就会进入`/usr/local/Library/Taps/caskroom/homebrew-cask/Casks`目录。 这货的安装非常方便,甚至都不需要下载任何东西,因为它已经整合在了 Oh My Zsh 中。编辑`~/.zshrc`文件,在`plugins=(git)`这行中加上`z`变成`plugins=(git z)`,然后运行`source ~/.zshrc`重新加载配置文件,就可以使用 z 了。 替代品有 autojump。autojump 需要使用 brew 安装。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#vimium)[Vimium](https://vimium.github.io/) Vimium 是一个 Google Chrome 扩展,让你可以纯键盘操作 Chrome,把你的 Chrome 变成“黑客的浏览器”。 安装方法请参考官方网站。 其他浏览器也有类似的工具,比如 FireFox 的 [KeySnail](https://github.com/mooz/keysnail)。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#lastpass)[LastPass](https://lastpass.com/) LastPass 是管理密码的工具,支持二次验证,提供所有浏览器插件以及 Mac 桌面版本。 最重要的是,它提供 命令行 的版本,可以直接通过 brew 安装 ```source-shell brew install lastpass-cli --with-pinentry ``` 之后,只需要登陆: ```source-shell lpass login you@email.com ``` 就可以拷贝密码或者集成到其他命令中了: ```source-shell lpass show --password gmail.com -c ``` ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#sourcetree)[SourceTree](https://www.sourcetreeapp.com/) SourceTree 是 Atlassian 公司出品的一款优秀的 Git 图形化客户端。如果你发现命令行无法满足你的要求,可以试试 SourceTree。 安装: ```source-shell brew cask install sourcetree ``` 用 brew-cask 安装会自动增加命令行工具`stree`到`$PATH`里。在命令行中输入`stree`可以快速用 SourceTree 打开当前 Git 仓库。详细用法请参见`stree --help`。 ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#cheatsheet)[CheatSheet](http://www.mediaatelier.com/CheatSheet/) CheatSheet 能够显示当前程序的快捷键列表,默认的快捷键是长按`⌘`。 [![CheatSheet](https://camo.githubusercontent.com/e92cfabcadbf461b7af191f57ace06b5f9f73c68/687474703a2f2f7777772e6d656469616174656c6965722e636f6d2f436865617453686565742f696d67732f6d61696e2e706e67)](https://camo.githubusercontent.com/e92cfabcadbf461b7af191f57ace06b5f9f73c68/687474703a2f2f7777772e6d656469616174656c6965722e636f6d2f436865617453686565742f696d67732f6d61696e2e706e67) 安装: ```source-shell brew cask install cheatsheet ``` ### [](https://github.com/macdao/ocds-guide-to-setting-up-mac#alfred)[Alfred](https://www.alfredapp.com/) Mac 用户不用鼠标键盘的必备神器,配合大量 Workflows,习惯之后可以大大减少操作时间。 上手简单,调教成本在后期自定义 Workflows,不过有大量雷锋使用者提供的现成扩展,访问[这里](http://www.alfredworkflow.com/)挑选喜欢的,并可以极其简单地根据自己的需要修改。 安装: ```source-shell brew cask install alfred ```