Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand regular abbreviations in command position anywhere in a line #53

Open
thingsiplay opened this issue Feb 21, 2022 · 5 comments
Open
Labels
enhancement New feature or request help welcome wontfix This will not be worked on

Comments

@thingsiplay
Copy link

I am using zsh-abbr for a while now and have an issue. And I just updated it from git directly; also zsh --version: "zsh 5.8 (x86_64-pc-linux-gnu)".

For me the abbreviations won't triggered or expanded after a pipe |. Like in this case: x expands to chmod +x, but chmod +x | x does not. This can be solved with a global option -g. The only problem is, that the abbr is really global and will even get triggered as an argument, like there: grep x file to grep chmod +x file. I would like to have an option that is less global and only affects as a command name, even after a pipe.

@olets
Copy link
Owner

olets commented Feb 21, 2022

Thanks for submitting the idea @thingsiplay! It makes sense. That's how zsh aliases work

% alias hello="echo world"
% echo hello; hello
hello
world

and how fish abbreviations work

> abbr --add w="echo world"
> echo hello; w
hello
world

I'll consider it but I'm not sure if it will be feasible. A naive version would use command abbreviations at the start of the line, and after at least &&, ||, ;, |, [, and [[; and test when that follows or word boundary or one of the delimiters I just listed. But there are probably important edge cases that would take truly parsing the command, and that's not in this project's scope.

I don't plan to start new abbr features soon. (I am getting close to launching some abbr updates though!) In the meantime you can create a global abbreviation and opt out of using it in certain circumstances

% abbr -g x="chmod +x"
% grep chmod +x[ctrl space] file

or choose an abbreviation that doesn't conflict with things you type:

% abbr -g cx="chmod +x"

@thingsiplay
Copy link
Author

thingsiplay commented Feb 21, 2022

"I thought it wouldn't be easy, but better report than not to. I didn't know about the manual opt out, but this is still not the solution with a lot of abbreviations. Because I would need to make them all global in order to be able to use in pipes, at least those that make sense.

Another idea would be to act the shortcut "[ctrl space]" as opposite if global option is not set. Meaning it would force to expand, if I manually do "[ctrl space]".

@olets olets added the enhancement New feature or request label Feb 22, 2022
@olets
Copy link
Owner

olets commented Mar 2, 2022

"[ctrl space]" as opposite if global option is not set

Interesting idea. That would not be as hard as parsing for command beginnings. I'll consider it. But I'm leaning towards not adding it— feels like a niche need that can be avoided with careful abbreviation naming. I'll leave this open though.

@thingsiplay
Copy link
Author

Thanks for considering it, it's just an idea and I get why you won't add or change every niche idea. But in my personal opinion (I speak for myself) don't see this as such niche problem. This plugin itself is relatively niche, so you won't get too many reports on that. Maybe people are not aware that it's a problem, if they use the -g option and the command gets triggered at any point in the arguments. The first time it happened to me, I had weird results and didn't notice the expansion at all! It is not the pipe only, also when using && or ; in example are affected.

Careful naming won't change the problem, it will make it less likely to happen. But if I start making complex names, then the abbreviations lose their meaning. There is already a system how I name my abbreviations. My best workaround to ignore abbr when using global option currently is to put the arguments into quotation marks.

@olets olets changed the title abbr won't get triggered after a pipe and global option is not the solution expand regular abbreviations in command position anywhere in a line Mar 13, 2022
@olets olets added help welcome wontfix This will not be worked on labels Mar 13, 2022
@olets
Copy link
Owner

olets commented Mar 13, 2022

I don't plan to work on this (wontfix) but I'll consider contributions (help wanted).

I imagine it would entail adding (or perhaps splitting abbr-expand-and-space into) abbr-expand-command-and-space and abbr-expand-global-and-space

Anyone intending to take this on: please discuss here first.

If you'd like to see this feature, give the original comment a 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help welcome wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants