Comments (14)
@henrebotha I've pushed up a wip branch, prefixes (diff). The idea is to treat abbreviations and expansions the same — so where abbr a=b
currently is saved as abbr a="b"
in the config file, with this change it would be saved as abbr "a"="b"
, and all the other quote level manipulation would be the same as well. Bad news is it doesn't really work right now, good news is I think it's just a question of following the data around and making sure we do with the abbreviation what we do with the expansion (and maybe find a way to simplify both? but that can also come later).
I've also added placeholders for some tests we'll need, and added a new test harness (in main
- diff) to make test writing a nicer experience.
Todo:
- fix test regressions
- write new tests
Don't know when I'll get back to this — probably not soon. If you're inspired to pick it up that'd be awesome!
from zsh-abbr.
I've been using this very happily over the last few months and have had no trouble with it at all. This is a game-changer! Thank you so much for making the effort of implementing this. I'd like to make a token donation to an org of your choice by way of thanks; perhaps a Hawaiian organisation championing indigenous rights? Let me know.
from zsh-abbr.
Time flies!
I've listed a couple organizations in the v5
branch README (see also the new v5.0.0.beta-1).
Thanks again. The sentiment is inspiring.
from zsh-abbr.
I started conversation in the PR before seeing this ticket. Relocating conversation to here.
@olets wrote
Interesting. Before you sink too much time into it, can you explain the use case?I'm excited to see what you do but heads up this week's really busy so I may be slow to respond.
[edit: I personally drop the g whenever I can — e.g. abbr s="git status". The original idea of the import was to make it easer for people who are heavily invested in Git aliases to move to abbr, not necessarily to generate final abbreviations. My initial thought is supporting a word prefix goes against to "get rid of every avoidable keystroke" philosophy. Still… very interesting]
@henrebotha wrote
No worries, whenever you have time.The use case for me is: Just like I never want to type git when g will suffice, I want to be able to use my extensive suite of Git aliases instead of typing their full equivalents. Given a regular command alias g=git, typing gs expands to git status --short and accepts it. Of course, I could simply have a command alias gs, which even accomplishes the same thing with one fewer keystroke; but then I run into the problem of colliding with other commands. (For example, I frequently have to make use of a command gp at work, which precludes having an alias such as gp='git pull'.) Having the ability to force an abbreviation to start with a particular prefix means I can "scope" all my Git aliases under a "namespace", and then go nuts with defining any Git aliases I want without having to worry about them potentially colliding with some command that just happens to start with "g".
Here's what I'm thinking:
Really cool idea. Rather than tie it to Git, I'd like to support spaces in abbreviations generally.
It would meet the Git need abbr "git p"="git pull"
and any other complex cases users might come up with, and would protect against requests like "there's support for a git prefix, can we add support for an x prefix?"
Data handling should be pretty straightfoward — q
s and Q
s where necessary (takes special care when updating, but it should be able to follow the existing support of multi-word expansions). In fact that part should be cleaner than supporting a Git prefix only.
The hard part is expansion, because there can be overlap.
abbr "a b a b"=d
abbr -g a=e
abbr -g b=f
abbr -g "a b"=g
abbr -g "b a"=h
abbr -g "a b a"=i
abbr -g "b a b"=j
I think longest (the one with the most spaces) should probably win — given
abbr "a b"=c
abbr -g b=d
a b<space>
should become c
. Is it okay that b
can't expand to d
if the b
is preceded by the word a
. Maybe? Possible there's some common use case where that behavior would be annoying. If not, could be up to the user to not block themselves.
I think hardest —and possibly even a deal breaker— is a performant implementation of the upgraded functions. But maybe it'll shake out as a pretty recursion.
//
Would you be interested in working on this?
Do you have an intuition about what the user expectation is for overlapping abbreviations?
from zsh-abbr.
Really cool idea. Rather than tie it to Git, I'd like to support spaces in abbreviations generally.
This is actually something I've started working on myself as a separate utility. The idea of "scoped aliases" is so useful to me in contexts like Git and ssh, I want that behaviour everywhere! So I agree: we should try to support this for any arbitrary command.
A simple but effective solution occurs to me w.r.t. overlapping abbreviations: we simply don't allow spaces in global abbreviations, and we always prefer a spaced abbreviation over a global one. That makes conflicts straightforward to resolve, and it makes it easy for the user to understand what to avoid (i.e. don't make global abbreviations that match subwords of spaced abbreviations).
from zsh-abbr.
don't allow spaces in global abbreviations, and we always prefer a spaced abbreviation over a global one
Perfect 👍
--
zsh associative array keys can have spaces as long as the entire key is quoted. So conceptually implementation won't be bad:
_abbr_widget_expand
passes_abbr_cmd_expansion
the entireLBUFFER
instead of just the last word- the add and rename functions [edit: and erase and probably others] don't error for multiple-word abbreviations iff the abbreviation is quoted
- quotes are handled correctly (in temp storage file, config file, listing, expanding, etc)
- I expect a lot of lines will have to change, but it shouldn't be too many distinct things to solve.
- tests cover adding, deleting, erasing, listing, and renaming [edit: anything else?] multi-word abbreviations
Won't have much spare time for a couple months. If you want to take a stab at it that'd be awesome! I'm happy to support.
from zsh-abbr.
It occurs to me now that one issue with handling it this way is that we can't really have abbreviations that are substrings of other abbreviations. For example:
abbr 'y l'='yarn lerna'
abbr 'y l r'='yarn lerna run'
What should happen if the user types y l
? Do we immediately expand according to the first expansion, or do we somehow wait to discover which of the two was intended?
I suppose this only affects inline expansion with Space; expand-and-accept with Enter would still work as intended (since pressing Enter serves to disambiguate).
from zsh-abbr.
I think immediately expand on y l
. Otherwise the computation gets complex quick. Prefixed/scoped/multiword abbreviations are an advanced feature and I think it’s reasonable to ask users to work within some limits.
Can think of it as two scopes: yarn abbreviations, and yarn lerna abbreviations:
abbr “y l”=“yarn lerna”
abbr “yarn lerna r”=“yarn lerna run”
Then —provided yarn
and yarn lerna
aren’t abbreviations themselves— y<space>l<space>r(<space>|<enter>)
becomes yarn lerna run
from zsh-abbr.
@henrebotha 🎁 I've built this out
If you're up for it I'd appreciate your trying it out! Branch is multi-word-abbreviations
. (Back up your abbreviations just in case)
For you original request
% git fp<space> # expands inline to `git fetch --prune`
do
% abbr "git fp"="git fetch --prune"
% git fp<space> # expands inline to `git fetch --prune`
Taking that further, in theory you could
% abbr g=git
% abbr "git fp"="git fetch --prune"
% g<space>fp<space> # expands inline to `git fetch --prune`
from zsh-abbr.
Legend! Going to try it now.
from zsh-abbr.
Works beautifully! I'll report back if I come across any issues.
from zsh-abbr.
Great to hear, and encourages me to get it released.
Amazing!! Let me think and get back to you with a couple groups to choose from.
from zsh-abbr.
@all-contributors please add @henrebotha for code, ideas, and financial. (#31, #32)
from zsh-abbr.
I've put up a pull request to add @henrebotha! 🎉
from zsh-abbr.
Related Issues (20)
- `zsh-abbr` not working when the `viins` keymap is selected HOT 5
- abbr command completion
- [Bug report] bad math expression: operator expected at `Jan 1 03:...' HOT 4
- [feature] abbreviations may place the cursor anywhere in the expansion, instead of only at the end HOT 1
- [Bug report] Cannot programmatically delete abbreviations containing certain characters HOT 5
- fast-syntax-highlighting highlighting of multi-word abbreviations
- [Bug report] Terminal "freezes" when there is no abbreviations and highlights for user abbreviations are used with zsh-syntax-highlighting HOT 4
- Using zi/zinit's `sbin'**/eza -> ls'` to replace `ls` with `eza` breaks zsh-abbr initialization HOT 4
- [Feature] Prefixes 1/n: Ignored string prefixes
- [Feature] Prefixes 2/n: Ignored glob prefixes
- [Feature] Prefixes 3/n: linear combinations of prefixes
- [Bug] unexpected behavior when `ABBR_EXPANSION_CURSOR_MARKER` set to caret HOT 3
- acknowledge committers
- allcontributors 1/ HOT 2
- acknowledge bug reporters HOT 1
- `!` is escaped in v5, but wasn’t in v4 HOT 12
- `abbr c` does not clear abbreviations created with the pattern `abbr x=y` HOT 3
- Teach `add` about `--force`
- [Bug report] involuntary history filtering possible in combination with zsh-autosuggestions and v5.x HOT 11
- Conflict warning logged in all new sessions when adding an abbreviation in zshrc HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zsh-abbr.