diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..b69200f --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1 @@ +Fish-like fast/unobtrusive autosuggestions for zsh. diff --git a/INFO b/INFO deleted file mode 100644 index 32fcaba..0000000 --- a/INFO +++ /dev/null @@ -1,3 +0,0 @@ -Fish-like fast/unobtrusive autosuggestions for zsh. -https://github.com/tarruda/zsh-autosuggestions -v0.1.1 diff --git a/Makefile b/Makefile index 85d8264..7533d37 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 61a94c6..6159c7f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/URL b/URL new file mode 100644 index 0000000..00a4330 --- /dev/null +++ b/URL @@ -0,0 +1 @@ +https://github.com/tarruda/zsh-autosuggestions diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..1474d00 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v0.2.0 diff --git a/script/test.zsh b/script/test.zsh index b1c1b77..6284518 100755 --- a/script/test.zsh +++ b/script/test.zsh @@ -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 \ diff --git a/src/start.zsh b/src/start.zsh index f793e75..3b0d841 100644 --- a/src/start.zsh +++ b/src/start.zsh @@ -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 diff --git a/dist/autosuggestions.zsh b/zsh-autosuggestions.zsh similarity index 98% rename from dist/autosuggestions.zsh rename to zsh-autosuggestions.zsh index d81d9e9..8679f6f 100644 --- a/dist/autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -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