Giter Club home page Giter Club logo

zsh-abbr's Introduction

zsh-abbr GitHub release (latest by date)

zsh-abbr is the zsh manager for auto-expanding abbreviations - text that when written in a terminal is replaced with other (typically longer) text. Inspired by fish shell.

For example, abbreviate git checkout as co (or even c or anything else). Type coSpace and the co turns into git checkout. Abbreviate git checkout main as cm. Type cmEnter and the cm turns into and runs git checkout main. Don't want an abbreviation to expand? Use CtrlSpace instead of Space, and ;Enter instead of Enter.

Why? Like aliases, abbreviations save keystrokes. Unlike aliases, abbreviations can leave you with a transparently understandable command history ready for using on a different computer or sharing with a colleague. And where aliases can let you forget the full command, abbreviations may help you learn the full command even as you type the shortened version.

Like zsh's alias, zsh-abbr supports "regular" (i.e. command-position) and "global" (anywhere on the line) abbreviations. Like fish's abbr, zsh-abbr supports interactive creation of persistent abbreviations which are immediately available in all terminal sessions. Abbreviations automatically sync to a file, ready for your dotfile management.

Run abbr help for documentation; if the package is installed with Homebrew, man abbr is also available.

Documentation

๐Ÿ“– See the guide at https://zsh-abbr.olets.dev/

v5 is a major release. It makes changes that will require some users to update their configurations. Details are in the migration guide.

Changelog

See the CHANGELOG file.

Roadmap

See the ROADMAP file.

Contributing

Looking for the documentation site's source? See https://github.com/olets/zsh-abbr-docs

Thanks for your interest. Contributions are welcome!

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Check the Issues to see if your topic has been discussed before or if it is being worked on. You may also want to check the roadmap (see above).

Please read CONTRIBUTING.md before opening a pull request.

The test suite uses zsh-test-runner v2.x. See tests/README.md for instructions on running the test suite.

Sponsoring

Love zsh-abbr? I'm happy to be able to provide it for free. If you are moved to turn appreciation into action, I invite you to make a donation to one of the organizations listed below (to be listed as a financial contributor, send me a receipt via email or Reddit DM). Thank you!

  • Oโ€˜ahu Water Protectors a coalition of organizers and concerned community members fighting for safe, clean water on Oสปahu. Currently focused on the Red Hill Bulk Fuel Storage Facility crisis (see Sierra Club of Hawaii's explainer).
  • Hoสปoulu สปฤ€ina is a 100-acre nature preserve nestled in the back of Kali hi valley on the island of Oสปahu which seeks to provide people of our ahupuaสปa and beyond the freedom to make connections and build meaningful relationships with the สปฤina, each other and ourselves.
  • Ol Pejeta Conservancy are caretakers of the land, safeguarding endangered species and ensuring the openness and accessibility of conservation for all. They empower their people to think the same way and embrace new approaches to conservation, and provide natural wilderness experiences, backed up by scientifically credible conservation and genuine interactions with wildlife.
  • Southern Utah Wilderness Alliance (SUWA) the only non-partisan, non-profit organization working full time to defend Utahโ€™s redrock wilderness from oil and gas development, unnecessary road construction, rampant off-road vehicle use, and other threats to Utahโ€™s wilderness-quality lands.

Community

This project uses all-contributors to recognize its community. The key to the emojis is on the all-contributors website.

Henry Bley-Vroman
Henry Bley-Vroman

๐Ÿ“– ๐ŸŽจ ๐Ÿ’ฌ ๐Ÿ”ง
Akinori MUSHA
Akinori MUSHA

๐Ÿ’ป
Alwin Wang
Alwin Wang

๐Ÿ’ป
Daniel Berninghoff
Daniel Berninghoff

๐Ÿ’ป
Henrรฉ Botha
Henrรฉ Botha

๐Ÿ’ป ๐Ÿค” ๐Ÿ’ต
Lucas Larson
Lucas Larson

๐Ÿ›
Stefan Hojer
Stefan Hojer

๐Ÿ’ป

License

zsh-abbr by Henry Bley-Vroman is licensed under a license which is the unmodified text of CC BY-NC-SA 4.0 and the unmodified text of a Hippocratic License 3. It is not affiliated with Creative Commons or the Organization for Ethical Source.

Human-readable summary of (and not a substitute for) the LICENSE file:

You are free to

  • Share โ€” copy and redistribute the material in any medium or format
  • Adapt โ€” remix, transform, and build upon the material

Under the following terms

  • Attribution โ€” You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • Non-commercial โ€” You may not use the material for commercial purposes.
  • Ethics - You must abide by the ethical standards specified in the Hippocratic License 3 with Ecocide, Extractive Industries, US Tariff Act, Mass Surveillance, Military Activities, and Media modules.
  • Preserve terms โ€” If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
  • No additional restrictions โ€” You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Acknowledgments

zsh-abbr's People

Contributors

allcontributors[bot] avatar alwinw avatar baod-rate avatar brendanfalk avatar henrebotha avatar hojerst avatar ifreund avatar justinretzolk avatar knu avatar mortenscheel avatar olets avatar vladdoster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zsh-abbr's Issues

Tabbing for abbrs does not work anymore

Hey,

i updated my fedora system yesterday from 31 to 32.

Before the update it was possible for me to use the abbreviations via tabbing. E.g. typing vp, hitting TAB and zsh shows my abbreviation vprov (for vagrant provision).
Since the update this is no longer the case.
The abbreviations work as expected (typing vprov auto-expands to vagrant provision after hitting space or enter).
I'm not sure where i have too look for the cause of this issue.

โžœ abbr version
zsh-abbr version 4.2.0

โžœ zsh --version
zsh 5.8 (x86_64-redhat-linux-gnu

Reinstalled abbr already (installed via brew now), but this has not fixed the issue.

import-git-aliases doesn't understand multiline aliases

I have aliases that look like this in my .gitconfig.

[alias]
	wkadd = ! "f() { \n\
		git worktree add ../$(echo \"$1\" | sed \"s./.--.g\") $2 -b $1 && \n\
		echo \"$2\" | grep -qv \"^origin/\" || git branch --unset-upstream $1; \n\
		}; f"

When I run abbr import-git-aliases, I get output like this.

Did not import the Git alias `wkadd` because its expansion is a function
Added the global user abbreviation `g$' '$'     'git`
Added the regular user abbreviation `$' '$'     'git`
Added the global user abbreviation `g$' '$'     'echo`
Added the regular user abbreviation `$' '$'     'echo`
Added the global user abbreviation `g$' '$'     '\}\;`
Added the regular user abbreviation `$' '$'     '\}\;`

The first line of course makes sense, but the rest don't.

import-git-aliases should probably be made more aware of multiline aliases so that it knows to skip the whole alias definition if it finds a function alias, and not just the first line of it.

allcontributors 1/

Is there an existing issue for this?

  • I have searched the existing issues

Update the issue title

  • I have updated the title

Expected Behavior

No response

Actual Behavior

No response

Steps To Reproduce

No response

Environment

.

Installation method

Plugin manager

Installation method details

No response

Anything else?

No response

[Bug report] testing issue form

Is there an existing issue for this?

  • I have searched the existing issues

Expected Behavior

A new issue should be created

Actual Behavior

Don't know yet!

Steps To Reproduce

  1. ol 1
  2. ol 2
  • ul 1
  • ul 2

Environment

% echo this should
% echo be a "shell" code block

Installation method

Other

Installation method details

more here

Anything else?

x

acknowledge committers

Hi there, people who have made commits to zsh-abbr.

I'm considering adding https://allcontributors.org/ to the zsh-abbr documentation. The current plan, which I may change in the future, is for the list to show at https://zsh-abbr.olets.dev/community/ and in the README (e.g. https://github.com/olets/zsh-abbr/tree/v5#community).

Despite managing this list with a tool that has the word "contributors" in its name, this "community" is not "contributors" in the licensing sense. For now, however, I am restricting the list to those people who have committed. edit: #83

If you'd like to be included in the community list, give this comment a thumbs up. I'll follow up with an allcontributors PR that you can review.

If you don't want to be included, do nothing or give a thumbs down.

To keep this from spamming everyone with notifications,

๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡
โš ๏ธ๐Ÿ‘‰ Do Not Comment ๐Ÿ‘ˆโš ๏ธ
๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†

I'll check the issue for new thumbs ups periodically, and will close it in a month. If the issue is closed, I've stopped checking for thumbs ups. At that point, commenting is the appropriate way to say you'd like to be added.

(I recommend unsubscribing, to avoid any comment notifications from late comers.)

Thanks!

ย 

ย 

done

ย 

p.s. sorry if you're getting notifications because of those commits. Didn't know GitHub is so eager about linkification

`!` is escaped in v5, but wasnโ€™t in v4

Is there an existing issue for this?

  • I have searched the existing issues

Update the issue title

  • I have updated the title

Expected Behavior

open a terminal window and load this amazing plugin and then enter s then r then n then space:

$ srn

...and have it transformed as it was in v4:

$ sed -e ':a' -e 'N' -e '$! b a' -e 's/\n//g'

Actual Behavior

the text is transformed into the following since v5 (the escaped exclamation point isย new)

$ sed -e ':a' -e 'N' -e '$\! b a' -e 's/\n//g'

Steps To Reproduce

  1. add an abbreviation with an exclamation in it
  2. try to quote it using double quotes, single quotes, and even by way of printf \\41. Hereโ€™s some examples I canโ€™t force to work no matter the means I use to try and hide the ! from zsh-abbr and zsh: try filling your $ABBR_USER_ABBREVIATIONS_FILE with the following, all of which worked fine in v4
$ cat $ABBR_USER_ABBREVIATIONS_FILE
abbr one='find . ! -name example'
abbr two='sed -e '\'':a'\'' -e '\''N'\'' -e '\''$! b a'\'' -e '\''s/\n//g'\'''
abbr two='sed -e '\'':a ;          N ;          $! b a ;          s/\n//g'\'''
abbr two='sed -e '\'':a ;          N ;          $! b a ;          s/\n//g'\'''
abbr --global fng2="$(printf -- 'find -- . -mindepth 1 ! -name '\''.git'\'' ! -path '\''*/.git/*'\'' ! -name '\''.DS_Store'\''\n')"
abbr --global fng3='find -- . -mindepth 1 ! -name '\''.git'\'' ! -path '\''*/.git/*'\'' ! -name '\''.DS_Store'\'''
abbr --global fng='find -- . -mindepth 1 ! -name '\''.git'\'' ! -path '\''*/.git/*'\'' ! -name '\''.DS_Store'\'''
abbr --global srn='sed -e '\'':a; N; $! b a; s/\\n//g'\'''
  1. when testing any of the abbreviations, notice that the exclamation point retains at least one level of escapedness. This is fine in find where find . \! -path xyz and find . ! -path xyz are interpreted as the same command. It does however break an already-escaped exclamation point
  2. I am able to get a partial workaround by adding the following line to my config, but then my problem is like so:
cat $ABBR_USER_ABBREVIATIONS_FILE
abbr --global srn1='sed -e :a -e N -e \$\!b\ a -e s/\\\n//g'

which expands into the following, which includes a literal newline:

$ sed -e :a -e N -e \$\!b\ a -e s/\\
//g

Environment

zsh-abbr version 5.0.0
zsh 5.9 (x86_64-apple-darwin22.1.0)
OSTYPE darwin22.1.0

Using both iTerm (Build 3.5.20230225-nightly) and kitty (Build 3.5.20230225-nightly), getting the sameย results.

Installation method

Manual

Installation method details

No response

Anything else?

Pretty sure the problem begins in either 30216ba7ba or 2503546976.

Thank you for this solid, serious, well-documented plugin.

snippets for zsh-autosuggestions and zsh-syntax-highlighting

Not really an issue. I noticed you have TODO items about autosuggestions and highlighting. Here are snippets I use to with zsh-autosuggestions and zsh-syntax-highlighting to better work with zsh-abbr. Hopefully they might be useful for you.

Enable regexp highlighter and add pattern that matches abbreviations as 'words' to highlight them as you like.

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main regexp)
# highlight known abbreviations
typeset -A ZSH_HIGHLIGHT_REGEXP
# regexp matches abbreviations only when they standalone word, but not part of other words
ZSH_HIGHLIGHT_REGEXP+=('(^| )('${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}')($| )' 'fg=blue')

Disable showing autosuggestion after abbreviations. Also I don't think autosuggesting the abbreviations make much sense as they are usually just 2-3 symbols.

# Don't show suggestions after abbreviations
ZSH_AUTOSUGGEST_HISTORY_IGNORE=${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}
ZSH_AUTOSUGGEST_COMPLETION_IGNORE=${ZSH_AUTOSUGGEST_HISTORY_IGNORE}

Do not follow aliases when calling system commands

I recently discovered a really nice ls replacement. Naturally, I did an alias ls=exa straight away... and my next terminal hung like crazy.

It turns out the problem is in _zsh_abbr_job_push:next_job_id(), where the behavior of ls -t is assumed to be constant. Unfortunately, exa's -t flag works very similarly, but doesn't have a default.

A straightforward fix would be to use \ls instead, but I don't know how that meshes with the project's practices.

command not found: create_aliases

Unfortunately, even with my fixes to the mktemp invocations in #1, the program fails to run with the following error:

$ abbr --version
_zsh_abbr:608: command not found: create_aliases

I'm running zsh 5.7.1 on arch linux. Any advice would be appreciated. I've been looking for something exactly like this plugin as I really liked fish's abbreviations but was annoyed by other aspects of fish.

Abbreviations do not expand [oh-my-zsh]

I've installed zsh-abbr using oh-my-zsh:

$ git clone https://github.com/olets/zsh-abbr.git  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-abbr

And added it to my plugins list in .zshrc:

plugins=(
    git
    common-aliases
    ---snip---
    zsh-syntax-highlighting
    zsh-abbr
)
source $ZSH/oh-my-zsh.sh

Then I ran abbr import-aliases and they were successfully imported, but weren't working even after I restarted zsh, commented out all the other plugins I have and re-imported aliases.

The solution to this problem is just

$ source $ZSH_CUSTOM/plugins/zsh-abbr/zsh-abbr.zsh

but isn't there more elegant solution? Should I just add the line above to my .zshrc? (I thought oh-my-zsh were doing exactly that -- sourceing plugins' scripts?)

Cannot use scopes

What is the exact syntax for scopes?

The documentation says

abbr [<SCOPE>] [<TYPE>] <COMMAND> [<ARGS>]

and I tried the following:

โฏโฏโฏ abbr -S session add  v=vim 
abbr add: Expected one argument, got 2: add v=vim
โฏโฏโฏ abbr session add  v=vim
abbr add: Expected one argument, got 2: add v=vim
โฏโฏโฏ abbr -S session add  
abbr add: Requires abbreviation and expansion
โฏโฏโฏ abbr -S session add v vim
abbr add: Expected one argument, got 3: add v vim

None of these works, so I think this could be simply a bug.

False-positive initialization errors possible when opening multiple sessions simultaneously

When multiple sessions are initializing at the same time, it's possible for the initializations to collide. Common symptoms are one terminal giving the error

util_add:source:45: no such file or directory: โ€ฆ/zsh-user-global-abbreviations

and another terminal giving for each user abbreviation the warning

abbr add: A matching abbreviation โ€ฆ already exists

These are false positives: in my testing, all sessions do end up with all the user abbreviations available.

Until this is addressed, users can work around it by letting one session load before opening another.

If zsh-autosuggestions is not present, an error calling `_zsh_autosuggest_clear` will be frequently be displayed

I installed zsh-abbr without having zsh-autosuggestions installed. The call to _zsh_autosuggest_clear therefore caused an error to be printed in the shell frequently (when _abbr_widget_expand_and_accept is called).

I solved this with the following change, but I'm sure there are better ways:

--- zsh-abbr.zsh.old	2020-10-29 10:42:06.000000000 -0700
+++ zsh-abbr.zsh	2020-10-29 10:42:40.000000000 -0700
@@ -1260,7 +1260,10 @@
     zle _abbr_widget_expand
   fi

-  _zsh_autosuggest_clear
+  # https://unix.stackexchange.com/questions/332005/test-for-functions-existence-that-can-work-on-both-bash-and-zsh/332010
+  if type '_zsh_autosuggest_clear' 2>/dev/null | grep -q 'function'; then
+    _zsh_autosuggest_clear
+  fi

   zle accept-line
 }

Teach `add` about `--force`

Expected Behavior

abbr add --force โ€ฆ will overwrite a conflicting abbreviation is one is already present.

Actual Behavior

add does not know about --force

Anything else?

`abbr c` does not clear abbreviations created with the pattern `abbr x=y`

Is there an existing issue for this?

  • I have searched the existing issues

Update the issue title

  • I have updated the title

Expected Behavior

When running abbr c / abbr clear-session I'm expecting all abbr to be wiped. My use case being to run abbr c; abbr import-aliases to get rid of old and add new aliases to abbr.

Actual Behavior

Screenshot 2023-04-19 at 11 59 47 AM

All other commands seem to work fine. The actual plugin works as expected, its just deleting the abbr which is tedious. I can delete with abbr erase <name>, just not abbr c.

Steps To Reproduce

Basic zsh install (no oh-my-zsh) w/ Zplug as the plugin manager running on MacOS ventura.

Environment

zsh-abbr version 5.0.1
zsh 5.9 (arm-apple-darwin22.1.0)
OSTYPE darwin22.0

Installation method

Other

Installation method details

brew tap "olets/tap"
brew install zplug olets/tap/zsh-abbr # & zsh of course

ZPlug setup

#!/usr/bin/env zsh
# as a part of your dotfiles setup/linking/stowing script
source /opt/homebrew/opt/zplug/init.zsh;
zplug "olets/zsh-abbr";
zplug install;
# .zshrc
source /opt/homebrew/opt/zplug/init.zsh;
zplug "olets/zsh-abbr";
zplug load;

Anything else?

No response

Abbreviations not expanded after (( or $(

abbr -g a="abc"
a[Space] # expands
b a[Space] # expands
[[ a[Space] # expands
(( a[Space] # does not expand ๐Ÿ˜ž
$( a[Space] # does not expand ๐Ÿ˜ž

This is due to how zsh parses strings containing ((.

% mytest() {
  local words=(${(z)1})
  local count=${#words}
  local word_count=${(w)#words}
  echo $count
  echo $word_count
  echo $words[-1]
  echo ${(w)words: -1}
}

% mytest "a"
1
1
a
a

% mytest "a b"
2
2
b
b

% mytest "[[ a"
2
2
a
a

% mytest "(( a"
1
2
(( a
(( a

wontfix because I'm okay living with this, help wanted because ideas are welcome. I do want to rely on zsh's shell grammar parsing and word splitting (retreating to pre-a3c00f5 is not a solution).

Integration with MacOS global text replacements

Hi, thanks for a great plugin!

Yesterday I came across this post on Reddit: Is there a way to get the macOS Text Substitutes feature working in Terminal?

It was a fun challenge, and this is what I ended up with:

while IFS="=" read -r key value; do
    abbr add --session --global --quiet "$key"="$value"        
done < <(defaults read ~/Library/Preferences/.GlobalPreferences.plist NSUserDictionaryReplacementItems | plutil -convert json -o - - | jq -r "map({ (.replace): .with}) | add | to_entries | map(\"\(.key)=\(.value|tostring)\")|.[]")

I have no idea if this is just a fun gimmick, or something a lot of Mac users would like to have. I just thought I'd share it here and let you decide.

Also, I haven't really used plutil or jq before, so there's probably cleaner ways of massaging the plist entries into a usable format.

[Bug report] One more .zwc in repo remains

Is there an existing issue for this?

  • I have searched the existing issues

Update the issue title

  • I have updated the title

Expected Behavior

No bindary .zwc files present in repo. Follow-up to #65

Actual Behavior

https://github.com/olets/zsh-abbr/blob/main/tests/tests.plugin.zsh.zwc is present in repo.

Steps To Reproduce

  1. git clone ...
  2. {
        emulate -LR zsh
        setopt local_options extended_glob
        autoload -Uz zrecompile
        for plugin_file in zsh-abbr/**/*.zsh{-theme,}(#q.); do
            zrecompile -pq "${plugin_file}"
        done
    }
    
  3. depending on zsh version and architecture, there will be diff for tests/tests.plugin.zsh.zwc

Environment

Irrelevant.

Installation method

Manual

Installation method details

git clone

Anything else?

No response

crash after switching between root and unprivileged users

_abbr_job_push:add_job:7: permission denied: /tmp/zsh-abbr/jobs/1646859860.17046
_abbr_job_push:wait_turn:3: bad math expression: operand expected at end of string

I don't really know any other way to describe this but segfault :)

'builtin' 'echo' $job_description > ${ABBR_TMPDIR}jobs/$job_name
next_job_age=$(( $(date +%s) - ${next_job%.*} ))

These are the two problematic lines. Looks like the second one is caused by the first.
I don't really know what to do about that permission denied. Denied by what? Permissions?

Autosuggestion for abbreviations

Autosuggestion for abbreviations doesn't work. #20 suggests that it's intentional. But there are some use cases, where it can be useful. Is there any chance it will be implemented?

occasional unexpected loss of global abbreviations temp file

Occasionally โ€”possibly related to putting my computer to sleep and then waking it up againโ€” I get a warning about a missing temp file. It's added to the rbuffer

For example:

# when the terminal loads
% _abbr_global_expansion:source:12: no such file or directory: /var/folders/xn/26nbvw6s6n30pfwf7rmz4tfw0000gn/T/zsh-abbr/global-user-abbreviations 

# when I then type `exec zsh`
% exec zsh_abbr_global_expansion:source:12: no such file or directory: /var/folders/xn/26nbvw6s6n30pfwf7rmz4tfw0000gn/T/zsh-abbr/global-user-abbreviations

# at this point, hitting ENTER to accept the line runs `exec zsh`, which resolves the problem

Performance improvements

Thank you for your work on this plugin! It's an essential one for me, coming from Fish. That said, it's also by far the slowest Zsh plugin I use and I was wondering if there's a performance tuning effort on the roadmap, if you've identified places where focusing on performance would have the biggest impact, or if you would accept PRs that address performance tuning?

When running /usr/bin/time zsh -i -c exit, my Zsh startup times jump from 0.10 real 0.05 user 0.03 sys to 0.29 real 0.13 user 0.13 sys when adding zsh-abbr. I use about 20 other plugins if that gives some context. Perhaps I'm spoiled by Fish's speed, but anything over .15 can feel really sluggish.

I have had great luck loading this plugin via zsh-defer, which waits until Zle is idle to do the work of loading a plugin, thus getting you to a prompt quicker. My times then drop to 0.05 real 0.02 user 0.02 sys. I think this is similar to what zinit does, but not everyone likes/uses zinit.

An alternative to performance tuning the existing code might be to carve out the core concepts from zsh-defer and implement a mini-defer within zsh-abbr itself to accomplish the same thing without changing any other code. I'm happy to help, but don't want to go down the wrong path here if some thought has already gone into how to achieve better performance from this plugin.

Again, thank you so much for the work on this!


As a reference, this is my topline zprof results:

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)   47         147.62     3.14   64.41%    140.42     2.99   61.27%  _abbr:util_add
 2)    1          24.53    24.53   10.70%     24.52    24.52   10.70%  _abbr_deprecations:widgets
 3)   48          10.84     0.23    4.73%     10.84     0.23    4.73%  _abbr_no_color
 4)   47         171.99     3.66   75.05%     10.36     0.22    4.52%  _abbr
 5)    1         229.18   229.18  100.00%     10.28    10.28    4.49%  _abbr_init
 6)    1           9.83     9.83    4.29%      9.83     9.83    4.29%  _abbr_job_push:wait_turn
 7)  294           4.42     0.02    1.93%      4.42     0.02    1.93%  _abbr_debugger
 8)    1         177.28   177.28   77.35%      3.07     3.07    1.34%  _abbr_load_user_abbreviations:load
 9)    1           2.88     2.88    1.26%      2.87     2.87    1.25%  _abbr_job_pop
