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
511 stars 18 forks source link

[Bug report] Terminal "freezes" when there is no abbreviations and highlights for user abbreviations are used with zsh-syntax-highlighting #126

Closed Farid-NL closed 1 month ago

Farid-NL commented 1 month ago

Is there an existing issue for this?

Update the issue title

Expected Behavior

Deleting characters (specifically the last one) should work as usual when using zsh-syntax-highlighting

Example:

example-right

Actual Behavior

The last character cannot be deleted and the terminal 'freezes' (can't type, can't use widgets, etc).

To 'unfreeze' the terminal it is necessary to use CTRL-C.

example-wrong

Steps To Reproduce

With a terminal session with at least 1 abbreviation:

  1. Type anything and delete everything, char by char. It should work as expected.
  2. Remove all abbreviations.
  3. Run exec zsh.
  4. Type anything and delete everything, char by char. It shouldn't work, the terminal "freezes". << That's the bug
  5. Use Ctrl + C to "unfreeze" the terminal.
  6. Add some abbreviations.
  7. Run exec zsh.
  8. Type anything and delete everything, character by character. It should work as expected.

bug

Environment

zsh-abbr version 5.7.0
zsh 5.9 (x86_64-ubuntu-linux-gnu)
OSTYPE linux-gnu (Ubuntu)

Installation method

Plugin manager

Installation method details

Zsh framework (Plugin manager): zsh4humans (latest)

Installation process:

  1. Add the plugin repo
    z4h install olets/zsh-abbr || return
  2. Load the plugin
    z4h load olets/zsh-abbr

Anything else?

I place the following code below where zsh-abbr is loaded:

#|---------------
#| Load plugins
#|---------------

z4h load olets/zsh-abbr

#|-------------------
#| Plugins settings
#|-------------------

#|-- zsh-syntax-highlighting --
#| zsh-abbr:
typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(regexp)
ZSH_HIGHLIGHT_REGEXP+=('^[[:blank:][:space:]]*('${(j:|:)${(Qk)ABBR_REGULAR_USER_ABBREVIATIONS}}')$' fg=blue,bold,underline)
ZSH_HIGHLIGHT_REGEXP+=('\<('${(j:|:)${(Qk)ABBR_GLOBAL_USER_ABBREVIATIONS}}')$' fg=blue,bold,underline)
Farid-NL commented 1 month ago

A workaround would be to check if $ABBR_USER_ABBREVIATIONS_FILE has contents:

~/.zshrc

if [[ -s "$ABBR_USER_ABBREVIATIONS_FILE" ]]; then
  typeset -A ZSH_HIGHLIGHT_REGEXP
  ZSH_HIGHLIGHT_HIGHLIGHTERS+=(regexp)
  ZSH_HIGHLIGHT_REGEXP+=('^[[:blank:][:space:]]*('${(j:|:)${(Qk)ABBR_REGULAR_USER_ABBREVIATIONS}}')$' fg=blue,bold,underline)
  ZSH_HIGHLIGHT_REGEXP+=('\<('${(j:|:)${(Qk)ABBR_GLOBAL_USER_ABBREVIATIONS}}')$' fg=blue,bold,underline)
fi
olets commented 1 month ago

Thanks for the report. Good catch!

More reliable than checking for ABBR_USER_ABBREVIATIONS_FILE file contents is to check that there's at least one user abbreviation:

- [[ -s "$ABBR_USER_ABBREVIATIONS_FILE" ]]
+ (( ${#ABBR_REGULAR_USER_ABBREVIATIONS} ))

I've updated the docs https://zsh-abbr.olets.dev/advanced.html#zsh-syntax-highlighting

olets commented 1 month ago

@Farid-NL I offer to add bug reporters to https://zsh-abbr.olets.dev/community/ and https://github.com/olets/zsh-abbr#community. Do you want to be listed? If so I'll have the all-contributors bot open a PR; you'll need to review it to make sure the info the bot pulls is correct

Farid-NL commented 1 month ago

Thanks for the offer, I'm good.

And thank you for such an awesome zsh plugin!