命令行的生活是如此的 F**K
你是不是經常在終端敲錯命令,其實這都是因為該死的終端不配合,不能領會你的意思。
每當這個時候,甚至當你一再敲錯的時候,你的內心肯定是崩潰的,一定在默念“……”。
而現在,是讓你的終端覺悟的時候了!
有位名為 @liamosaur 的哥們就忍不住對自己的終端發出了憤怒的吼聲,並付諸實踐:

受此啟發, 一位名為 Vladimir Iakovlev 程序員對這個該死的終端發出了致命一擊!他以及他的 90 位憤怒的小夥伴們打造出了一個名為 “thefuck” 的神器!
當你的終端沒有按你想象的輸入命令時,請 fuck 它!
當你的終端沒有按你想象的以 sudo 執行命令時,請 fuck 它!
當你的的終端不知道填上顯而易見的參數時,請 fuck 它!
當你輸入錯誤的命令時:
puthonNo command 'puthon' found, did you mean:Command 'python' from package 'python-minimal' (main)Command 'python' from package 'python3' (main)zsh: command not found: puthonfuckpython [enter/↑/↓/ctrl+c]Python 3.4.2 (default, Oct 8 2014, 13:08:17)...
當你忘記輸入參數時:
git pushfatal: The current branch master has no upstream branch.To push the current branch and set the remote as upstream, usegit push --set-upstream origin masterfuckgit push --set-upstream origin master [enter/↑/↓/ctrl+c]Counting objects: 9, done....
當你輸入錯誤的參數時:
git brnchgit: 'brnch' is not a git command. See 'git --help'.Did you mean this?branchfuckgit branch [enter/↑/↓/ctrl+c]* master
當你忘記輸入 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 [enter/↑/↓/ctrl+c][sudo] password for nvbn:Reading package lists... Done...
如果生活是如此的不如意,你可以不斷的“教誨”它:
aptget install vimNo command 'aptget' found, did you mean:Command 'apt-get' from package 'apt' (main)zsh: command not found: aptgetfuckaot-get install vim [enter/ctrl-c]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?
還需要權限?再來!
fucksudo apt-get install vim [enter/ctrl-c][sudo] password for nvbn:Reading package lists... DoneBuilding dependency tree... 0%... ...

虐我千百遍 我待如初戀
好了,我想你肯定也想擁有這樣的神器,請如此這般……
我要這個神器!
環境需求
首先,你需要這些:
- python (2.7+ or 3.3+)
- pip
- python-dev
安裝
然後,在不同的操作係統上(沒錯,有 Python 的地方就行):
在 Ubuntu 上可以通過 apt 安裝:
sudo apt updatesudo apt install python3-dev python3-pippip3 install --user thefuck
OS X 上使用 Homebrew 來安裝:
brew install thefuck
其它的係統上,隻要你有 pip 就行:
pip install --user thefuck
更多的 Linux 發行版,可以看這裏。
設置別名
上述安裝的軟件包名字是:“thefuck”——別問我為啥不能直接叫 “fuck”。所以,你可以設置個別名:
Bash
將下述行加入到 .bashrc 或 .bash_profile (用於 OSX):
eval "$(thefuck --alias)"
將下述行加入到 .zshrc:
eval "$(thefuck --alias)"
其它的 shell ,包括 powershell,可以參考這裏。
當然,我覺得我更喜歡給它起個別名叫 “kao”。:D
要讓別名立刻生效,你需要用 source 命令,如:
source ~/.bashrc或source ~/.zshrc
它是怎麼讓我念頭通達的?
thefuck 這個軟件包包含了上百個匹配規則,專門用來修改你的那些錯誤,貼心地將它們修改成應該的樣子!
具體有哪些規則,你可以看看這裏,或者試試就知道了。
當然,如果你經常犯一些獨特的錯誤,你也可以建立自己的規則,而且不妨提交拉取請求給這個項目,找到和你一樣獨特的小夥伴們。
還等什麼?趕快去裝啊!
原文發布時間為:2017-05-03
本文來自雲棲社區合作夥伴“Linux中國”
最後更新:2017-05-19 14:05:13