2008-03-16

在 bash 內加入 up、down 鍵功能

使用過 tcsh shell 的人會發現一個好用的功能,可以用 up、down 鍵來 match 先前的指令,如先前輸入了:

ls -l /etc
...
ls ~/
ls -alF /root
...

當我們使用 tcsh,先輸入 ls 再按 up 鍵,則分別會出現 ls -alf /root、ls ~/ 及 ls -l /etc,這樣是不是很方便呢?

現今,linux 內定的 shell 是 bash,那麼 bash 這個 shell 有沒有這個功能呢?

在網路上找了一下資料,發現是可行的:

- 首先在 ~ 目錄下建立(如沒這個檔案)一個 .inputrc,加入以下內容

#Move in history using up and down arrows
"\e[A": history-search-backward
"\e[B": history-search-forward

#On tab show completion
set show-all-if-ambiguous on

重新進入終端機後,我們就可使用這項好用的功能了。

參考資料:
http://amix.dk/blog/viewEntry/19030

沒有留言 :

張貼留言