10)   47         151.10     3.21   65.93%      2.82     0.06    1.23%  _abbr:add
11)   47           3.06     0.07    1.34%      2.12     0.05    0.92%  _abbr:util_check_command
12)   47         174.20     3.71   76.01%      1.66     0.04    0.72%  abbr
13)    1           1.42     1.42    0.62%      1.42     1.42    0.62%  colors
14)   47           2.15     0.05    0.94%      1.19     0.03    0.52%  _abbr:util_sync_user
15)    1          11.20    11.20    4.89%      1.03     1.03    0.45%  _abbr_job_push
16)   47           1.43     0.03    0.62%      0.83     0.02    0.36%  _abbr:util_log_unless_quiet
17)    1         177.92   177.92   77.63%      0.49     0.49    0.21%  _abbr_load_user_abbreviations
18)    1          24.87    24.87   10.85%      0.33     0.33    0.14%  _abbr_deprecations
19)    1           0.32     0.32    0.14%      0.31     0.31    0.13%  _abbr_job_push:add_job
20)    1           0.15     0.15    0.06%      0.15     0.15    0.06%  add-zsh-hook
21)    1           0.09     0.09    0.04%      0.07     0.07    0.03%  _abbr_create_files
22)    1           0.08     0.08    0.03%      0.07     0.07    0.03%  _abbr_bind_widgets
23)    1           0.05     0.05    0.02%      0.04     0.04    0.02%  _abbr_add_widgets
24)    1           0.14     0.14    0.06%      0.03     0.03    0.01%  _abbr_load_user_abbreviations:setup

