1

I can get process completion more useful by doing zstyle ':completion:*:processes' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'. Is there some way to do something similar for file completion, like using ls -l or exa or something?

1

From spelunking around in zshall(1) (for zsh 5.4.2, no idea when this feature was added) one may find

   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.

So using this, where on the last command ls blah/tab was typed:

$ 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
  • That's neat, but unless the normal version, it doesn't support $LS_COLORS... Still, I should be able to copy some code from _list_files and create my own version. – Caagr98 Sep 10 '17 at 19:35
  • while GNU/ls uses LS_COLORS some BSD ls and other implementations do not, so that lack of support is not surprising – thrig Sep 11 '17 at 14:51
  • I ended up creating my own _list_files function (replacing the builtin one) which formats the output as I want it. – Caagr98 Sep 12 '17 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.