被頂了一下,今天看了一下。
準備把評論區某我的拉出來批。
對,就是@laike9m 。
張口國人閉口國人的言論就不說了,陰陽怪氣的在下面說這說那。
本文原文所有來自thefuck的readme,沒有參考任何第二手資料!
其餘任何網站有雷同,所有是來自本文!
例如oschina的收錄:https://www.oschina.net/p/the...。
例如知名爬取了的oschina的所有數據的open-open:http://www.open-open.com/lib/...
例如http://www.genshuixue.com/i-c...
例如https://www.zhihu.com/questio...php
通常而言,能受到普遍關注的開源項目分爲這麼幾類:html
分離出去的項目,例如 io.jspython
解決了痛點的項目,例如 jQuerylinux
提升效率的項目,例如 Anjular.jsgit
大公司的項目或者原本就特別火的項目,例如 .NETgithub
固然也有腦洞大開的項目,好比 SegmentFault 上以前介紹過的《編程語言中的精品——草泥馬語》。(你還記得嗎?)web
更好比,今天要講的主角:thefuck。docker
開發者都或多或少接觸過 linux 接觸過命令行,固然確定也都被命令行狠狠地「fuck」過。我不少時候都是微不足道的緣由致使了命令行出錯,例如將 python 輸入成 ptyhon,例如將 ls -alh
輸入成 ls a-lh
而致使出錯,這個時候我會想說:「fuck」。shell
開發 thefuck 的這位同仁,恐怕也常常會有這種不和諧的狀況。所以開發了這個軟件 thefuck。編程
thefuck 不只僅能修復字符輸入順序的錯誤,在不少別的你想說「fuck」的狀況下,thefuck 依然有效。
例如如下狀況。
任何狀況下你想說「我操」,你均可以用獲得 thefuck。
例如:
使用過 ubuntu 的開發者不少都知道有這麼一條命令:sl。這條命令是在你將 ls 錯誤地輸成 sl 時,會在屏幕上快速駛過一輛火車。固然,有了 thefuck,sl 彷佛也能夠退休了。
➜ sl The program 'sl' is currently not installed. You can install it by typing: sudo apt-get install sl ➜ fuck ls #修正 a.go b.php dockerui jekyll-casper main.go PureBlog sss.png typecho a.php c-hash Font-Awesome jekyll-pure mili signal.c TeamTalk upload bii-ubuntu-64_3_0.deb Dockerfile harmony JekyllPure ngircd signal.c~ tingyun-agent-php-latest.x86_64.deb web.go blog Dockerfile.bak hashmap kasper php-src sss.jpg tipi zerver
➜ 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
➜ 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 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 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 * master
thefuck 還有其餘不少種用法,就等着你去發現。
python (2.7+ or 3.3+)
pip
python-dev
可使用 pip 安裝:sudo pip install thefuck
或者使用 OS X、Ubuntu、Arch 的包管理器安裝。
安裝後配置
bash:
alias fuck='eval $(thefuck $(fc -ln -1)); history -r'
Zsh、Fish 和 PowerShell 的 配置方法見這裏。
更新到最新的 thefuck 的方法很是簡單:
sudo pip install thefuck --upgrade
前面說了那麼多用法,
那麼有人以爲 thefuck 可能只是一個用來
thefuck 進行命令修復的模塊名和對應的修復原理以下:
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
選項。
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
選項。
固然,你也能夠自定義修正規則:
一個自定義規則的案例:
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
,這樣能夠本身決定是否執行修正後的命令。