Use add-zsh-hook to remove need to call autosuggest_start.

This commit is contained in:
Eric Freese 2016-02-07 14:21:57 -07:00
parent 48d2dc1091
commit 00bd0e9125
9 changed files with 40 additions and 47 deletions

1
DESCRIPTION Normal file
View file

@ -0,0 +1 @@
Fish-like fast/unobtrusive autosuggestions for zsh.

3
INFO
View file

@ -1,3 +0,0 @@
Fish-like fast/unobtrusive autosuggestions for zsh.
https://github.com/tarruda/zsh-autosuggestions
v0.1.1

View file

@ -1,8 +1,7 @@
DIST_DIR := ./dist
SRC_DIR := ./src
SCRIPT_DIR := ./script
SRC_TARGETS := \
SRC_FILES := \
$(SRC_DIR)/config.zsh \
$(SRC_DIR)/deprecated.zsh \
$(SRC_DIR)/bind.zsh \
@ -11,17 +10,27 @@ SRC_TARGETS := \
$(SRC_DIR)/suggestion.zsh \
$(SRC_DIR)/start.zsh
$(DIST_DIR)/autosuggestions.zsh: $(SRC_TARGETS) LICENSE
mkdir -p $(DIST_DIR)
cat INFO | sed -e 's/^/# /g' > $@
echo "#" >> $@
cat LICENSE | sed -e 's/^/# /g' >> $@
cat >> $@ $(SRC_TARGETS)
HEADER_FILES := \
DESCRIPTION \
URL \
VERSION \
LICENSE
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
clean:
rm -rf $(DIST_DIR)
rm $(ALL_TARGETS)
.PHONY: test
test: $(DIST_DIR)/autosuggestions.zsh $(SCRIPT_DIR)/test.sh
$(SCRIPT_DIR)/test.sh
test: all
$(SCRIPT_DIR)/test.zsh

View file

@ -7,6 +7,8 @@ It suggests commands as you type, based on command history.
## Installation
### Manual
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
```sh
@ -16,11 +18,10 @@ It suggests commands as you type, based on command history.
2. Add the following to your `.zshrc`:
```sh
source ~/.zsh/zsh-autosuggestions/dist/autosuggestions.zsh
autosuggest_start
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
```
**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
@ -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_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.
@ -72,22 +71,6 @@ bindkey '^ ' autosuggest-accept
## 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)
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)
```
Make sure you add/remove these widgets *before* calling `autosuggest_start`.
For example:
```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
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)
autosuggest_start
```
@ -152,7 +131,7 @@ When reporting an issue, please include:
### 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

1
URL Normal file
View file

@ -0,0 +1 @@
https://github.com/tarruda/zsh-autosuggestions

1
VERSION Normal file
View file

@ -0,0 +1 @@
v0.2.0

View file

@ -2,9 +2,9 @@
SCRIPT_DIR=$(dirname "$0")
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() {
assertEquals \

View file

@ -4,7 +4,10 @@
#-------#
# Start the autosuggestion widgets
autosuggest_start() {
_zsh_autosuggest_start() {
_zsh_autosuggest_check_deprecated_config
_zsh_autosuggest_bind_widgets
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd _zsh_autosuggest_start

View file

@ -1,7 +1,6 @@
# Fish-like fast/unobtrusive autosuggestions for zsh.
# https://github.com/tarruda/zsh-autosuggestions
# v0.1.1
#
# v0.2.0
# Copyright (c) 2013 Thiago de Arruda
# Copyright (c) 2016 Eric Freese
#
@ -339,7 +338,10 @@ _zsh_autosuggest_suggestion() {
#-------#
# Start the autosuggestion widgets
autosuggest_start() {
_zsh_autosuggest_start() {
_zsh_autosuggest_check_deprecated_config
_zsh_autosuggest_bind_widgets
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd _zsh_autosuggest_start