Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Feature request: readline's completion-prefix-display-length option
- X-seq: zsh-workers 38518
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Hong Xu <hong@xxxxxxxxxx>
- Subject: Re: Feature request: readline's completion-prefix-display-length option
- Date: Thu, 19 May 2016 21:14:27 +0000
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- In-reply-to: <CAH+w=7aYcxp73F2koe1nVBRMR8jwJ5eYLAyMi2_35FEX9=dJXw@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <5738124C.7020705@topbug.net> <CAH+w=7aYcxp73F2koe1nVBRMR8jwJ5eYLAyMi2_35FEX9=dJXw@mail.gmail.com>
Bart Schaefer wrote on Sun, May 15, 2016 at 04:50:50 -0700:
> On Sat, May 14, 2016 at 11:08 PM, Hong Xu <hong@xxxxxxxxxx> wrote:
> >
> > I believe that readline's completion-prefix-display-length is a great
> > option to have for zle. This option enables the common part of long
> > completions to be represented by ellipsis, so the options in the
> > completion list would not be too long in many cases.
>
> There might be a deviously clever way to do this with the list-colors
> style, similar to the way that show-ambiguity is implemented.
Like this?
[[[
$ zsh -f
% autoload compinit && compinit
% zstyle -e ':completion:*' list-colors $'reply=( "=(#b)(${(b)PREFIX})(?)([^ ]#)*=0=33=${#PREFIX}D…\e[34=33" )'
% rsync --no-<TAB>
…D -- turn off --devices and --specials
…blocking-io -- turn off --blocking-io
…detach -- do not detach from the parent
…devices -- turn off --devices
…dirs …d -- turn off --dirs
…group …g -- turn off --group
…hard-links …H -- turn off --hard-links
]]]
This is simply a bobby tables solution:
- The xterm control sequence for coloring is «\e[42m».
- The xterm control sequence for "move left" is «\e[42D».
- Setting the part between the two '=' signs to «42Dfoobar\e[43» causes
the cursor to move left 42 spaces (over the common prefix already
output), insert "foobar", and switch to color number 43.
(reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)
This solution breaks alignment¹ since zle doesn't account for the
cursor movement; a workaround for that is to add padding:
[[[
% zstyle -e ':completion:*' list-colors $'reply=( "=(#b)(${(b)PREFIX})(?)([^ ]#)*=0=33=${#PREFIX}D${(r:$#PREFIX-1:: :):-}…\e[34=33" )'
% rsync --delete<TAB>
--delete -- delete files that do not exist on the sending side
…-before -- receiver deletes before transfer
…-delay …-after -- receiver deletes after transfer
…-during -- receiver deletes during transfer
…-excluded -- also delete excluded files on the receiving side
…-missing-args -- delete missing source args from destination
]]]
However, this workaround doesn't make the listing occupy less columns,
which was the original request.
Cheers,
Daniel
¹ Alignment is broken in two cases: (a) when both ${PREFIX} and
${PREFIX}foo are possible completions; (b) when some completions have the
same description as each other and are shown together. If ${PREFIX} is
a proper prefix of all possible completions and all descriptions are
unique, the listing will be aligned, but descriptions will not use the
full terminal width.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author