2017-05-30 61 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选项,但我还没有证明它。 –