the: !命令行智能纠错
the: !命令行智能纠错
开发者都或多或少接触过 linux 接触过命令行,当然肯定也都被命令行地“”过。我很多时候都是微不足道的原因导致了命令行出错,例如将 python 输入成 ptyhon,例如将 ls -alh
输入成 ls a-lh
而导致出错,这个时候我会想说:“”。
开发 the 的这位同仁,恐怕也经常会有这种不和谐的情况。因此开发了这个软件 the。
the 不仅仅能修复字符输入顺序的错误,在很多别的你想说“”的情况下,the 依然有效。
例如以下情况。
任何情况下你想说“”,你都可以用得到 the。
例如:
ls 和 sl
使用过 ubuntu 的开发者很多都知道有这么一条命令:sl。这条命令是在你将 ls 错误地输成 sl 时,会在屏幕上快速驶过一辆火车。当然,有了 the,sl 似乎也可以退休了。
代码语言:javascript代码运行次数:0运行复制➜ sl
The program 'sl' is currently not installed. You can install it by typing:
sudo apt-get install sl
➜
ls #修正
a.go b.php dockerui jekyll-casper main.go PureBlog sss.png typecho
a.php c-hash Font-Awesome jekyll-pure mili TeamTalk upload
bii-ubuntu-64__0.deb Dockerfile harmony JekyllPure ngircd ~ tingyun-agent-php-latest.x86_64.deb web.go
blog Dockerfile.bak hashmap kasper php-src sss.jpg tipi zerver
忘记 sudo
代码语言:javascript代码运行次数:0运行复制➜ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (1: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
➜
sudo apt-get install vim
[sudo] password for nvbn:
Reading package lists... Done
操作 git
代码语言:javascript代码运行次数:0运行复制➜ 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
➜
git push --set-upstream origin master
Counting objects: 9, done.
...
错输命令
代码语言:javascript代码运行次数:0运行复制➜ puthon
o command 'puthon' found, did you mean:
Command 'python' from package 'python-minimal' (main)
Command 'python' from package 'python' (main)
zsh: command not found: puthon
➜
python
Python .4.2 (default, Oct 8 2014, 1:08:17)
...
选项修正
代码语言:javascript代码运行次数:0运行复制➜ git brnch
git: 'brnch' is not a git command. See 'git --help'.
Did you mean this?
branch
➜
git branch
* master
其他
the 还有其他很多种用法,就等着你去发现。
安装需求
- python (2.7+ or .+)
- pip
- python-dev
安装方法
可以使用 pip 安装:sudo pip install the
或者使用 OS X、Ubuntu、Arch 的包管理器安装。
安装后配置 bash:
代码语言:javascript代码运行次数:0运行复制alias ='eval $(the $(fc -ln -1)); history -r
Zsh、Fish 和 PowerShell 的 配置方法见这里。
更新
更新到最新的 the 的方法非常简单:
代码语言:javascript代码运行次数:0运行复制sudo pip install the --upgrade
软件原理
前面说了那么多用法, 那么有人觉得 the 可能只是一个用来 the 进行命令修复的模块名和对应的修复原理如下:
- brew_unknown_command:修复
brew
命令,例如将brew docto
修复为brew doctor
- cd_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 diff
- pacman:arch 系统上,如果使用没有安装的软件,尝试使用
pacman
或者yaourt
安装。 - pip_unknown_command:修正错误的
pip
命令,例如pip isntall
修正为pip install
- python_command:当前目录试图执行没有
x
权限的 python 程序时,修复为添加python
前缀 - sl_ls:
sl
修正为ls
- rm_dir:如果删除文件夹,为
rm
添加-rf
选项。 - _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
选项。
自定义规则
当然,你也可以自定义修正规则: 一个自定义规则的案例:
代码语言:javascript代码运行次数:0运行复制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):
('chmod 777 .', shell=True)
# 优先级,数字越大优先级越低。
priority = 1000
使用须知
虽然 the 带来了很多便利,不过仍然建议注意这件事情:
the 会给出的修正后的命令,但是默认情况下你看到它们的时候,命令都已经默认执行了。
大部分情况下,the 可能给出的是正确的修正,但是小部分情况下,给出的修正并不是你想要的。
所以建议将 ~/.the/settings.py
中的设置改为 require_confirmation = True
,这样可以自己决定是否执行修正后的命令。
#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
推荐阅读
留言与评论(共有 13 条评论) |
本站网友 万达广场老总 | 11分钟前 发表 |
did you mean | |
本站网友 四方租房 | 3分钟前 发表 |
不过仍然建议注意这件事情:the 会给出的修正后的命令 | |
本站网友 金山软件董事长 | 27分钟前 发表 |
are you root? ➜ sudo apt-get install vim [sudo] password for nvbn | |
本站网友 茶园租房 | 8分钟前 发表 |
Command 'python' from package 'python-minimal' (main) Command 'python' from package 'python' (main) zsh | |
本站网友 抚顺皇家极地海洋馆 | 28分钟前 发表 |
has_exists_script:为所有的提示不存在的命令尝试添加 ./ 前缀 | |
本站网友 免费数据库 | 5分钟前 发表 |
尝试使用 pacman 或者 yaourt 安装 | |
本站网友 微波炉哪个牌子好 | 28分钟前 发表 |
Reading package lists... Done操作 git代码语言:javascript代码运行次数:0运行复制➜ git push fatal | |
本站网友 珠海电信网上营业厅 | 8分钟前 发表 |
尝试使用 pacman 或者 yaourt 安装 | |
本站网友 镇江租房信息 | 23分钟前 发表 |
git_add:修正没有 git add 的情况 | |
本站网友 暗之职业经理人 | 12分钟前 发表 |
lein_not_task:修正 lein | |
本站网友 北京安定门 | 1分钟前 发表 |
为 rm 添加 -rf 选项 | |
本站网友 刘雄伟 | 26分钟前 发表 |
are you root? ➜ sudo apt-get install vim [sudo] password for nvbn |