A simple manager for abbreviations in Z shell (Zsh).
Abbreviations are a concept inspired by the fish shell. They are very similar to aliases, being used to reference commands in order to reduce keystrokes and improve efficiency.
The difference between aliases and abbreviations are that aliases are left in place and reference commands, where as abbreviations are replaced with the commands they reference.
E.g.
alias GP="git pull"
If you create an alias called GP
standing for git pull
.
GP<enter>
And you type GP
and hit enter the alias will be looked up behind the scenes and the command git pull
will be executed.
zsh-simple-abbreviations --set GP "git pull"
If you create an abbreviation called GP
standing for git pull
.
GP<space>
And you type GP
followed by a space.
git pull<space>
The command referenced by the abbreviation will be inlined into the place of the abbreviation. Now when you hit enter to execute the command nothing is being looked up/processed behind the scenes.
When you hit enter you do not have to guess what is being executed and hope something in your command will not be misinterpreted. Because abbreviations inline the referenced commands, therefore you will never be surprised by what is actually being executed.
Because abbreviations inline the referenced commands your history now accurately stores exactly what was executed at the time. Where as if you change an alias, your history no longer matches what was actually executed.
If you are collaborating with others and they are viewing your terminal, your custom aliases will seem like magic; they have no idea what GRM
means or does.
However, if you are using abbreviations it will be inlined to git rebase master
and others will not have to guess what you are doing.
zsh-simple-abbreviations is a simple manager for abbreviations with a minimal but useful set of features.
zsh-simple-abbreviations --set <abbreviation> <command abbreviation expands to>
E.g.
zsh-simple-abbreviations --set GP "git pull"
zsh-simple-abbreviations --unset <abbreviation>
E.g.
zsh-simple-abbreviations --unset GP
If you want to insert a space and not expand the any abbreviations to the left of the cursor then simply use control plus space to insert a space.
You first need to clone zsh-simple-abbreviations.
version="1.0.0" && curl -sL "https://github.com/DeveloperC286/zsh-simple-abbreviations/archive/refs/tags/v${version}.tar.gz" | tar xz --directory "/tmp/" && rm -rf "${HOME}/.zsh-simple-abbreviations" && mv "/tmp/zsh-simple-abbreviations-${version}" "${HOME}/.zsh-simple-abbreviations"
Then in your .zshrc
you need to source zsh-simple-abbreviations, before you can add, remove and use abbreviations.
source "${HOME}/.zsh-simple-abbreviations/zsh-simple-abbreviations.zsh"
zsh-simple-abbreviations is included as part of oh-my-minimal see https://github.com/DeveloperC286/oh-my-minimal for more information.
To report a bug/issue or request a new feature use https://github.com/DeveloperC286/zsh-simple-abbreviations/issues.