再也不用担心敲错命令了,


相信大家每个人都有敲错过命令的时候,把python 输入成 puthon. 手速过快把ls -alh 输入成 ls a-lh等等等,这时候是不是想拍一下键盘说一声fuck.

有一个同事就开发了一个thefuck的项目,可纠正先前控制台命令中的错误。让我们能愉快的工作下去.

安装

在 macOS 或 Linux 上,您可以通过Homebrew安装The Fuck:

  1. brew install thefuck 

在 FreeBSD 上,使用以下命令安装The Fuck:

  1. pkg install thefuck 

Centos系统/Ubuntu系统

  1. pip install thefuck 

配置 

  1. #编辑bashrc配置文件  
  2. vim ~/.bashrc  
  3. #在文件尾加入一行给thefuck取别名fuck  
  4. eval "$(thefuck --alias fuck)"  
  5. #使生效  
  6. source ~/.bashrc 

Ubuntu安装vim

忘记加sudo,fuck一下就好了.

  1. apt-get install vim  
  2. E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)  
  3. E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?  
  4. ➜ fuck  
  5. sudo apt-get install vim [enter/↑/↓/ctrl+c]  
  6. [sudo] password for nvbn:  
  7. Reading package lists... Done 

git 首次push

  1. ➜ git push  
  2. fatal: The current branch master has no upstream branch.  
  3. To push the current branch and set the remote as upstream, use  
  4.     git push --set-upstream origin master  
  5. ➜ fuck  
  6. git push --set-upstream origin master [enter/↑/↓/ctrl+c]  
  7. Counting objects: 9, done.  
  8. ... 

把python敲成puthon

  1. ➜ puthon  
  2. No command 'puthon' found, did you mean:  
  3.  Command 'python' from package 'python-minimal' (main)  
  4.  Command 'python' from package 'python3' (main)  
  5. zsh: command not found: puthon  
  6. ➜ fuck  
  7. python [enter/↑/↓/ctrl+c]  
  8. Python 3.4.2 (default, Oct  8 2014, 13:08:17)  
  9. ... 

thefuck原理

其实TheFuck的原理就是规则匹配(正则表达式),如果找到匹配规则的命令,则创建一个命令给用户选择或直接运行。

  1. cat_dir - 当你尝试cat目录的时候,用ls替换cat;  
  2. cd_correction – 拼写检查和纠正失败的cd命令;  
  3. cd_mkdir – 在进入目录之前创建目录;  
  4. cd_parent – 更改 cd.. 为cd ..;  
  5. dry – 修复类似的重复问题:git git push;  
  6. fix_alt_space – 用空格字符代替Alt + Space;  
  7. # 还有很多可以参考https://github.com/nvbn/thefuck#how-it-works  

相关内容

    暂无相关文章