更多示例:
➜ 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
...
➜ 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.
...
➜ 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)
...
➜ git brnch
git: 'brnch' is not a git command. See 'git --help'.
Did you mean this?
branch
➜ fuck
git branch [enter/↑/↓/ctrl+c]
* master
➜ lein rpl
'rpl' is not a task. See 'lein help'.
Did you mean this?
repl
➜ fuck
lein repl [enter/↑/↓/ctrl+c]
nREPL server started on port 54848 on host 127.0.0.1 - nrepl://127.0.0.1:54848
REPL-y 0.3.1
...
如果您不害怕盲目地运行已更正的命令, 则可以禁用require_confirmation 设置选项,让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
...
环境要求
- python (3.4+)
- pip
- python-dev
安装
在OS X上,您可以通过Homebrew(或在Linux上通过Linuxbrew)安装The Fuck:
在Ubuntu / Mint上,使用以下命令安装The Fuck:
在FreeBSD上,使用以下命令安装The Fuck:
在Chrome操作系统上,使用chromebrew通过以下命令安装The Fuck:
在其他系统上, 使用来安装The Fuck
或者,您可以使用OS软件包管理器(OS X,Ubuntu,Arch)。
其中 chcp.com 65001 只有在windows环境下才需要运行。
Zsh:
其他的可见:
https://github.com/nvbn/thefuck/wiki/Shell-aliases
要在不进行确认的情况下运行固定命令,请使用
要递归修复命令直到成功,请使用以下
注意:别名功能在The Fuck的v1.34中已更改
下面是简单的 sudo 规则示例:
如果命令运行结果出现 permission denied 或者 EACCES,则执行 sudo xxx.
此外,还可以配置side_effect,如果你配置了enabled_by_default = True,side_effect函数内的操作将会被执行。
或通过环境变量:
目前,即时模式仅支持bash或zsh的Python 3。还必须禁用zsh的自动更正功能,以使其正常工作。
要启用即时模式,添加
brew install thefuck
sudo apt update
sudo apt install python3-dev python3-pip python3-setuptools
sudo pip3 install thefuck
pkg install thefuck
crew install thefuck
pip:
pip install thefuck
配置
接下来需要把这个命令写入到.bash_profile, .bashrc,.zshrc 等启动脚本中。
根据你的终端类型,运行相应的命令即可:
Bash
chcp.com 65001 eval "$(thefuck --alias)"
eval "$(thefuck --alias)"
--yeah选项(或者-y简称,或者--hard如果您特别沮丧):
fuck --yeah
-r选项:
fuck -r
更新中
pip3 install thefuck --upgrade
这个怎么运作
Fuck尝试将前一个命令与规则匹配。如果找到匹配项,则使用匹配的规则创建一个新命令并执行。默认情况下启用以下规则:adb_unknown_command–修复类似拼写错误的命令adb logcta;ag_literal-增加了-Q对ag建议的时候;aws_cli–修复类似拼写错误的命令aws dynamdb scan;az_cli–修复类似拼写错误的命令az providers;cargo–运行cargo build代替cargo;cargo_no_command–修复错误命令,例如cargo buid;cat_dir-替换cat用ls当您尝试cat目录;cd_correction–拼写检查和纠正失败的cd命令;cd_mkdir–在进入目录之前创建目录;cd_parent–更改cd..为cd ..;chmod_x–增加执行位;choco_install–附加巧克力包装的通用后缀;composer_not_command–修正了作曲家的命令名称;cp_create_destination-创建一个新的目录当您尝试cp或mv到一个不存在的一个cp_omitting_directory–-a在cp目录中添加;cpp11–-std=c++11向g++或添加缺失clang++;dirty_untar–修复tar x了当前目录中未解压缩的命令;dirty_unzip–修复unzip了在当前目录中解压缩的命令;django_south_ghost–--delete-ghost-migrations因鬼魂django向南迁移而增加失败;django_south_merge–增加--merge了不一致的django南迁徙;docker_login–执行docker login并重复上一个命令;docker_not_command–修复了错误的docker命令,如docker tags;docker_image_being_used_by_container‐在移除图像之前先移除使用图像的容器;dry–修复类似的重复git git push;fab_command_not_found–修复拼写错误的结构命令;fix_alt_space–用空格字符代替Alt + Space;fix_file–打开您的错误文件$EDITOR;gem_unknown_command–修正错误的gem命令;git_add–修复了“ pathspec’foo’与git已知的任何文件都不匹配。” ;git_add_force-添加--force到git add <pathspec>...当路径.gitignore’d;git_bisect_usage-修复git bisect strt,git bisect goood,git bisect rset,平分时等;git_branch_delete–更改git branch -d为git branch -D;git_branch_delete_checked_out-变化git branch -d给git checkout master && git branch -D试图删除已签出分支的时候;git_branch_exists– offergit branch -d foo,git branch -D foo或git checkout foo在创建已经存在的分支时;git_branch_list–git branch list代替git branch并删除创建的分支;git_checkout–修改分支名称或创建新分支;git_clone_git_clone–替换git clone git clone ...为git clone ...git_commit_amend–git commit --amend先前提交后的报价;git_commit_reset–git reset HEAD~先前提交后的报价;git_diff_no_index–添加--no-index到以前git diff的未跟踪文件上;git_diff_staged–添加--staged到前一个git diff具有意外输出;git_fix_stash–修复git stash命令(拼写错误的子命令和missingsave);git_flag_after_filename–修复fatal: bad flag '...' after filenamegit_help_aliased–修复git help <alias>用别名命令替换的命令;git_hook_bypass-增加--no-verify标志之前的git am,git commit或git push命令;git_lfs_mistype–修正输入错误的git lfs <command>命令;git_merge–将远程名称添加到分支名称;git_merge_unrelated–--allow-unrelated-histories必要时添加git_not_command–修复错误的git命令,如git brnch;git_pull–在执行上一个之前设置上游git pull;git_pull_clone–在仓库不存在时克隆而不是拉取;git_pull_uncommitted_changes–在拉动之前隐藏更改,然后将其弹出;git_push–添加--set-upstream origin $branch到以前的失败git push;git_push_different_branch_names–修复本地分支名称与远程分支名称不匹配时的推送;git_push_pull–git pull在push被拒绝时运行;git_push_without_commits–在创建git add .新项目时,如果您忘记并且仅创建一个初始提交;git_rebase_no_changes–运行git rebase --skip而不是git rebase --continue没有更改时;git_remote_delete–替换git remote delete remote_name为git remote remove remote_name;git_rm_local_modifications–添加-f或--cached尝试添加到rm本地修改的文件;git_rm_recursive–-r尝试访问rm目录时添加;git_rm_staged–添加-f或--cached当您尝试对rm文件进行分阶段更改时git_rebase_merge_dir–在进行重新设置基准时提供git rebase (--continue | --abort | --skip)或删除.git/rebase-merge目录;git_remote_seturl_add-运行git remote add时git remote set_url不存在的遥控器上;git_stash–在重新建立基础或转移分支之前存储本地修改;git_stash_pop–在弹出存储区之前添加您的本地修改,然后重置;git_tag_force-增加了--force对git tag <tagname>当标签已经存在;git_two_dashes–给诸如git commit -amend或的命令添加破折号git rebase -continue。go_run–.go在编译/运行Go程序时附加扩展名;go_unknown_command–修复错误的go命令,例如go bulid;gradle_no_task–修复未找到的gradle任务或模棱两可的任务;gradle_wrapper–替换gradle为./gradlew;grep_arguments_order–修复grep类似情况的参数顺序grep -lir . test;grep_recursive–-r尝试grep目录时添加;grunt_task_not_found–修复拼写错误的grunt命令;gulp_not_task–修复拼写错误的gulp任务;has_exists_script–./在脚本/二进制文件存在时开始;heroku_multiple_apps–添加--app <app>到heroku类似命令heroku pg;heroku_not_command–修复错误的heroku命令,例如heroku log;history–尝试用历史记录中最相似的命令替换命令;hostscli–试图解决hostscli用法问题;ifconfig_device_not_found-修正错误的设备名称,如wlan0到wlp2s0;java–.java在运行Java程序时删除扩展名;javac–.java编译Java文件时追加缺少的内容;lein_not_task–修复错误的lein任务,例如lein rpl;long_form_help-改变-h到--help时不支持缩写形式ln_no_hard_link–在目录上捕获硬链接创建,建议符号链接;ln_s_order–确定ln -s参数顺序;ls_all-添加-A到ls时输出是空的;ls_lah–添加-lah到ls;man–更改手册部分;man_no_space–例如mandiff,修复无空格的man命令;mercurial–修正错误的hg命令;missing_space_before_subcommand–修复缺少空格的命令,如npminstall;mkdir_p–-p当您尝试创建没有父目录的目录时添加;mvn_no_command–添加clean package到mvn;mvn_unknown_lifecycle_phase–修复拼写错误的生命周期阶段mvn;npm_missing_script–修复npm自定义脚本名称npm run-script <script>;npm_run_script–增加run-script自定义npm脚本的缺失;npm_wrong_command–修复错误的npm命令,如npm urgrade;no_command–修复错误的控制台命令,例如vom/vim;no_such_file–使用mv和cp命令创建丢失的目录;open–要么在http://传递给的地址之前添加地址,open要么创建一个新的文件或目录,然后将其传递给open;pip_install–通过在必要时pip install添加--user或添加前缀来解决命令的权限问题sudo;pip_unknown_command–修复错误的pip命令,例如pip instatl/pip install;php_s–尝试运行本地php服务器时替换-s为-S;port_already_in_use–杀死绑定端口的进程;prove_recursively–-r用目录调用时添加;pyenv_no_such_command–修复错误的pyenv命令,例如pyenv isntall或pyenv list;python_command–python当您尝试运行不可执行/没有./python脚本时准备;python_execute–.py执行Python文件时追加缺少的内容;quotation_marks-修正的不均用法'和"含有当ARGS’;path_from_history–用与历史记录相似的绝对路径替换未找到的路径;react_native_command_unrecognized–修复无法识别的react-native命令;remove_shell_prompt_literal–删除$从文档复制命令时常见的前导外壳提示符号;remove_trailing_cedilla–删除尾随的小提琴ç,这是欧洲键盘布局的常见错字;rm_dir–-rf当您尝试删除目录时添加;scm_correction-修正错误的SCM喜欢hg log到git log;sed_unterminated_s–在sed的s命令中添加缺少的“ /” ;sl_ls–更改sl为ls;ssh_known_hosts–从known_hosts警告中删除主机;sudo–sudo如果由于权限失败而在前一个命令之前添加;sudo_command_from_user_path-运行来自用户的命令$PATH以sudo;switch_lang–将命令从您的本地布局切换到en;systemctl–正确订购混乱的参数systemctl;terraform_init.py–terraform init在计划或应用之前运行;test.py–运行py.test代替test.py;touch–在“接触”之前创建丢失的目录;tsuru_login–tsuru login如果未通过身份验证或会话过期,则运行;tsuru_not_command–修复错误的tsuru命令,例如tsuru shell;tmux–修复tmux命令;unknown_command–修复了hadoop hdfs样式的“未知命令”,例如在上的命令中添加了丢失的“-”hdfs dfs ls;unsudo–sudo如果进程拒绝以超级用户特权运行,则从上一个命令中删除。vagrant_up–启动无业游民的实例;whois–修复whois命令;workon_doesnt_exists–修复了virtualenvwrapperos建议创建新的env名称的问题。yarn_alias–修复yarn类似别名的命令yarn ls;yarn_command_not_found–修复拼写错误的yarn命令;yarn_command_replaced–修复了替换的yarn命令;yarn_help–使打开yarn文件更加容易;
apt_get–如果未安装,则从apt安装应用(需要python-commandnotfound/python3-commandnotfound);apt_get_search–更改尝试使用搜索进行apt-get搜索apt-cache;apt_invalid_operation–修复无效apt和apt-get呼叫,例如apt-get isntall vim;apt_list_upgradable–帮助您apt list --upgradable追赶apt update;apt_upgrade–帮助您apt upgrade追赶apt list --upgradable;brew_cask_dependency–安装桶依赖关系;brew_install–固定公式名称brew install;brew_reinstall-转brew install <formula>成brew reinstall <formula>;brew_link–--overwrite --dry-run链接失败时添加;brew_uninstall-增加了--force对brew uninstall是否已安装了多个版本;brew_unknown_command–修复错误的冲煮命令,例如brew docto/brew doctor;brew_update_formula-转brew update <formula>成brew upgrade <formula>;dnf_no_such_command–修正了错误键入的DNF命令;nixos_cmd_not_found–在NixOS上安装应用;pacman–与pacman未安装的应用一起安装(使用yay或yaourt可用);pacman_invalid_option–pacman用大写字母替换小写字母选项。pacman_not_found-与修复包的名称pacman,yay或yaourt。yum_invalid_operation–修复无效的yum呼叫,例如yum isntall vim;
git_push_force–增加--force-with-lease了git push(可能与冲突git_push_pull);rm_root–添加--no-preserve-root到rm -rf /命令。
创建自己的规则
要添加自己的规则,在~/.config/thefuck/rules 创建一个文件名为your-rule-name.py 的规则文件,必须包含两个函数:
match(command: Command) -> bool get_new_command(command: Command) -> str | list[str]
def match(command):
return ('permission denied' in command.output.lower()
or 'EACCES' in command.output)
def get_new_command(command):
return 'sudo {}'.format(command.script)
# Optional:
enabled_by_default = True
def side_effect(command, fixed_command):
subprocess.call('chmod 777 .', shell=True)
priority = 1000 # Lower first, default is 1000
requires_output = True
设定值
可以在文件中更改几个Fuck参数$XDG_CONFIG_HOME/thefuck/settings.py ($XDG_CONFIG_HOME默认为~/.config):
rules–默认情况下已启用规则的列表thefuck.const.DEFAULT_RULES;exclude_rules–默认情况下禁用的规则列表[];require_confirmation–默认情况下True,在运行新命令之前需要确认;wait_command–获取先前命令输出的最长时间(以秒为单位);no_colors–禁用彩色输出;priority–具有规则优先级的字典,具有较低优先级的规则priority将首先匹配;debug–默认情况下启用调试输出False;history_limit–将扫描多少个历史命令的数值,例如2000;alter_history–默认情况下True,将固定命令推送到历史记录;wait_slow_command–如果先前的命令输出在slow_commands列表中,则以秒为单位的最长时间;slow_commands–慢速命令列表;num_close_matches–默认情况下建议的最大匹配数3。
settings.py:
rules = ['sudo', 'no_command']
exclude_rules = ['git_push']
require_confirmation = True
wait_command = 10
no_colors = False
priority = {'sudo': 100, 'no_command': 9999}
debug = False
history_limit = 9999
wait_slow_command = 20
slow_commands = ['react-native', 'gradle']
num_close_matches = 5
THEFUCK_RULES–启用的规则列表,例如DEFAULT_RULES:rm_root或sudo:no_command;THEFUCK_EXCLUDE_RULES–禁用规则列表,例如git_pull:git_push;THEFUCK_REQUIRE_CONFIRMATION–在运行新命令之前需要确认true/false;THEFUCK_WAIT_COMMAND–获取先前命令输出的最长时间(以秒为单位);THEFUCK_NO_COLORS–禁用彩色输出true/false;THEFUCK_PRIORITY–规则的优先级,例如no_command=9999:apt_get=100,优先级较低的规则priority将首先匹配;THEFUCK_DEBUG–启用调试输出true/false;THEFUCK_HISTORY_LIMIT–将扫描多少个历史命令,例如2000;THEFUCK_ALTER_HISTORY–将固定命令推向历史true/false;THEFUCK_WAIT_SLOW_COMMAND–如果先前的命令输出在slow_commands列表中,则以秒为单位的最长时间;THEFUCK_SLOW_COMMANDS–慢速命令列表,例如lein:gradle;THEFUCK_NUM_CLOSE_MATCHES–建议的接近匹配的最大数量,例如5。
export THEFUCK_RULES='sudo:no_command'
export THEFUCK_EXCLUDE_RULES='git_pull:git_push'
export THEFUCK_REQUIRE_CONFIRMATION='true'
export THEFUCK_WAIT_COMMAND=10
export THEFUCK_NO_COLORS='false'
export THEFUCK_PRIORITY='no_command=9999:apt_get=100'
export THEFUCK_HISTORY_LIMIT='2000'
export THEFUCK_NUM_CLOSE_MATCHES='5'
具有规则的第三方软件包
如果您想制定一组特定的非公共规则,但仍想与其他人共享,请创建一个thefuck_contrib_*具有以下结构的包:
thefuck_contrib_foo
thefuck_contrib_foo
rules
__init__.py
*third-party rules*
__init__.py
*third-party-utils*
setup.py
Fuck将找到位于rules模块中的规则。
实验即时模式
The Fuck的默认行为需要时间来重新运行以前的命令。在即时模式下,The Fuck通过使用script记录输出,然后读取日志来节省时间。
目前,即时模式仅支持bash或zsh的Python 3。还必须禁用zsh的自动更正功能,以使其正常工作。
要启用即时模式,添加--enable-experimental-instant-mode 到别名初始化.bashrc,.bash_profile或.zshrc。
例如:
eval $(thefuck --alias --enable-experimental-instant-mode)
发展
参见CONTRIBUTING.md麻省理工学院许可证
项目许可证可以在这里找到。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)