olets / zsh-abbr

The zsh manager for auto-expanding abbreviations, inspired by fish. ~13,000 unique cloners as of May '24, 580+ Homebrew installs 6/23-6/24
https://zsh-abbr.olets.dev
Other
510 stars 18 forks source link

ZSH_HIGHLIGHT_REGEXP regex expression not working #56

Closed mikkksewce closed 2 years ago

mikkksewce commented 2 years ago

ZSH_HIGHLIGHT_REGEXP+=('^[[:blank:][:space:]]*('"${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}"')$' style) ZSH_HIGHLIGHT_REGEXP+=('\<('"${(j:|:)${(k)ABBR_GLOBAL_USER_ABBREVIATIONS}}"')$' style)

Those regex expressions aren't working for me on linux (style is appropriately adjusted of course)

echo "${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}" gives me an array separated by whitespaces of my abbreviations, but they are not getting matched and highlighted.

I am calling aforementioned ZSH_HIGHLIGHT_REGEXP+=[...] after

source $HOME/.config/zsh/zsh-abbr/zsh-abbr.zsh
typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(main regexp)

in my .zshrc according to the zsh-syntax-highlighting documentation

https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/regexp.md

olets commented 2 years ago

Thanks for the report!

I don't use zsh-syntax-highlighting or Linux so debugging this might take some back and forth; I also don't know if zsh-syntax-highlighting has changed something.

The setup was originally tested in a Ubuntu VM. πŸ‘‰ What arch are you on?

Your regexes are different from what's in the README. Yours

πŸ‘‰ Was that intentional?

style is appropriately adjusted of course

πŸ‘‰ What is it really?

mikkksewce commented 2 years ago

Hey there. I am on Arch Linux (just updated to zsh 5.9)

The changes weren't really intentional, I just copied what was under the Linux section the wiki

ZSH_HIGHLIGHT_REGEXP+=('^[[:blank:][:space:]]*('"${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}"')$' <styles for regular abbreviations>)
ZSH_HIGHLIGHT_REGEXP+=('\<('"${(j:|:)${(k)ABBR_GLOBAL_USER_ABBREVIATIONS}}"')$' <styles for global abbreviations>)

What I see in the wiki: image Maybe I am not understanding something here? I will try with the changes you mentioned, so without double quotes and \< Currently it still looks like this:

ZSH_HIGHLIGHT_REGEXP+=('^[[:blank:][:space:]]*('"${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}"')$' fg=blue,bg=white,bold)
ZSH_HIGHLIGHT_REGEXP+=('\<('"${(j:|:)${(k)ABBR_GLOBAL_USER_ABBREVIATIONS}}"')$' fg=magenta,bg=white,bold)

I was thinking it could have something to do with the highlighting bug that some user reported on the zsh-syntax-highligthing bug tracker, see: https://github.com/zsh-users/zsh-syntax-highlighting/issues/857 Which is supposedly fixed in 5.9

olets commented 2 years ago

add double quotes…

My mistake, I was looking at https://github.com/olets/zsh-abbr/issues/23#issuecomment-695351622 which doesn't use the '". You did what the README says πŸ‘

replaces \< with <

GitHub fooled me. Your initial \< rendered as < because it isn't in backticks.

--

I don't remember why the double quotes were added after the version from #23. What happens if you drop the "s?

ZSH_HIGHLIGHT_REGEXP+=('^[[:blank:][:space:]]*('${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}')$' <styles for regular abbreviations>)
ZSH_HIGHLIGHT_REGEXP+=('\<('${(j:|:)${(k)ABBR_GLOBAL_USER_ABBREVIATIONS}}')$' <styles for global abbreviations>)

The difference is

% echo "${(j:|:)${(k)ABBR_GLOBAL_USER_ABBREVIATIONS}}"
"abbr1" "abbr2" "abbr3"
% echo ${(j:|:)${(k)ABBR_GLOBAL_USER_ABBREVIATIONS}}
"abbr1"|"abbr2"|"abbr3"

where the latter looks like it should work in the regex and the former looks like it shouldn't.

cycloss commented 2 years ago

I just encountered this problem where highlighting wasn't working on macos. Dropping the the double quotes as suggested above by @olets fixed it for me.

olets commented 2 years ago

Thanks for confirming @cycloss

olets commented 2 years ago

That change is in the readme now!

olets commented 1 month ago

Belatedly acknowledging more contributors in https://github.com/olets/zsh-abbr#community and https://zsh-abbr.olets.dev/community/

Would you like to be added @mikkksewce and @cycloss? If so, I'll have the all-contributors bot open a pull request. Then I'll tag you in it to review for correct info