zsh-abbr icon indicating copy to clipboard operation
zsh-abbr copied to clipboard

[Bug report] Cannot programmatically delete abbreviations containing certain characters

Open Chekote opened this issue 1 year ago • 7 comments

@olets's maintainer edit: this generalized into several bugs related. Summarizing here.

erase outputs a success message but doesn't actually delete if the abbreviation contains

  • [x] a caret (^) (original report)
  • [x] a hash symbol (#)
  • [ ] an exclamation point (!) *
  • [ ] double quotation marks (") *
  • [ ] single quotation marks (')

* Read https://github.com/olets/zsh-abbr/issues/118#issuecomment-2649057475 for workarounds.

Original report follows…


       

Is there an existing issue for this?

  • [X] I have searched the existing issues

Update the issue title

  • [X] I have updated the 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^`
  1. Run the abbreviation:
$ a^
  1. Notice the abbreviation runs as expected.
$ echo "Do something"
Do something
  1. Delete the abbreviation:
$ abbr e a^
Erased regular user abbreviation `a^`
  1. Try to run the abbreviation
$ a^
  1. 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

Chekote avatar May 15 '24 18:05 Chekote

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)

olets avatar May 15 '24 19:05 olets

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 avatar May 16 '24 15:05 Chekote

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.

Chekote avatar May 16 '24 15:05 Chekote

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]

  • Tracked in #84.

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 avatar May 16 '24 18:05 olets

Abbreviations with quotation marks also can't be deleted.

  • Reported in https://github.com/olets/zsh-abbr/pull/128?show_full=true#issuecomment-2159568251

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

olets avatar Jun 11 '24 19:06 olets