Drop .zwc files from repo

I believe those files were committed by mistake. History doesn't hint any reason why they we added in the first place, and they aren't following changes in .zsh files:

As you may know .zwc is compiled script, internal representation of which depends zsh version, machine architecture and probably some other factors. So it doesn't make sense to keep .zwc files in repo, users who need them are able to generate them locally.

arch linux aur package

re: #3 (comment):

I just made an AUR package for my own use by the way.

@ifreund awesome!

"for my own use"โ€ฆ Is it something that will work for all Arch users? If so it'd be great to add in the package installation section of the readme.

Really like the idea of having an AUR. What do you think the best way to keep the package updated is? I can't register with aur.archlinux.org without actually having Arch (or, I suppose, without lying about the pacman output for the anti-bot command), so I can't even flag a package as being out of date. Are you up for continuing to maintain it? I could ping you about releases.

Shell hanging when trying to source abbr

I cloned the repo and tried to source zsh-abbr.zsh. The shell was hanging for a looong time so I stopped it by ctrl+c. Tried sourcing again and get the error message:
abbr: A job added at 16:20:54 Sep 10 2020 has timed out. The job was related to initialization. This could be the result of manually terminating an abbr activity, for example during session startup.
I uninstalled and tried again, but with same result.

I am using zsh 5.4.2 (with prezto) on ubuntu on WSL2.
Is it possible to add is a a module in prezto?

