再也不用擔心敲錯命令了
作者:佚名
相信大家每個人都有敲錯過命令的時候,把python 輸入成 puthon. 手速過快把ls -alh 輸入成 ls a-lh等等等,這時候是不是想拍一下鍵盤說一聲fuck 。
相信大家每個人都有敲錯過命令的時候,把python 輸入成 puthon. 手速過快把ls -alh 輸入成 ls a-lh等等等,這時候是不是想拍一下鍵盤說一聲fuck.
有一個同事就開發了一個thefuck的項目,可糾正先前控制臺命令中的錯誤。讓我們能愉快的工作下去.
安裝
在 macOS 或 Linux 上,您可以通過Homebrew安裝The Fuck:
- brew install thefuck
在 FreeBSD 上,使用以下命令安裝The Fuck:
- pkg install thefuck
Centos系統/Ubuntu系統
- pip install thefuck
配置
- #編輯bashrc配置文件
- vim ~/.bashrc
- #在文件尾加入一行給thefuck取別名fuck
- eval "$(thefuck --alias fuck)"
- #使生效
- source ~/.bashrc
Ubuntu安裝vim
忘記加sudo,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 [enter/↑/↓/ctrl+c]
- [sudo] password for nvbn:
- Reading package lists... Done
git 首次push
- ➜ 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.
- ...
把python敲成puthon
- ➜ 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)
- ...
thefuck原理
其實TheFuck的原理就是規則匹配(正則表達式),如果找到匹配規則的命令,則創建一個命令給用戶選擇或直接運行。
- cat_dir - 當你嘗試cat目錄的時候,用ls替換cat;
- cd_correction – 拼寫檢查和糾正失敗的cd命令;
- cd_mkdir – 在進入目錄之前創建目錄;
- cd_parent – 更改 cd.. 為cd ..;
- dry – 修復類似的重復問題:git git push;
- fix_alt_space – 用空格字符代替Alt + Space;
- # 還有很多可以參考https://github.com/nvbn/thefuck#how-it-works
責任編輯:龐桂玉
來源:
良許Linux