olets / zsh-abbr

The zsh manager for auto-expanding abbreviations, inspired by fish. ~24,000 clones by ~15,000 unique cloners as of late Nov '24, and averaging ~60 Homebrew installs monthly since June 2023
https://zsh-abbr.olets.dev
Other
585 stars 20 forks source link

[Bug report] Cannot programmatically delete abbreviations containing certain characters #118

Open Chekote opened 6 months ago

Chekote commented 6 months ago

Is there an existing issue for this?

Update the issue title

Expected Behavior

The abbreviation should be deleted.

Actual Behavior

zsh-abbr claims the abbreviation was deleted, but it is not.

Steps To Reproduce

  1. Add the abbreviation:

    $ abbr a^='echo "Do something"'
    Added the regular user abbreviation `a^`
  2. Run the abbreviation:

    $ a^
  3. Notice the abbreviation runs as expected.

    $ echo "Do something"
    Do something
  4. Delete the abbreviation:

    $ abbr e a^
    Erased regular user abbreviation `a^`
  5. Try to run the abbreviation

    $ a^
  6. Notice that it runs, even those zsh-abbr claimed it was erased.

    $ echo "Do something"
    Do something

Environment

zsh-abbr version 5.4.1
zsh 5.9 (x86_64-apple-darwin23.0)
OSTYPE darwin23.0

Installation method

Homebrew

Installation method details

Homebrew 4.3.0-20-g1f603d3

Anything else?

No response

olets commented 6 months ago

Thanks for the report!

I'm able to replicate this. Added breaking tests in the new branch ~ 118-caret ~ ~edit: now named118-failed-erasure~ edit: now named issues/118. The caret ^ is the source of the problem. Possible they'll have to be disallowed. For now, a workaround is to not use carets in abbreviations.

- $ abbr a^='echo "Do something"'
+ $ abbr a='echo "Do something"'

You'll need to manually delete the a^ abbreviation from the user abbreviations file (see https://github.com/olets/zsh-abbr/discussions/119)

Chekote commented 6 months ago

Thanks for the quick response ❤️

This also happens with the exclamation mark. I am migrating from Fish to Zsh, and these are the abbreviations that I have set up from Fish. If at all possible, it would be ideal if these could be supported so I don't have to retrain my dumb brain 😆

Thanks for updating the title. I got confused by the output of abbr and thought Added the regular user abbreviation said Added the regular expression abbreviation. My dumb brain assumes "regular" is always followed by "expression" 🤦

Chekote commented 6 months ago

I just discovered something interesting:

If I add the following abbreviation:

abbr dcr!='docker container run --rm'

It ends up in the user file as:

abbr "dcr\!"="docker container run --rm"

Which doesn't expand properly in the shell. But if I edit the user file to remove the backslash:

abbr "dcr!"="docker container run --rm"

Then it works as expected.

But if I add another abbreviation via the abbr command, it adds the backslash back in.

olets commented 6 months ago

If at all possible, it would be ideal if these could be supported so I don't have to retrain my dumb brain

I hear that!

Will look into the caret. But heads up that it'll be at least a few days before I have time to investigate, maybe longer.

This also happens with the exclamation mark.

Good find! I can replicate. Updating the title and adding a failing test

I just discovered something interesting [escaped exclamation point]

But if I add another abbreviation via the abbr command, it adds the backslash back in.

Expected, that's because the full file is rewritten.

Thanks for updating the title

No worries! I don't feel users should have to use or know jargon.

olets commented 5 months ago

Abbreviations with quotation marks also can't be deleted.

Looks relevant https://unix.stackexchange.com/a/626529/248959