Support variables in abbr value

Hi, I think it wil ge great to support variable evaluation when expanding abbreviation.

For example:
Given password=mysecret

abbr cflogin='cf login -p ${password} -o myOrg -s mySpace'

zsh-autosuggestions' suggestions don't clear after the line is accepted

I do apologize if zsh-abbr is not at fault here, I am still a ZSH newbie who recently migrated from Fish..

What I am here to report today is that whenbindkey -M main "^M" abbr-expand-and-accept is used, the suggestions provided by zsh-autosuggestions would still be printed after the entered command even though it was never accepted.

image

And after some experimentation + searching I stumbled upon bindkey -M main "^M" accept-line which happens to solve the issue but at the cost of having no abbr on Enter.

Before Enter:
image

After Enter:
image

I obviously do not know what the appropriate solution to this issue is and therefore I am here to request help from someone who is more knowledgeable than myself!

SHA256 Mismatch

Homebrew
iTerm2
MacOS Catalina

error is as follows:

==> Installing zsh-abbr from olets/tap
==> Downloading https://github.com/olets/zsh-abbr/releases/download/v4.1.0/v4.1.0.tar.gz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/167840485/a486e300-1620-11eb-94a5-c244f3169fc6?X-Amz-Algorithm=AWS4-HMAC-S
######################################################################## 100.0%
Error: SHA256 mismatch
Expected: 44fafc4
Actual: bacc95a9c65faf851a3009641885fae0b2ae9a80ade1aa7892e200ee6c399294
Archive: /Users/USERNAMEREDACTED/Library/Caches/Homebrew/downloads/be31d708fcd84ff43e0cdd759ce4234827c06f437125a37858ff364650658ea3--v4.1.0.tar.gz
To retry an incomplete download, remove the file above.

