2010-07-23 43 views
18

我剛剛從Bash遷移到Zsh,但是我遇到了一些問題。在Ubuntu系統上的bash中,當我鍵入不存在的命令的名稱時,Bash會搜索apt數據庫以查找匹配的命令名稱,並打印出提供該命令的軟件包名稱。這是一個非常有用的特性,所以我想知道是否可以在Zsh中使用腳本或其他東西來實現類似的東西?Zsh包建議

下面是一個例子:

$>xmms2 
The program 'xmms2' is currently not installed. You can install it by typing: 
sudo apt-get install xmms2-client-cli 

或者命令是不完全匹配:

$>xmms 
No command 'xmms' found, did you mean: 
Command 'lmms' from package 'lmms' (universe) 
Command 'xmms2' from package 'xmms2-client-cli' (universe) 
Command 'xmds' from package 'xmds' (universe) 
Command 'xdms' from package 'xdms' (universe) 
+0

屬於上superuser.com – 2010-07-23 09:05:05

+0

稀釋ö k對不起,我在這裏新:) – 2010-07-23 12:28:16

+0

@Paul R如果這個軟件包不存在比不是一個編程問題? @如果你發現這個技巧的源代碼,我可以把它移植到zsh。 – ZyX 2010-08-03 18:11:54

回答

11

至於建議的米哈爾Politowski,我會回答我的問題,並把它標記爲解決:)

要在zsh中獲得此功能,請安裝名爲「command-not-found」的軟件包(不知道其他發行版,但在Ubuntu中,它位於存儲庫中)。

注意:在Ubuntu 12.04中,此軟件包默認安裝。

命令和apt-get安裝命令未找到

然後你需要編輯你的.zshrc然後源文件/ etc中/中加入下面的行zsh_command_not_found您.zshrc

源的/ etc/zsh_command_not_found

+2

只是要清楚。我已經安裝了command-not-found,我需要添加的是以下to.zshrc'source/etc/zsh_command_not_found' – Sam 2014-02-03 11:43:28