Skip to content

Completely disable path checking when style is 'none'. #378

@sevanteri

Description

@sevanteri

When setting ZSH_HIGHLIGHT_STYLES[path]='none' I think the whole path checking should be disabled. Slightly related to #144, I am having some problems with a FUSE mount, too.

What happens is that when I'm midway writing the path the FUSE mount keeps trying to find the path that doesn't exist. And this is pretty slow.

I don't really need the path highlighting and tried to set the style to 'none' but noticed that it doesn't cut it.

So _zsh_highlight_main_highlighter_check_path() should return 1 immediately if path style is set to 'none'.

_zsh_highlight_main_highlighter_check_path()
{
  [[ "$ZSH_HIGHLIGHT_STYLES[path]" == "none" ]] && return 1
  ...

Or if there's another way, please tell me. :)

Activity

danielshahaf

danielshahaf commented on Oct 3, 2016

@danielshahaf
Member

Does none mean "fall back to zle_highlight[default]", or does it mean "fall back to the terminal emulator's default colors (overriding zle_highlight[default])"?

(My reading of zshzle(1) is that none means the latter, but as implemented it means the former.)

If it's the former, then omitting a none entry from region_highlight is a no-op, and your suggested fix makes sense. If it's the latter, we still need to add something to region_highlight, but we could use [[ $ZSH_HIGHLIGHT_STYLES[path] = $ZSH_HIGHLIGHT_STYLES[default] ]] as the short-circuit condition, as in the following patch.

diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh
index f7aa2a9..c4a77c2 100644
--- a/highlighters/main/main-highlighter.zsh
+++ b/highlighters/main/main-highlighter.zsh
@@ -745,6 +745,19 @@ _zsh_highlight_main_highlighter_highlight_path_separators()
 # Else, return non-zero (and the contents of $REPLY is undefined).
 _zsh_highlight_main_highlighter_check_path()
 {
+  # Early exit if possible.
+  #
+  # The assignment to $styles must enumerate every value $REPLY may have at
+  # return from this function.
+  {
+    local -aU styles
+    styles=( "$ZSH_HIGHLIGHT_STYLES[default]" "$ZSH_HIGHLIGHT_STYLES[path]" "$ZSH_HIGHLIGHT_STYLES[path_prefix]" )
+    if (( $#styles == 1 )); then
+      # Pretend it's not a path; won't affect the output
+      return 1
+    fi
+  }
+
   _zsh_highlight_main_highlighter_expand_path $arg;
   local expanded_path="$REPLY"

The diff currently breaks all tests, see path-redirection2.zsh for why. (So it needs some test harness changes)

Action items:

  • Follow up with upstream about meaning of none. Clarify zshzle(1).
    Implement a way to disable path highlighting, e.g., the above patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sevanteri@danielshahaf

        Issue actions

          Completely disable path checking when style is 'none'. · Issue #378 · zsh-users/zsh-syntax-highlighting