I removed the file mbut it makes no difference.

Multi-word / prefixed abbreviations

I don't really like using import-git-aliases as it produces too many conflicts with other commands. What I think would be really fantastic is if zsh-abbr could be clever enough to expand regular Git aliases contextually, i.e. when prefixed with the command git.

$ abbr add --git fp='fetch --prune'
$ git fp<space>
# expands inline to
$ git fetch --prune

What would it take to implement this? I see this in _abbr_widget_expand:

zsh-abbr/zsh-abbr.zsh

Lines 1236 to 1242 in ccac4d0

if [[ $word_count == 1 ]]; then
expansion=$(_abbr_cmd_expansion $word)
fi
if [[ ! $expansion ]]; then
expansion=$(_abbr_global_expansion $word)
fi

I suppose we'd need another layer here, something like _abbr_git_expansion, which takes place only if $words[0] == 'git'. I tried this, but even though _abbr_git_expansion fp prints fetch --prune, typing git fp<space> doesn't expand. What am I missing? Zsh arrays are 1-indexed, haha.

Error updating on Homebrew

==> Upgrading olets/tap/zsh-abbr 4.2.0 -> 4.2.1 ==> Downloading https://github.com/olets/zsh-abbr/releases/download/v4.2.1/v4.2.1.tar.gz ##O#- # curl: (22) The requested URL returned error: 404 Error: Failed to download resource "zsh-abbr" Download failed: https://github.com/olets/zsh-abbr/releases/download/v4.2.1/v4.2.1.tar.gz

expand regular abbreviations in command position anywhere in a line

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.

Using single quotes around abbr value causes error on zsh initialization

I added the following abbreviation with single quotes. It worked fine in that terminal session.

โฏ abbr -a nodes='echo "MASTERS" && kubectl get nodes --selector="kubernetes.io/role=master" && echo "REGULAR NODES" && kubectl get nodes --selector="kubernetes.io/role!=master,dedicated!=heavy" && echo "HEAVY NODES" && kubectl get nodes --selector="kubernetes.io/role!=master,dedicated=heavy"'

When I opened a new terminal I hit this error....

[WARNING]: Console output during zsh initialization detected.

abbr add: Expected one argument, got nodes=echo MASTERS && kubectl get nodes --selector=kubernetes.io/role=master && echo REGULAR NODES && kubectl get nodes --selector=kubernetes.io/role!=master,dedicated!=heavy && echo HEAVY NODES && kubectl get nodes --selector=kubernetes.io/role!=master,dedicated=heavy

Trying to delete it fails...

โฏ abbr -e nodes
abbr erase: No matching abbreviation nodes exists
For help run abbr --help

String should only expand words anchored to the left?

I'm finding that zsh-abbr is expanding words found within the command.

For instance, in fish shell I had abbrs for "master" and "pods", but not I can't use these words in other commands.

