Replies: 4 comments 2 replies
-
Thanks for the idea! Going to experiment with multiple response threads…
I've played a bit with the idea of a tool that would help me identify good abbreviation candidates. Low priority because my abbreviations stabilized long ago. The more I was taking advantage of abbreviations, the more obvious it was which commands I was still repeatedly typing in full. Still, a tool like that could be fun. Don't know that it will end up built into zsh-abbr itself. I'll follow up here if make something. Note If anyone has a good solution for this, let us know! |
Beta Was this translation helpful? Give feedback.
-
This space is partly covered by history search plugins. The UX isn't exactly the abbreviation effect you're describing, but it's close. Check out https://github.com/zsh-users/zsh-history-substring-search, in particular with the fuzzy search option. I rely heavily on it, bound to the up and down arrows. Or you might like https://github.com/marlonrichert/zsh-autocomplete. It's said to have history fuzzy search. |
Beta Was this translation helpful? Give feedback.
-
I know you're proposing this in the context of history searching, and if you don't want to create abbreviations that's cool. For me, this is where abbreviations shine. abbr git cm="commit -m"
abbr git cnv="commit --no-verify once and you'll be able to type git cm[space] # expands to git commit -m
x y git cm[space] # expands to x y git commit -m
gcm[space] # expands to git commit -m
git cnv[space] # expands to git commit --no-verify
x y git cnv[space] # expands to x y git commit --no-verify
gcnv[space] # expands to git commit --no-verify without losing time stepping through any other fuzzy history matches. |
Beta Was this translation helpful? Give feedback.
-
Finally got around to doing this with my own history. I made a copy of my HISTFILE, sorted by unique lines (I used https://open-vsx.org/extension/Tyriar/sort-lines), and went through it manually. I've had
for a long time, so the commands I run most often don't necessarily appear most often in my history. |
Beta Was this translation helpful? Give feedback.
-
Just found out about
zsh-abbr
. it's a cool idea, but I doubt I would ever generate abbreviations manually, which makes zsh-abbr have limited value for me. I've been on projects where dozens of incomprehensible aliases are used, so I can see a use case there, for sure, but I'm far more likely to rely on zsh completion plugins than I am on manually configured aliases.With that in mind... it would be really cool if you could type a few arbitrary letters, then hit a keyboard shortcut, and have it provide a list of suggestions based on your zsh history.
Back in the day, I used to play a lot of MUDs. They had some pretty good interpretation of arbitrary abbreviations. For example, while
mm
is obvious formagic missile
, you could also type things likemami
/mmi
/etc and it would generally figure out what you meant. And that was decades ago!I'm sure there's a better algorithm than the following, but one way you could do this is generate a regex that inserts *s between what the user typed, then use that w/ grep over zsh history. A slight reliability improvement might be to only match the start of words, e.g. if you type
ga
and hit the shortcut, it'd look forg.* a.*|ga.*
Again, I'm sure there's a better way (and regexes are not my specialty; I'm sure there's a better regex for this), but the above seems like a reasonably low-effort way to do this.
You could also try to trim parameters that are only used once. For example, zsh history could be full of things like
git checkout -b somebranchname
. somebranchname might only exist once in the history, butgit checkout -b
could be a frequent history substring.This could be a really flexible way of shortening parameters.
gcm
(or maybe require explicit hyphens to reduce ambiguity, e.g.gc-m
) + shift+space or something might expand togit commit -m
, whereasgcnv
/gc-nv
might findgit commit --no-verify
, etc.I was surprised there didn't appear to already be a suggestion along these lines... there were some red herrings that were actually about integrating with zsh-autosuggestions plugin.
Beta Was this translation helpful? Give feedback.
All reactions