开拓者都或多或少打仗过 linux 打仗过命令行,当然肯定也都被命令行狠狠地“fuck”过。我很多时候都是微不足道的缘故原由导致了命令行出错,例如将 python 输入成 ptyhon,例如将 ls -alh 输入成 ls a-lh而导致出错,这个时候我会想说:“fuck”。
起源开拓 thefuck 的这位同仁,恐怕也常常会有这种不和谐的情形。因此开拓了这个软件 thefuck。
thefuck 不仅仅能修复字符输入顺序的缺点,在很多别的你想说“fuck”的情形下,thefuck 依然有效。

例如以下情形。
案例任何情形下你想说“我操”,你都可以用得到 thefuck。
例如:
ls 和 sl利用过 ubuntu 的开拓者很多都知道有这么一条命令:sl。这条命令是在你将 ls 缺点地输成 sl 时,会在屏幕上快速驶过一辆火车。当然,有了 thefuck,sl 彷佛也可以退休了。
➜ slThe program 'sl' is currently not installed. You can install it by typing:sudo apt-get install sl➜ fuckls #改动a.go b.php dockerui jekyll-casper main.go PureBlog sss.png typechoa.php c-hash Font-Awesome jekyll-pure mili signal.c TeamTalk uploadbii-ubuntu-64_3_0.deb Dockerfile harmony JekyllPure ngircd signal.c~ tingyun-agent-php-latest.x86_64.deb web.goblog Dockerfile.bak hashmap kasper php-src sss.jpg tipi zerver忘却 sudo
➜ apt-get install vimE: 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?➜ fucksudo apt-get install vim[sudo] password for nvbn:Reading package lists... Done操作 git
➜ git pushfatal: 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➜ fuckgit push --set-upstream origin masterCounting objects: 9, done....错输命令
➜ puthonNo command 'puthon' found, did you mean: Command 'python' from package 'python-minimal' (main) Command 'python' from package 'python3' (main)zsh: command not found: puthon➜ fuckpythonPython 3.4.2 (default, Oct 8 2014, 13:08:17)...选项改动
➜ git brnchgit: 'brnch' is not a git command. See 'git --help'.Did you mean this? branch➜ fuckgit branch master其他
thefuck 还有其他很多种用法,就等着你去创造。
安装
安装需求
python (2.7+ or 3.3+)pippython-dev安装方法
可以利用 pip 安装:sudo pip install thefuck或者利用 OS X、Ubuntu、Arch 的包管理器安装。https://github.com/nvbn/thefuck/wiki/Installation安装后配置bash:alias fuck='eval $(thefuck $(fc -ln -1)); history -r'Zsh、Fish 和 PowerShell 的 配置方法见这里:https://github.com/nvbn/thefuck/wiki/Shell-aliases
更新
更新到最新的 thefuck 的方法非常大略:
sudo pip install thefuck --upgrade
其他
软件事理
前面说了那么多用法,
那么有人以为 thefuck 可能只是一个用来
thefuck 进行命令修复的模块名和对应的修复原理如下:
brew_unknown_command:修复 brew 命令,例如将 brew docto 修复为 brew doctorcd_parent:将 cd.. 改动为 cd ..cd_mkdir:cd 进入不存在的目录时考试测验创建目录。cp_omitting_directory:cp 时添加 -a 选项fix_alt_space:将所有的的Alt+Space 改动为 Space。git_add:改动没有 git add 的情形。git_checkout:git checkout 不存在的分支之前考试测验创建分支。git_no_command:改动缺点的选项,例如 git brnch。git_push:如果 push 失落败,考试测验将 git push 改动为 git push --set-upstream origin $branch。has_exists_script:为所有的提示不存在的命令考试测验添加 ./ 前缀。lein_not_task:改动 lein,例如 lein rpl。mkdir_p:mkdir 时考试测验添加 -p 选项。no_command:改动不存在的命令,例如 vom 改动为 vim。man_no_space:将没有空格的 man 命令添加空格,例如 mandiff 改动为 man diffpacman:arch 系统上,如果利用没有安装的软件,考试测验利用 pacman 或者 yaourt 安装。pip_unknown_command:改动缺点的 pip 命令,例如 pip isntall 改动为 pip installpython_command:当前目录试图实行没有 x 权限的 python 程序时,修复为添加 python 前缀sl_ls:sl 改动为 lsrm_dir:如果删除文件夹,为 rm 添加 -rf 选项。ssh_known_hosts:如果远程主机公钥不匹配,考试测验将远程主机公钥从 know_hosts 中移除。sudo:如果提示没有权限,考试测验添加 sudo。switch_layout:将键盘布局改动为英语布局。apt_get:如果不存在命令,考试测验利用 apt-get 包管理器安装。brew_install:改动 brew install 的格式。composer_not_command:改动 composer 命令。没有启用的模块:
ls_lah:为 ls 添加 -alh 选项。rm_root:为 rm -rf / 添加 --no-preserve-root 选项。自定义规则当然,你也可以自定义改动规则:
https://github.com/nvbn/thefuck#creating-your-own-rules
一个自定义规则的案例:
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,这样可以自己决定是否实行改动后的命令。
————————————————————————————————————
想理解更多前沿技能,想获取最新免费编程资源视频源码条记,小伙伴请往下看!
qun号是:八六四,六三四,八四五。qun内有很多开拓工具,很多干货和技能资料分享!
如果您以为此篇文章对您有帮助,欢迎关注微信公众年夜众号:大禹编程,您的支持是对我最大的鼓励!
共同学习,共同进步: