限制zsh选项卡完成行为

限制zsh选项卡完成行为,zsh,zsh-completion,Zsh,Zsh Completion,我的zsh有一些补全功能,我不理解,也找不到可以更改的地方。我有两个问题,我怀疑他们对我的问题有类似的“修复”。我使用以下命令初始化zsh完成系统 autoload -Uz compinit compinit 为了获得高级完成功能,我还遇到了以下问题,如果没有compinit,我就不会遇到这些问题 首先:我的主目录中碰巧有一个名为mydir的目录,不幸的是,还有一个名为mydir的用户。当我想更改到我的目录,然后使用制表符完成,即 cd mydir/<TAB> 在我的.zlogi

我的zsh有一些补全功能,我不理解,也找不到可以更改的地方。我有两个问题,我怀疑他们对我的问题有类似的“修复”。我使用以下命令初始化zsh完成系统

autoload -Uz compinit
compinit
为了获得高级完成功能,我还遇到了以下问题,如果没有compinit,我就不会遇到这些问题

首先:我的主目录中碰巧有一个名为
mydir
的目录,不幸的是,还有一个名为
mydir
的用户。当我想更改到我的目录,然后使用制表符完成,即

cd mydir/<TAB>
在我的
.zlogin
文件中,但它只更改用户名本身的完整性,而不更改后续目录。是否有类似的开关来关闭其他用户主目录的完成?或者,如果当前目录的完成将首先出现在完成菜单中,这已经很好了

Second:我编写了一个名为
setup-file-with-a-long-name.sh的脚本,它位于我的主目录中。当我想通过

source setup-file-with-a-long-name.sh
我从前几个字符开始,按
,我会得到一个列表,其中列出了许多可执行文件,这些文件可能位于系统安装的
$PATH
上,但我不关心所有这些文件,我只想要我的文件(当前目录中唯一匹配的文件)要在菜单中首先显示并通过
访问,或者更好,请在第一个
之后接受。(如果我选择了其中任何一个,它们都不会工作,因为源代码需要的是绝对路径,而不是文件名。因此,我不理解这一行为,也看不出这对于任何人来说是多么有用。)

可能的解决办法:
1.写~/显式-这是我想要避免的,因为我必须经常用ssh连接到一个新的shell中,并且想要开始导航,而不考虑我是否在
$HOME
中。

2.不要使用compinit,原则上我喜欢上下文感知完成,我只是想根据自己的需要调整它。

以下内容在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.
禁用标志的指令略高于sourcepath的描述

       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

在bash中执行以下工作:

       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.
人力资源-

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.
禁用标志的指令略高于sourcepath的描述

       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

谢谢。但是当我这样做的时候,它说没有找到
shopt
命令。我知道了,我的答案适用于bash,我想它也适用于zsh,对此表示抱歉。我也开始研究zsh builtin,它看起来很不一样,有点痛苦,伙计,zshoptions和zshbuiltins。setopt似乎是一个有趣的命令,它可能是HASH_LIST_ALL选项,但我还没有证明它。谢谢。但是当我这样做的时候,它说没有找到
shopt
命令。我知道了,我的答案适用于bash,我想它也适用于zsh,对此表示抱歉。我也开始研究zsh builtin,它看起来很不一样,有点痛苦,伙计,zshoptions和zshbuiltins。setopt似乎是一个有趣的命令,它可能是HASH_LIST_ALL选项,但我还没有证明它。
       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.