diff --git a/docs/highlighters/files.md b/docs/highlighters/files.md index 8cde125..86bc3e6 100644 --- a/docs/highlighters/files.md +++ b/docs/highlighters/files.md @@ -36,7 +36,7 @@ according to that style (following `LS_COLORS`): * `sg` - files that have the sgid bit set * `ow` - files that are world-writable * `tw` - files that are world-writable and sticky -* `lp` - if set, the path-component of a filename is highlighted using this style +* `lp` - if set, the path component of a filename is highlighted using this style, unless it is set to `same`, in which case the path component is highlighted the same as the file If a file would be highlighted `fi`, then it can be highlighted according to the filename using `ZSH_HIGHLIGHT_FILE_PATTERNS` instead. This array has the form diff --git a/highlighters/files/files-highlighter.zsh b/highlighters/files/files-highlighter.zsh index 11f997f..4dcf300 100644 --- a/highlighters/files/files-highlighter.zsh +++ b/highlighters/files/files-highlighter.zsh @@ -219,10 +219,19 @@ _zsh_highlight_highlighter_files_paint() fi if [[ -n "$col" ]]; then - if (( end > start + $#basename && ${+ZSH_HIGHLIGHT_FILE_TYPES[lp]} )); then - region_highlight+=("$start $(( end - $#basename )) $ZSH_HIGHLIGHT_FILE_TYPES[lp]") + if (( end > start + $#basename )); then + # There is a path component + if [[ $ZSH_HIGHLIGHT_FILE_TYPES[lp] = "same" ]]; then + region_highlight+=("$start $end $col") + else + if (( ${+ZSH_HIGHLIGHT_FILE_TYPES[lp]} )); then + region_highlight+=("$start $(( end - $#basename )) $ZSH_HIGHLIGHT_FILE_TYPES[lp]") + fi + region_highlight+=("$(( end - $#basename )) $end $col") + fi + else + region_highlight+=("$start $end $col") fi - region_highlight+=("$(( end - $#basename )) $end $col") fi start=$end