如何设置 zsh 完成部分标题的样式?

如何设置 zsh 完成部分标题的样式?

在我的屏幕截图中,部分标题(“最近的分支”、“本地头”等)在视觉上与完成建议没有区别。

compinstall似乎无法更改样式。

例如,如何将节标题设置为粗体或反转 fg/bg 颜色?

在此输入图像描述

答案1

info zsh format(您可能需要安装一个zsh-doc包或等效项)。

您可以设置format zstyle完成:

zstyle ':completion:*' format '%K{blue}%F{yellow}Completing %d:%k%f'

会将完成标题显示为Completing recent branches:蓝色背景上的黄色。

您可以在以下菜单中找到它compinstall

3.  Styles for changing the way completions are displayed and inserted.
[...]
1.  Change appearance of completion lists:  allows descriptions of
    completions to appear and sorting of different types of completions.
[...]
1.  Print a message above completion lists describing what is being
    completed.
[...]
You can set a string which is displayed on a line above the list of matches
for completions.  A `%d' in this string will be replaced by a brief
description of the type of completion.  For example, if you set the
string to `Completing %d', and type ^D to show a list of files, the line
`Completing files' will appear above that list.  Enter an empty line to
turn this feature off.  If you enter something which doesn't include `%d',
then `%d' will be appended.  Quotation will be added automatically.

description>

你会发现确实compinstall将样式设置为zstyle ':completion:*' format.这设置了格式全部各种补全(文件、目录、过滤器……)。您还可以为不同的类别设置不同的样式(请参阅传递给 的第一个参数_descriptiongrep -rw _descriptions $fpath

zstyle ':completion:*:*director*' format '%F{blue}%BCompleting %d:%b%f'
zstyle ':completion:*:*file*' format '%F{magenta}%BCompleting %d:%b%f'

# fallback:
zstyle ':completion:*:descriptions' format '%BCompleting %d:%b'

虽然你会发现那些标签( files, directories...) 并不总是被所有完成者一致使用。

答案2

我找到了一个解决方案https://github.com/solnic/dotfiles/blob/master/home/zsh/completion.zsh

相关摘录是

// needs 'autoload -U colors && colors' 

zstyle ':completion:*:descriptions' format "%{${fg_bold[magenta]}%}= %d =%{$reset_color%}"

相关内容