Typing "pods" expands to "kubectl get pods", but if I press the up arrow to re-run, it expands to "kubectl get kubectl get pods", which then fails.

Instead, should the expansion only happen for the first word in the string, which I think it what fish does.

Deleted the branch `master`

The branch master has been deleted. Maintaining it complicated the zsh-abbr devops.

main has been the default branch for years.

Early adopters who use Homebrew to install zsh-abbr may initially have used master. In my testing Homebrew is good about handling a change in default branch + deletion of the old default branch.

I have not tested every possible zsh plugin manager.

If you get an error like

fatal: Couldn't find remote ref refs/heads/master

or

pathspec 'master' did not match any file(s) known to git

you'll need to change the branch to main.

If you've specified master somewhere, change that to main.

If you didn't specify master somewhere, or if changing it didn't help, try checking out the branch main:

cd $ABBR_SOURCE_PATH
git checkout main

๐ŸŽ‰ If you have a success story, share you method here with installation method and steps taken.

๐Ÿ˜ž If you have trouble, let me know here.

ZSH_HIGHLIGHT_REGEXP regex expression not working

ZSH_HIGHLIGHT_REGEXP+=('^[[:blank:][:space:]]*('"${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}"')$' style)
ZSH_HIGHLIGHT_REGEXP+=('<('"${(j:|:)${(k)ABBR_GLOBAL_USER_ABBREVIATIONS}}"')$' style)

Those regex expressions aren't working for me on linux (style is appropriately adjusted of course)

echo "${(j:|:)${(k)ABBR_REGULAR_USER_ABBREVIATIONS}}"
gives me an array separated by whitespaces of my abbreviations, but they are not getting matched and highlighted.

I am calling aforementioned ZSH_HIGHLIGHT_REGEXP+=[...] after

source $HOME/.config/zsh/zsh-abbr/zsh-abbr.zsh
typeset -A ZSH_HIGHLIGHT_REGEXP
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(main regexp)

in my .zshrc according to the zsh-syntax-highlighting documentation

https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/regexp.md

acknowledge bug reporters

Hi there, people who have reported zsh-abbr bugs.

I'm adding https://allcontributors.org/ to the zsh-abbr documentation. For now the list will show at https://zsh-abbr.olets.dev/community/ and in the README (e.g. https://github.com/olets/zsh-abbr#community).

Despite managing this list with a tool that has the word "contributors" in its name, this "community" is not "contributors" in the licensing sense.

If you'd like to be included in the community list, give this comment a thumbs up. I'll follow up with an allcontributors PR that you can review.

If you don't want to be included, do nothing or give a thumbs down.

To keep this from spamming everyone with notifications,

๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡โš ๏ธ๐Ÿ‘‡
โš ๏ธ๐Ÿ‘‰ Do Not Comment ๐Ÿ‘ˆโš ๏ธ
๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†โš ๏ธ๐Ÿ‘†

I'll check the issue for new thumbs ups periodically, and will close it in a month. If the issue is closed, I've stopped checking for thumbs ups. At that point, commenting is the appropriate way to say you'd like to be added.

(I recommend unsubscribing, to avoid any comment notifications from late comers.)

Thanks!

ย 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.