在微博上看到的, 在 Mac 或者 Linux 下经常输错命令, 很让人烦躁. 于是有人用 Python 语言写了一个 fuck 命令来解决这种问题.

例如我们来看看这个项目官方的例子:

➜ 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
[sudo] password for nvbn:
Reading package lists... Done
...
➜ 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
Counting objects: 9, done.
...
➜ 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
Python 3.4.2 (default, Oct  8 2014, 13:08:17)
...

不一而足...

这个时候, fuck 命令就能大显身手了. 效果也很明显, 就跟上面的例子一样, 只要你大喊 "fuck" 就能得到正确的命令.

要安装这个命令很简单, 当然你本身需要安装有 Python 以及 pip, 之后使用 sudo pip install thefuck 即可安装. 之后将 alias fuck='eval $(thefuck $(fc -ln -1)); history -r' 这段话添加到你的 .bashrc 或者 .bash_profile 中就行了.

个人建议: 作为中国人, 建议再添加一句话 alias cao='fuck' ^_^

最后在官方的 repo 里都有详细的说明, 就请自己去官网链接查看咯.

Comments
Write a Comment