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

Autosuggestion for abbreviations #44

Closed onnyyonn closed 2 years ago

onnyyonn commented 3 years ago

Autosuggestion for abbreviations doesn't work. #20 suggests that it's intentional. But there are some use cases, where it can be useful. Is there any chance it will be implemented?

olets commented 2 years ago

Hi thanks for the issue! It's different from #20 — what you want is sort of the opposite of what that user wanted.

zsh-autosuggestions suggests history items and commands. By definition abbreviations aren't commands, so that's out. You could add them to your history:

  1. Use the history or match_prev_cmd strategy (see https://github.com/zsh-users/zsh-autosuggestions#suggestion-strategy)
  2. Add to the history:
    • either: disable zsh-abbr, reload the terminal, run each abbreviation as a command, then enable zsh-abbr and reload the terminal
    • or: make sure you have a history file (echo $HISTFILE. if there isn't one, add [ -z "$HISTFILE" ] && HISTFILE="~/.zsh_history" to your .zshrc (use any path you like, but know that ~/.zsh_history is a standard choice)), then add your abbreviations to it:
      abbr list-abbreviations -U >> $HISTFILE

But that's not a real solution, because as you run other commands the abbreviation history entries could be deprioritized.

What you really need is for zsh-autosuggestions to support passing in a custom list of terms which would match before anything else. Pretty niche need but you could request the feature over at zsh-autosuggestions.

olets commented 2 years ago

Closing because the change currently necessary is not to zsh-abbr, but do please let me know if you get this working!