我可以更改文件完成的显示方式吗?

我可以更改文件完成的显示方式吗?

我可以通过执行以下操作来更有用地完成流程zstyle ':completion:*:processes' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'。有没有什么方法可以完成类似的文件完成操作,例如使用ls -lexa之类的东西?

答案1

从洞穴探险zshall(1)(对于zsh 5.4.2,不知道何时添加此功能)人们可能会发现

   file-list
          This style controls whether files completed using  the  standard
          builtin  mechanism  are to be listed with a long list similar to
          ls -l.  Note that this feature uses the  shell  module  zsh/stat
          for  file  information;  this  loads the builtin stat which will
          replace any external stat executable.  To avoid this the follow-
          ing code can be included in an initialization file:

                 zmodload -i zsh/stat
                 disable stat

          The style may either be set to a `true' value (or `all'), or one
          of the values `insert' or `list', indicating that files  are  to
          be  listed in long format in all circumstances, or when attempt-
          ing to insert a file name, or when listing  file  names  without
          attempting to insert one.

因此,使用这个,在最后一个命令的位置ls blah/tab输入:

$ PS1='%% ' zsh -f
% autoload -U compinit && compinit
% zstyle ':completion:*' file-list all
% mkdir blah
% touch blah/{a,b,c}
% ls blah/
-rw-r--r--   1 jhqdoe    grp             0 Sep 10 08:36 a
-rw-r--r--   1 jhqdoe    grp             0 Sep 10 08:36 b
-rw-r--r--   1 jhqdoe    grp             0 Sep 10 08:36 c

相关内容