mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Use add-zsh-hook
to remove need to call autosuggest_start
.
This commit is contained in:
parent
48d2dc1091
commit
00bd0e9125
9 changed files with 40 additions and 47 deletions
1
DESCRIPTION
Normal file
1
DESCRIPTION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fish-like fast/unobtrusive autosuggestions for zsh.
|
3
INFO
3
INFO
|
@ -1,3 +0,0 @@
|
||||||
Fish-like fast/unobtrusive autosuggestions for zsh.
|
|
||||||
https://github.com/tarruda/zsh-autosuggestions
|
|
||||||
v0.1.1
|
|
31
Makefile
31
Makefile
|
@ -1,8 +1,7 @@
|
||||||
DIST_DIR := ./dist
|
|
||||||
SRC_DIR := ./src
|
SRC_DIR := ./src
|
||||||
SCRIPT_DIR := ./script
|
SCRIPT_DIR := ./script
|
||||||
|
|
||||||
SRC_TARGETS := \
|
SRC_FILES := \
|
||||||
$(SRC_DIR)/config.zsh \
|
$(SRC_DIR)/config.zsh \
|
||||||
$(SRC_DIR)/deprecated.zsh \
|
$(SRC_DIR)/deprecated.zsh \
|
||||||
$(SRC_DIR)/bind.zsh \
|
$(SRC_DIR)/bind.zsh \
|
||||||
|
@ -11,17 +10,27 @@ SRC_TARGETS := \
|
||||||
$(SRC_DIR)/suggestion.zsh \
|
$(SRC_DIR)/suggestion.zsh \
|
||||||
$(SRC_DIR)/start.zsh
|
$(SRC_DIR)/start.zsh
|
||||||
|
|
||||||
$(DIST_DIR)/autosuggestions.zsh: $(SRC_TARGETS) LICENSE
|
HEADER_FILES := \
|
||||||
mkdir -p $(DIST_DIR)
|
DESCRIPTION \
|
||||||
cat INFO | sed -e 's/^/# /g' > $@
|
URL \
|
||||||
echo "#" >> $@
|
VERSION \
|
||||||
cat LICENSE | sed -e 's/^/# /g' >> $@
|
LICENSE
|
||||||
cat >> $@ $(SRC_TARGETS)
|
|
||||||
|
PLUGIN_TARGET := zsh-autosuggestions.zsh
|
||||||
|
|
||||||
|
ALL_TARGETS := \
|
||||||
|
$(PLUGIN_TARGET)
|
||||||
|
|
||||||
|
all: $(ALL_TARGETS)
|
||||||
|
|
||||||
|
$(PLUGIN_TARGET): $(HEADER_FILES) $(SRC_FILES)
|
||||||
|
cat $(HEADER_FILES) | sed -e 's/^/# /g' >> $@
|
||||||
|
cat $(SRC_FILES) >> $@
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(DIST_DIR)
|
rm $(ALL_TARGETS)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: $(DIST_DIR)/autosuggestions.zsh $(SCRIPT_DIR)/test.sh
|
test: all
|
||||||
$(SCRIPT_DIR)/test.sh
|
$(SCRIPT_DIR)/test.zsh
|
||||||
|
|
33
README.md
33
README.md
|
@ -7,6 +7,8 @@ It suggests commands as you type, based on command history.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
### Manual
|
||||||
|
|
||||||
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
|
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -16,11 +18,10 @@ It suggests commands as you type, based on command history.
|
||||||
2. Add the following to your `.zshrc`:
|
2. Add the following to your `.zshrc`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
source ~/.zsh/zsh-autosuggestions/dist/autosuggestions.zsh
|
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||||
autosuggest_start
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** If you're using other zle plugins like `zsh-syntax-highlighting` or `zsh-history-substring-search`, check out the [section on compatibility](#compatibility-with-other-zle-plugins) below.
|
3. Start a new terminal session.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -51,8 +52,6 @@ This plugin works by triggering custom behavior when certain [zle widgets](http:
|
||||||
- `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked.
|
- `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked.
|
||||||
- `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked.
|
- `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked.
|
||||||
|
|
||||||
**Note:** These arrays must be set before calling `autosuggest_start`.
|
|
||||||
|
|
||||||
**Note:** A widget shouldn't belong to more than one of the above arrays.
|
**Note:** A widget shouldn't belong to more than one of the above arrays.
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,22 +71,6 @@ bindkey '^ ' autosuggest-accept
|
||||||
|
|
||||||
## Compatibility With Other ZLE Plugins
|
## Compatibility With Other ZLE Plugins
|
||||||
|
|
||||||
### [`zsh-syntax-highlighting`](https://github.com/zsh-users/zsh-syntax-highlighting)
|
|
||||||
|
|
||||||
Source `zsh-autosuggestions.zsh` *before* `zsh-syntax-highlighting`.
|
|
||||||
|
|
||||||
Call `autosuggest_start` *after* sourcing `zsh-syntax-highlighting`.
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
source ~/.zsh/zsh-autosuggestions/dist/autosuggestions.zsh
|
|
||||||
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
|
||||||
|
|
||||||
autosuggest_start
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### [`zsh-history-substring-search`](https://github.com/zsh-users/zsh-history-substring-search)
|
### [`zsh-history-substring-search`](https://github.com/zsh-users/zsh-history-substring-search)
|
||||||
|
|
||||||
When the buffer is empty and one of the `history-substring-search-up/down` widgets is invoked, it will call the `up/down-line-or-history` widget. If the `up/down-line-or-history` widgets are in `ZSH_AUTOSUGGEST_CLEAR_WIDGETS` (the list of widgets that clear the suggestion), this can create an infinite recursion, crashing the shell session.
|
When the buffer is empty and one of the `history-substring-search-up/down` widgets is invoked, it will call the `up/down-line-or-history` widget. If the `up/down-line-or-history` widgets are in `ZSH_AUTOSUGGEST_CLEAR_WIDGETS` (the list of widgets that clear the suggestion), this can create an infinite recursion, crashing the shell session.
|
||||||
|
@ -106,18 +89,14 @@ Additionally, the `history-substring-search-up` and `history-substring-search-do
|
||||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
|
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure you add/remove these widgets *before* calling `autosuggest_start`.
|
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
source ~/.zsh/zsh-autosuggestions/dist/autosuggestions.zsh
|
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||||
source ~/Code/zsh-history-substring-search/zsh-history-substring-search.zsh
|
source ~/Code/zsh-history-substring-search/zsh-history-substring-search.zsh
|
||||||
|
|
||||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")
|
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")
|
||||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
|
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
|
||||||
|
|
||||||
autosuggest_start
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +131,7 @@ When reporting an issue, please include:
|
||||||
|
|
||||||
### Build Process
|
### Build Process
|
||||||
|
|
||||||
Edit the source files in `src/`. Run `make` to build `dist/autosuggestions.zsh` from those source files.
|
Edit the source files in `src/`. Run `make` to build `zsh-autosuggestions.zsh` from those source files.
|
||||||
|
|
||||||
|
|
||||||
### Pull Requests
|
### Pull Requests
|
||||||
|
|
1
URL
Normal file
1
URL
Normal file
|
@ -0,0 +1 @@
|
||||||
|
https://github.com/tarruda/zsh-autosuggestions
|
1
VERSION
Normal file
1
VERSION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
v0.2.0
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
SCRIPT_DIR=$(dirname "$0")
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
TEST_DIR=$SCRIPT_DIR/../test
|
TEST_DIR=$SCRIPT_DIR/../test
|
||||||
DIST_DIR=$SCRIPT_DIR/../dist
|
DIST_DIR=$SCRIPT_DIR/../
|
||||||
|
|
||||||
source $DIST_DIR/autosuggestions.zsh
|
source $DIST_DIR/zsh-autosuggestions.zsh
|
||||||
|
|
||||||
testDefaultHighlightStyle() {
|
testDefaultHighlightStyle() {
|
||||||
assertEquals \
|
assertEquals \
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
#-------#
|
#-------#
|
||||||
|
|
||||||
# Start the autosuggestion widgets
|
# Start the autosuggestion widgets
|
||||||
autosuggest_start() {
|
_zsh_autosuggest_start() {
|
||||||
_zsh_autosuggest_check_deprecated_config
|
_zsh_autosuggest_check_deprecated_config
|
||||||
_zsh_autosuggest_bind_widgets
|
_zsh_autosuggest_bind_widgets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoload -Uz add-zsh-hook
|
||||||
|
add-zsh-hook precmd _zsh_autosuggest_start
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
||||||
# https://github.com/tarruda/zsh-autosuggestions
|
# https://github.com/tarruda/zsh-autosuggestions
|
||||||
# v0.1.1
|
# v0.2.0
|
||||||
#
|
|
||||||
# Copyright (c) 2013 Thiago de Arruda
|
# Copyright (c) 2013 Thiago de Arruda
|
||||||
# Copyright (c) 2016 Eric Freese
|
# Copyright (c) 2016 Eric Freese
|
||||||
#
|
#
|
||||||
|
@ -339,7 +338,10 @@ _zsh_autosuggest_suggestion() {
|
||||||
#-------#
|
#-------#
|
||||||
|
|
||||||
# Start the autosuggestion widgets
|
# Start the autosuggestion widgets
|
||||||
autosuggest_start() {
|
_zsh_autosuggest_start() {
|
||||||
_zsh_autosuggest_check_deprecated_config
|
_zsh_autosuggest_check_deprecated_config
|
||||||
_zsh_autosuggest_bind_widgets
|
_zsh_autosuggest_bind_widgets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoload -Uz add-zsh-hook
|
||||||
|
add-zsh-hook precmd _zsh_autosuggest_start
|
Loading…
Reference in a new issue