Skip to content

Commit 8c8d5d1

Browse files
mattiaceruttimarlonrichert
authored andcommitted
Add common substring highlight customization
1 parent 11f1145 commit 8c8d5d1

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Diff for: Completions/_autocomplete__unambiguous

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ _requested $tag ||
3333

3434
typeset -g _autocomplete__unambiguous="$compstate[unambiguous]"
3535

36-
builtin compadd -J "$tag" -x $'%{\e[0;2m%}%Bcommon substring:%b %F{0}%K{11}'"$compstate[unambiguous]%f%k"
36+
# Retrieve highlight value.
37+
local format
38+
zstyle -s ":completion:${curcontext}:unambiguous" format format ||
39+
format=$'%{\e[0;2m%}%Bcommon substring:%b %0F%11K%d%f%k'
40+
41+
zformat -F format "$format" "d:$compstate[unambiguous]"
42+
43+
builtin compadd -J "$tag" -x "$format"
3744

3845
false

Diff for: Functions/Init/.autocomplete__config

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ builtin zstyle ':completion:*:default' select-prompt '%F{black}%K{12}line %l %p%
162162
builtin zstyle ':completion:*' insert-sections yes
163163
builtin zstyle ':completion:*' separate-sections yes
164164

165+
builtin zstyle ':autocomplete:*' common-substring-highlight '%F{0}%K{11}'
166+
167+
165168
# Needed for _gnu_generic to prevent descriptions from getting cropped.
166169
is-at-least 5.9 ||
167170
builtin zstyle ':completion:*' command '- COLUMNS=999'

Diff for: README.md

+18
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@ zstyle ':completion:*:*' matcher-list 'm:{[:lower:]-}={[:upper:]_}' '+r:|[.]=**'
194194
Note, though, that this will also slightly change what completions are listed initially. This is a
195195
limitation of the underlying implementation in Zsh.
196196

197+
### Customize common substring message
198+
You can customize the way the common substring is presented. The following sets the presentation to
199+
the default:
200+
```zsh
201+
builtin zstyle ':autocomplete:*:unambiguous' format \
202+
$'%{\e[0;2m%}%Bcommon substring:%b %0F%11K%d%f%k'
203+
```
204+
`%d` will be replaced with the common substring. Additionally, the following [Zsh prompt escape
205+
sequences](https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Visual-effects) are
206+
supported for adding visual effects:
207+
* `%B`: bold
208+
* `%F`: foreground color
209+
* `%K`: background color
210+
* `%S`: `terminfo` "standout"
211+
* `%U`: underline
212+
* `%{...%}`: arbitrary [ANSI escape
213+
sequence](https://en.wikipedia.org/wiki/ANSI_escape_code#Select_Graphic_Rendition_parameters)
214+
197215
### Make <kbd>Enter</kbd> submit the command line straight from the menu
198216
By default, pressing <kbd>Enter</kbd> in the menu search exits the search and
199217
pressing it otherwise in the menu exits the menu. If you instead want to make

0 commit comments

Comments
 (0)