一个好玩的 Terminal 插件

推荐一个好玩的终端插件,名字叫:thefuck。回想下每次把 git status 写成 git stats, git branch 写成 git brunch 的懊恼,虽然每次重新输入并不会花费太多时间,然而输错的瞬间你可能最容易脱口而出的就是 “fuck” 了。那么当输入有误时,假如你能任性的敲入 fuck,终端乖乖替你完成正确的输入,是不是很解气?

这就是 the fuck 插件的主要作用。

安装

  • 在 OS X 下可以使用 Homebrew 来安装:
1
brew install thefuck
  • 这个时候如果直接写错,敲入 fuck,发现并不成功,提示说:
1
2
3
Seems like fuck alias isn't configured!
Please put eval $(thefuck --alias) in your ~/.zshrc.
More details - https://github.com/nvbn/thefuck#manual-installation

好吧,按照提示,将 alias 内容拷贝到 zshrc 里,并让其生效。

  • 然后就能使用了

下面是官方的几个例子:

1
2
3
4
5
6
7
8
9
➜ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

➜ fuck
sudo apt-get install vim [enter/↑/↓/ctrl+c]
[sudo] password for nvbn:
Reading package lists... Done
...
1
2
3
4
5
6
7
8
9
10
➜ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

➜ fuck
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
Counting objects: 9, done.
...
1
2
3
4
5
6
7
8
9
10
➜ puthon
No command 'puthon' found, did you mean:
 Command 'python' from package 'python-minimal' (main)
 Command 'python' from package 'python3' (main)
zsh: command not found: puthon

➜ fuck
python [enter/↑/↓/ctrl+c]
Python 3.4.2 (default, Oct  8 2014, 13:08:17)
...
1
2
3
4
5
6
7
8
9
➜ git brnch
git: 'brnch' is not a git command. See 'git --help'.

Did you mean this?
    branch

➜ fuck
git branch [enter/↑/↓/ctrl+c]
* master

安装以及使用的细节在项目的 Github 地址 可以看到,支持诸多特性,你甚至可以自己定义规则。