About me

Saturday 7 January 2017

[Linux] bash-completion

  

介紹

之前我不知道原來『bash-completion』沒有在Ubuntu上是預設,還以為是ubuntu上面就沒有這個功能,還在社群上鬧笑話=.=,這篇文來紀錄一下bash-completion的用法。

bash-completion是一系列的bash script,不只可以對檔案,資料夾,還可以對指令做自動完成的功能。



安裝 $ sudo apt-get install bash-completion 或者是重新安裝: $ sudo apt-get install --reinstall bash-completion
開啟bash-completion 在檔案『~/.bashrc』,檢查一下是否有底下這些,如果沒有的話就加上去: # enable bash completion in interactive shells if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi 然後: $ source ~/.bashrc 或是logout重開機都會套用。 實驗一下,如果用『nmcli』,沒有bash-completion的話,如果你輸入『nmcli』然後一直按『tab』,只會一直出現這個路徑底下的檔案,但是如果已經安裝也啟用了bash-completion的話,輸入『nmcli』以後按兩次『tab』,可以看到下圖,每一次的參數都會幫你列出來,這樣真的很省時間,也不怕打錯字。 hugh@hugh-MS:~$ nmcli agent device help networking connection general monitor radio hugh@hugh-MS:~$ nmcli con add delete edit help load monitor show clone down export import modify reload up hugh@hugh-MS:~$ nmcli con add autoconnect help master type con-name ifname slave-type hugh@hugh-MS:~$ nmcli con add con-name hugh-test autoconnect master slave-type ifname save type hugh@hugh-MS:~$ nmcli con add con-name hugh-test ifname br-8451ecd9f6b0 docker0 enp0s31f6 lo hugh@hugh-MS:~$ nmcli con add con-name hugh-test ifname enp0s31f6
ref http://askubuntu.com/questions/545540/terminal-autocomplete-doesnt-work-properly https://github.com/scop/bash-completion

No comments:

Post a Comment