2017-05-30 89 views
1

我的zsh有一些完成功能,我不明白,也找不到要更改的地方。我有兩個問題,我懷疑他們對我的問題有類似的「修復」。我初始化完成zsh的系統限制zsh選項卡完成行爲

autoload -Uz compinit 
compinit 

獲得先進的完成特性,但我也感到我沒有不compinit以下問題。

第一:我正好有一個在我的主目錄下名爲mydir目錄不幸的是,還有一個叫mydir用戶。當我想換到我的目錄,然後用tab鍵完成,即

cd mydir/<TAB> 

我得到的~myusername/mydir/的內容目錄與可用於~mydir/所有目錄一起。我已經試圖把

zstyle ':completion:*' users myusername 

在我.zlogin文件,但它只是更改用戶名本身,而不是後續目錄的完成。是否有類似的開關來關閉其他用戶的主目錄的完成?或者,如果當前目錄完成將在完成菜單中首先出現,那就已經很好了。

第二:我寫了一個名爲setup-file-with-a-long-name.sh的腳本,該腳本駐留在我的主目錄中。當我想通過

source setup-file-with-a-long-name.sh 

我的前幾個字符開始執行它,我按<TAB>和我得到的可能是某處由系統安裝在我的$PATH大量的可執行文件的列表,但我不不關心所有這些文件,我只想讓我的文件(這是當前目錄中的唯一匹配項)首先顯示在菜單中,並且可以通過<TAB> <TAB>或更好的方式訪問,在第一個<TAB>之後被接受。 (如果我選擇其中的任何一個,它們都不起作用,因爲源需要絕對路徑,而不是文件名。因此,這是一種我不明白的行爲,並且無法看到這對任何人都是有用的。 )

可能的解決方法:
1.寫入〜/明確 - 這是我想避免的東西,因爲我有ssh到一個新的外殼相當頻繁,要啓動時不考慮我是否在$HOME導航或不。
2.不要使用compinit - 好吧,我喜歡原則上的上下文感知完成,我只是想適應它以滿足我的需求。

回答

0

在bash下面的作品,

人源 -

source filename [arguments] 
       Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename. If filename does not contain a slash, file 
       names in PATH are used to find the directory containing filename. The file searched for in PATH need not be executable. When bash is not in posix mode, the current directory is searched if 
       no file is found in PATH. If the sourcepath option to the shopt builtin command is turned off, the PATH is not searched. 

禁用標誌指令源路徑的描述略高於

 shopt [-pqsu] [-o] [optname ...] 
       Toggle the values of variables controlling optional shell behavior. With no options, or with the -p option, a list of all settable options is displayed, with an indication of 
       whether or not each is set. The -p option causes output to be displayed in a form that may be reused as input. Other options have the following meanings: 
       -s  Enable (set) each optname. 
       -u  Disable (unset) each optname. 
       -q  Suppresses normal output (quiet mode); the return status indicates whether the optname is set or unset. If multiple optname arguments are given with -q, the return 
        status is zero if all optnames are enabled; non-zero otherwise. 
       -o  Restricts the values of optname to be those defined for the -o option to the set builtin. 
... 
      sourcepath 
         If set, the source (.) builtin uses the value of PATH to find the directory containing the file supplied as an argument. This option is enabled by default. 

所以執行下面應該刪除從您的標籤頁完成路徑...

shopt -u sourcepath

+0

謝謝。但是當我這樣做時,它說沒有找到'shopt'命令。 – skaphle

+0

我明白了,我的答案適用於bash我認爲它也適用於zsh,對此很抱歉。我開始研究zsh builtin,它似乎有點不同,可能會有點痛苦,但是zshoptions和zshbuiltins。 setopt似乎是感興趣的命令,它可能是HASH_LIST_ALL選項,但我還沒有證明它。 –