又是一个名叫草泥马的项目:thefuck

被顶了一下,今天看了一下。
准备把评论区某我的拉出来批。
对,就是@laike9m
张口国人闭口国人的言论就不说了,阴阳怪气的在下面说这说那。
本文原文所有来自thefuck的readme,没有参考任何第二手资料!
其余任何网站有雷同,所有是来自本文!
例如oschina的收录:https://www.oschina.net/p/the...
例如知名爬取了的oschina的所有数据的open-open:http://www.open-open.com/lib/...
例如http://www.genshuixue.com/i-c...
例如https://www.zhihu.com/questio...php

通常而言,能受到普遍关注的开源项目分为这么几类:html

  • 分离出去的项目,例如 io.jspython

  • 解决了痛点的项目,例如 jQuerylinux

  • 提升效率的项目,例如 Anjular.jsgit

  • 大公司的项目或者原本就特别火的项目,例如 .NETgithub

固然也有脑洞大开的项目,好比 SegmentFault 上以前介绍过的《编程语言中的精品——草泥马语》。(你还记得吗?)web

更好比,今天要讲的主角:thefuckdocker

开发者都或多或少接触过 linux 接触过命令行,固然确定也都被命令行狠狠地“fuck”过。我不少时候都是微不足道的缘由致使了命令行出错,例如将 python 输入成 ptyhon,例如将 ls -alh 输入成 ls a-lh而致使出错,这个时候我会想说:“fuck”。shell

起源

开发 thefuck 的这位同仁,恐怕也常常会有这种不和谐的状况。所以开发了这个软件 thefuck。编程

thefuck 不只仅能修复字符输入顺序的错误,在不少别的你想说“fuck”的状况下,thefuck 依然有效。

例如如下状况。

案例

任何状况下你想说“我操”,你均可以用获得 thefuck。

例如:

ls 和 sl

使用过 ubuntu 的开发者不少都知道有这么一条命令:sl。这条命令是在你将 ls 错误地输成 sl 时,会在屏幕上快速驶过一辆火车。固然,有了 thefuck,sl 彷佛也能够退休了。

➜ sl
The program 'sl' is currently not installed. You can install it by typing:
sudo apt-get install sl
➜ fuck
ls #修正
a.go                   b.php           dockerui      jekyll-casper  main.go  PureBlog   sss.png                              typecho
a.php                  c-hash          Font-Awesome  jekyll-pure    mili     signal.c   TeamTalk                             upload
bii-ubuntu-64_3_0.deb  Dockerfile      harmony       JekyllPure     ngircd   signal.c~  tingyun-agent-php-latest.x86_64.deb  web.go
blog                   Dockerfile.bak  hashmap       kasper         php-src  sss.jpg    tipi                                 zerver

忘记 sudo

➜ 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

➜ 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)
...

选项修正

➜ git brnch
git: 'brnch' is not a git command. See 'git --help'.

Did you mean this?
    branch

➜ fuck
git branch
* master

其余

thefuck 还有其余不少种用法,就等着你去发现。

安装

安装需求

  • python (2.7+ or 3.3+)

  • pip

  • python-dev

安装方法

  1. 可使用 pip 安装:sudo pip install thefuck
    或者使用 OS X、Ubuntu、Arch 的包管理器安装

  2. 安装后配置
    bash:

    alias fuck='eval $(thefuck $(fc -ln -1)); history -r'

    Zsh、Fish 和 PowerShell 的 配置方法见这里

更新

更新到最新的 thefuck 的方法很是简单:

sudo pip install thefuck --upgrade

其余

软件原理

前面说了那么多用法,
那么有人以为 thefuck 可能只是一个用来
thefuck 进行命令修复的模块名和对应的修复原理以下:

  1. brew_unknown_command:修复 brew 命令,例如将 brew docto 修复为 brew doctor

  2. cd_parent:将 cd.. 修正为 cd ..

  3. cd_mkdir:cd 进入不存在的目录时尝试建立目录。

  4. cp_omitting_directory:cp 时添加 -a 选项

  5. fix_alt_space:将全部的的Alt+Space 修正为 Space

  6. git_add:修正没有 git add 的状况。

  7. git_checkout:git checkout 不存在的分支以前尝试建立分支。

  8. git_no_command:修正错误的选项,例如 git brnch

  9. git_push:若是 push 失败,尝试将 git push 修正为 git push --set-upstream origin $branch

  10. has_exists_script:为全部的提示不存在的命令尝试添加 ./ 前缀。

  11. lein_not_task:修正 lein,例如 lein rpl

  12. mkdir_p:mkdir 时尝试添加 -p 选项。

  13. no_command:修正不存在的命令,例如 vom 修正为 vim

  14. man_no_space:将没有空格的 man 命令添加空格,例如 mandiff 修正为 man diff

  15. pacman:arch 系统上,若是使用没有安装的软件,尝试使用 pacman 或者 yaourt 安装。

  16. pip_unknown_command:修正错误的 pip 命令,例如 pip isntall 修正为 pip install

  17. python_command:当前目录试图执行没有 x 权限的 python 程序时,修复为添加 python 前缀

  18. sl_ls:sl 修正为 ls

  19. rm_dir:若是删除文件夹,为 rm 添加 -rf 选项。

  20. ssh_known_hosts:若是远程主机公钥不匹配,尝试将远程主机公钥从 know_hosts 中移除。

  21. sudo:若是提示没有权限,尝试添加 sudo

  22. switch_layout:将键盘布局修正为英语布局。

  23. apt_get:若是不存在命令,尝试使用 apt-get 包管理器安装。

  24. brew_install:修正 brew install 的格式。

  25. composer_not_command:修正 composer 命令。

没有启用的模块:

  1. ls_lah:为 ls 添加 -alh 选项。

  2. rm_root:为 rm -rf / 添加 --no-preserve-root 选项。

自定义规则

固然,你也能够自定义修正规则
一个自定义规则的案例:

def match(command, settings):
    return ('permission denied' in command.stderr.lower()
            or 'EACCES' in command.stderr)
# 获取 stderr 中的字符串和程序返回值(errno),

# 修正规则(命令前添加 sudo)
def get_new_command(command, settings):
    return 'sudo {}'.format(command.script)

# 如下为可选项
# 默认是否开启
enabled_by_default = True
# 附加命令
def side_effect(command, settings):
    subprocess.call('chmod 777 .', shell=True)
# 优先级,数字越大优先级越低。
priority = 1000

使用须知

虽然 thefuck 带来了不少便利,不过仍然建议注意这件事情:

thefuck 会给出的修正后的命令,可是默认状况下你看到它们的时候,命令都已经默认执行了。
大部分状况下,thefuck 可能给出的是正确的修正,可是小部分状况下,给出的修正并非你想要的。
因此建议将 ~/.thefuck/settings.py 中的设置改成 require_confirmation = True,这样能够本身决定是否执行修正后的命令。

相关文章
相关标签/搜索