Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main highlighter does not highlight hashed directories with autocd and cdablevars set #930

Open
zaidhaan opened this issue Jun 13, 2023 · 2 comments

Comments

@zaidhaan
Copy link

Screenshot:
image

I was able to fix it with this

diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh
index f691051..505fe3c 100644
--- a/highlighters/main/main-highlighter.zsh
+++ b/highlighters/main/main-highlighter.zsh
@@ -196,6 +196,8 @@ _zsh_highlight_main__type() {
       REPLY=builtin
     elif (( $+commands[(e)$1] )); then
       REPLY=command
+    elif (( $+nameddirs[(e)$1] )) && [[ -x $nameddirs[$1] ]]; then
+      REPLY=hashed
     # None of the special hashes had a match, so fall back to 'type -w', for
     # forward compatibility with future versions of zsh that may add new command
     # types.

And get these results:
image

Though I'm not sure if that's the right approach, or whether that addresses it in the right place.

Additionally, cdablevars appears to also not be respected (not sure whether this should be moved to a new issue but these both seem related so I'll keep it here)
image

Even with my patch above, it only is able to partially addresses this, since it appears that after entering into that directory, only then does it update the hash table (and once the hash table is updated, it gets highlighted, as shown below)
image


  • zsh 5.9 (x86_64-pc-linux-gnu)
  • zsh-syntax-highlighting commit 1386f12
@phy1729
Copy link
Member

phy1729 commented Jun 14, 2023

I think the right place to add the check would be in _zsh_highlight_main_highlighter_check_path where autocd is handled currently. To check the user's cdablevars setting you can use the zsyh_user_options array as done at the top of that function for autocd.

@zaidhaan
Copy link
Author

Ah, thanks. Looks like my fix can do the following only:

  • make it such that a command positioned hashed directory name is highlighted as a hashed-command (given autocd and cdablevars of course).

That addresses half of what this issue presents, since now just the hashed directory will be highlighted, as expected
image

But if you hit tab and allow it to expand into a path, then it does not get highlighted as expected
image

image

It feels like this could be made easier if _zsh_highlight_main_highlighter_expand_path handled this instead, but I'm not sure if expansion alone can resolve a hashed directory name

$ _zsh_highlight_main_highlighter_expand_path ~repos/autowikibrowser && echo $REPLY
/home/zai/dev/repos/autowikibrowser
                                                                                              
$ _zsh_highlight_main_highlighter_expand_path repos/autowikibrowser && echo $REPLY 
repos/autowikibrowser

Anyhow, I think I'll PR the fix I described above. If it's on the right path, it could be merged. If it's considered incomplete, then it could be worked on further. And if the approach is wrong (e.g. needs to be addressed in _zsh_highlight_main_highlighter_expand_path instead), then it can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants