项目作者: Ryooooooga

项目描述 :
zsh abbreviation expansion plugin
高级语言: Rust
项目地址: git://github.com/Ryooooooga/zabrze.git
创建时间: 2021-08-14T08:38:22Z
项目社区:https://github.com/Ryooooooga/zabrze

开源协议:MIT License

下载


zabrze


ZSH abbreviation expansion plugin

Usage

Simple abbreviation

  1. # ~/.config/zabrze/config.yaml
  2. abbrevs:
  3. - name: git
  4. abbr: g
  5. snippet: git
  6. - name: awk '{print $1}'
  7. abbr: '.1'
  8. snippet: awk '{print $1}'
  1. $ eval "$(zabrze init --bind-keys)"

then

  1. $ g<SP>
  2. # ↓ expanded
  3. $ git
  4. $ cat a.txt | .1<CR>
  5. # ↓ expanded and executed
  6. $ cat a.txt | awk '{print $1}'

Global abbreviation

  1. abbrevs:
  2. - name: '>/dev/null 2>&1'
  3. abbr: 'null'
  4. snippets: '>/dev/null 2>&1'
  5. global: true
  1. $ echo a null<SP>
  2. # ↓ expanded
  3. $ echo a >/dev/null 2>&1

Global abbreviation with context

  1. abbrevs:
  2. - name: git commit
  3. abbr: c
  4. snippet: commit
  5. global: true
  6. context: '^git\s'
  7. - name: git commit -m
  8. abbr: cm
  9. snippet: commit -m '{}'
  10. cursor: "{}" # optional; defaults to "{}"
  11. global: true
  12. context: '^git\s'
  13. - name: branch name
  14. abbr: B
  15. snippet: $(git symbolic-ref --short HEAD)
  16. evaluate: true
  17. global: true
  18. context: '^git\s'
  1. $ git c<SP>
  2. # ↓ expanded
  3. $ git commit
  4. $ git cm<SP>
  5. # ↓ expanded and move into quotes
  6. $ git commit -m '|'
  7. $ git push -d origin B<CR>
  8. # ↓ expanded and executed
  9. $ git push -d origin main

Conditional abbreviation

  1. abbrevs:
  2. - name: chrome
  3. abbr: chrome
  4. snippet: open -a 'Google Chrome'
  5. if: '[[ "$OSTYPE" =~ darwin ]]' # only available in macOS
  6. - name: trash
  7. abbr: rm
  8. snippet: trash
  9. if: (( ${+commands[trash]} )) # available if trash is installed
  10. - name: rm -r
  11. abbr: rm
  12. snippet: rm -r # fallback

Suffix alias

  1. abbrevs:
  2. - name: python3 *.py
  3. abbr-pattern: ^(?<file>.+\.py)$
  4. snippet: python3 $file
  5. evaluate: true
  6. # or
  7. - name: python3 *.py
  8. abbr-pattern: \.py$
  9. snippet: python3 $abbr
  10. evaluate: true
  1. $ ./a.py<CR>
  2. # ↓ expanded and executed
  3. $ python3 ./a.py

Installation

From prebuilt binary

You can download a binary release here.

zinit

  1. zinit blockf light-mode as"program" from"gh-r" for \
  2. atload'eval "$(zabrze init --bind-keys)"' \
  3. Ryooooooga/zabrze

Cargo

  1. $ cargo install zabrze

Homebrew

  1. $ brew install ryooooooga/tap/zabrze

Configuration

zabrze reads configuration files from the following locations:

  • $ZABRZE_CONFIG_HOME if set, otherwise $XDG_CONFIG_HOME/zabrze (defaults to $HOME/.config/zabrze)
  • Configuration files are read in lexicographical order.
  • Supported file extensions are yaml and yml.

The configuration file is a YAML file that defines a list of abbreviations. Each abbreviation has the following properties:

  • name (string): A descriptive name for the abbreviation.
  • abbr (string, required, mutually exclusive with abbr-pattern): The abbreviation to expand.
  • abbr-pattern (string, required, mutually exclusive with abbr): A regular expression to match the abbreviation.
  • snippet (string, required): The text to replace the abbreviation with.
  • global (boolean): A boolean value indicating whether the abbreviation should be expanded globally. Defaults to false.
  • context (string): A regular expression that must match the beginning of the line for the abbreviation to be expanded.
  • evaluate (boolean): A boolean value indicating whether the snippet should be evaluated as a shell command. Defaults to false.
  • if (string): A conditional expression that must evaluate to true for the abbreviation to be expanded.
  • cursor (string or null): A string that specifies the cursor position after expansion. Defaults to {}.

Alternatives