Skip to content

Supercharged context-dependent aliases for ZSH that save you keystrokes!

License

Notifications You must be signed in to change notification settings

langston-barrett/zsh-contextual-abbrevs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contextual Abbreviations for ZSH

Contextual abbreviations (cabbrevs) are like aliases that are only valid in certain contexts and expand automatically. For example, the cabbrev docker,a,attach means "Expand a to attach, but only when the current command line starts with docker". With this cabbrev, when you type docker a<SPACE>, it will automatically expand to docker attach, but echo a<SPACE> is still just echo a .

The following demo shows just how many keystrokes you can save. docker a expands to docker attach. Pressing space again shows the available cabbrevs, entering n d results in docker attach --no-stdin --detach-keys.

Demo of contextual abbreviations for docker attach

Another example: git ce q j 4 be expands to git clone --quiet --jobs 4 --bare.

This repo also contains a script for generating cabbrevs from --help text.

Installation

Manual

Clone the repo somewhere:

git clone https://github.com/langston-barrett/zsh-contextual-abbrevs ~/somewhere

Then add this line to your ~/.zshrc:

source ~/somewhere/src/contextual-abbrevs.zsh

With a Plugin Manager

TODO(#1): PRs welcome :-)

Configuration

cabbrevs are defined in ZSH arrays named _ABBREVS, like so:

_ABBREVS=(
"git restore,s,--source"
"git restore,p,--patch"
"git restore,W,--worktree"
)

(This example was extracted from git.zsh.) Each file in ./src/abbrevs contains one such array. These arrays must be sorted in decreasing prefix length.

You can generate abbreviations from help text using extract-abbrevs.py, e.g.

./scripts/extract-abbrevs.py git

Comparison to Other Tools

Contextual abbreviations work like globalias or zsh-abbr, except that they are contextual - a expands differently when it comes after *git vs. docker.

About

Supercharged context-dependent aliases for ZSH that save you keystrokes!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published