ZSH abbreviation expansion plugin
Differences from original repository
- Fewer to construct regex
- Advanced operation
- No compatible with original repository
| (Root) | key | value type |
|---|---|---|
| abbrevs | List<Abbr> |
| Abbr | key | value type | description |
|---|---|---|---|
| name | Option<String> | abbreviation name | |
| context | String | default is "" (empty)see below |
|
| global | bool | default is falsesee below |
|
| abbr | String | a trigger string (required either abbr or abbr-regex) |
|
| ^ | abbr-regex | String | a trigger regex (required either abbr or abbr-regex) |
| snippet | String | the string to be expanded (required) | |
| operation | String | expansion method ● replace-self: replace the last argument with snippet (default)● replace-command: replace the first argument with snippet● replace-all: replace whole command with snnipet● append: insert snnipet after the last argument● prepend: insert snippet before the first argument |
|
| evaluate | bool | ● false: insert as string (default)● true: do zsh parameter expansion, then insert |
context == "" |
context != "" |
|
|---|---|---|
global == false |
only trigger at the first argument | only trigger at the second argument |
global == true |
trigger anywhere | trigger anywhere if the first argument is context |
Following variables are available if evaluate == true
| name | description |
|---|---|
$1 |
expands to trigger string |
In your .zshrc
$ eval "$(zabbrev init --bind-keys)"behaves like zsh aliases
# ~/.config/zsh/zabbrev.yaml
abbrevs:
# normal abbreviations
- name: git
abbr: 'g'
snippet: 'git'
- name: editor
abbr: 'e'
snippet: '${EDITOR}'
evaluate: truethen
$ g<Space>
# ↓ expanded
$ git
$ e<Space>
# ↓ expanded
$ nvim # ~/.config/zsh/zabbrev.yaml
abbrevs:
# add default option
- name: mv -i
abbr: 'mv'
snippet: '-i'
operation: appendthen
$ mv<Space>
# ↓ expanded
$ mv -i # ~/.config/zsh/zabbrev.yaml
abbrevs:
# prepend sudo
- name: sudo apt
abbr: 'apt'
snippet: 'sudo'
operation: prependthen
$ apt<Space>
# ↓ expanded
$ sudo apt # ~/.config/zsh/zabbrev.yaml
abbrevs:
# subcommand abbreviations
- name: git commit
context: 'git'
abbr: 'c'
snippet: 'commit'
- name: git push -u origin HEAD
context: 'git'
abbr: 'pu'
snippet: 'push -u origin HEAD'
- name: git pull --rebase origin CURRENT_BRANCH
context: 'git'
abbr: 'pr'
snippet: 'pull --rebase origin $(git symbolic-ref --short HEAD)'
evaluate: truethen
$ git c<Space>
# ↓ expanded
$ git commit
$ git pu<Enter>
# ↓ expanded
$ git push -u origin HEAD
$ git pr<Enter>
# ↓ expanded
$ git pull --rebase origin main# ~/.config/zsh/zabbrev.yaml
abbrevs:
# fake command
- name: extract tar
context: 'extract'
abbr-regex: '\.tar$'
snippet: 'tar -xvf'
operation: replace-command
- name: compress tar
context: 'compress'
abbr-regex: '\.tar$'
snippet: 'tar -cvf'
operation: replace-commandthen
$ extract archive.tar<Enter>
# ↓ expanded
$ tar -xvf archive.tar
$ compress archive.tar<Space>
# ↓ expanded
$ tar -cvf archive.tar behaves like zsh suffix aliases
# ~/.config/zsh/zabbrev.yaml
abbrevs:
# associated command
- name: run jar file
abbr-regex: '\.jar$'
snippet: 'java -jar'
operation: prependthen
$ ./main.jar<Space>
# ↓ expanded
$ java -jar ./main.jar behaves like zsh functions
# ~/.config/zsh/zabbrev.yaml
abbrevs:
# like a function
- name: mkdircd
context: 'mkdircd'
abbr-regex: '.+'
snippet: 'mkdir -p $1 && cd $1'
operation: replace-all
evaluate: truethen
$ mkdircd foo<Space>
# ↓ expanded
$ mkdir -p foo && cd foo behaves like zsh global abbreviations
# ~/.config/zsh/zabbrev.yaml
abbrevs:
# global abbreviations
- name: '>/dev/null'
abbr: 'null'
snippet: '>/dev/null'
global: truethen
$ type cargo null<Space>
# ↓ expanded
$ type cargo >/dev/null # ~/.config/zsh/zabbrev.yaml
abbrevs:
# global abbreviations with context
- name: git current branch
context: 'git'
abbr: 'B'
snippet: '$(git symbolic-ref --short HEAD)'
global: true
evaluate: truethen
$ git show B<Space>
# ↓ expanded
$ git show main
$ echo B<Space>
# ↓
$ echo B # ~/.config/zsh/zabbrev.yaml
abbrevs:
# as one pleases
# You don't have to remember shortcut key.
- context: 'cd'
abbr: 'f'
snippet: $(fd --type d --hidden --no-ignore --exclude .git | fzf --preview 'exa -lha --time-style long-iso --color=always {}')
evaluate: true
- context: 'cd'
abbr: 'g'
snippet: $(fd --type d --hidden --follow '^.git$' ~ -x dirname | fzf --preview 'git -c color.status=always -C {} status')
evaluate: true
# choose commit interactively
- context: 'git'
abbr: 'i'
snippet: rebase -i $(git log --graph --all --oneline --color=always | fzf --ansi --no-sort --reverse --tiebreak index -0 --height=60% --preview "git show --color=always \$(printf '%s' {} | grep -io '[0-9a-f]\{7,\}' | head -1)" | \grep -io '[0-9a-f]\{7,\}' | head -1)
evaluate: truethen
$ cd f<Space>
# ↓ expanded
$ cd ./Downloads
$ git i<Space>
# ↓ expanded
$ git rebase -i 544f368$ git clone https://github.com/a-happin/zabbrev.git && cd zabbrev && cargo install --path .- zabrze (original repository)
- zsh-abbrev-alias
- zeno.zsh