Zsh
如何設置 zsh 完成部分標題的樣式?
在我的螢幕截圖中,部分標題(“最近的分支”、“本地頭”等)在視覺上與完成建議沒有區別。
compinstall
似乎無法更改樣式。例如,如何將節標題設置為粗體或反轉 fg/bg 顏色?
請參閱
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
. 這設置了各種完成(文件、目錄、過濾器……)的格式。您還可以為不同的類別設置不同的樣式(參見傳遞給_description
in的第一個參數grep -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
…) 並不總是被所有完成者一致使用。