Compare commits

...

8 Commits

Author SHA1 Message Date
Eric Freese
0ae5907294 [README] Add note about Oh My Zsh paste bug. 2016-02-13 09:59:16 -07:00
Eric Freese
03bd381112 Add .plugin file and installation instructions for Oh My Zsh (#104). 2016-02-07 15:35:54 -07:00
Eric Freese
00bd0e9125 Use add-zsh-hook to remove need to call autosuggest_start. 2016-02-07 15:35:43 -07:00
Eric Freese
48d2dc1091 Remove absolute link in readme. 2016-02-07 14:50:00 -07:00
Eric Freese
f154d25fb3 Fix typo when setting up autosuggest-clear widget. 2016-02-07 08:58:09 -07:00
Eric Freese
e91db46ce0 Add Development section to README (#106) 2016-02-07 08:52:52 -07:00
Eric Freese
28836f15c5 Test script should be a .zsh file instead of .sh 2016-02-07 08:52:34 -07:00
Eric Freese
0dd1b7febb Add Troubleshooting section to README 2016-02-07 08:52:07 -07:00
11 changed files with 108 additions and 50 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.0

View File

@@ -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,32 @@ 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
OH_MY_ZSH_LINK_TARGET := zsh-autosuggestions.plugin.zsh
ALL_TARGETS := \
$(PLUGIN_TARGET) \
$(OH_MY_ZSH_LINK_TARGET)
all: $(ALL_TARGETS)
$(PLUGIN_TARGET): $(HEADER_FILES) $(SRC_FILES)
cat $(HEADER_FILES) | sed -e 's/^/# /g' >> $@
cat $(SRC_FILES) >> $@
$(OH_MY_ZSH_LINK_TARGET): $(PLUGIN_TARGET)
ln -s $(PLUGIN_TARGET) $@
.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

View File

@@ -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,29 @@ 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.
### Oh My Zsh
1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`)
```sh
git clone git://github.com/tarruda/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
```
2. Add the plugin to the list of plugins for Oh My Zsh to load:
```sh
plugins=(zsh-autosuggestions)
```
3. Start a new terminal session.
> **Note:** There is an open issue ([#102](https://github.com/tarruda/zsh-autosuggestions/issues/102)) when using this plugin with `bracketed-paste-magic`, which is enabled by default by Oh My Zsh.
## Usage ## Usage
@@ -34,7 +54,9 @@ If you invoke the `forward-word` widget, it will partially accept the suggestion
## Configuration ## Configuration
You may want to override the default global config variables after sourcing the plugin. Default values of these variables can be found [here](https://github.com/tarruda/zsh-autosuggestions/blob/master/src/config.zsh). You may want to override the default global config variables after sourcing the plugin. Default values of these variables can be found [here](src/config.zsh).
**Note:** If you are using Oh My Zsh, you can put this configuration in a file in the `$ZSH_CUSTOM` directory. See their comments on [overriding internals](https://github.com/robbyrussell/oh-my-zsh/wiki/Customization#overriding-internals).
### Suggestion Highlight Style ### Suggestion Highlight Style
@@ -51,8 +73,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,23 +92,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.
@@ -107,21 +110,33 @@ 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
``` ```
## Troubleshooting
If you have a problem, please search through [the list of issues on GitHub](https://github.com/tarruda/zsh-autosuggestions/issues) to see if someone else has already reported it.
### Reporting an Issue
Before reporting an issue, please try temporarily disabling sections of your configuration and other plugins that may be conflicting with this plugin to isolate the problem.
When reporting an issue, please include:
- The smallest, simplest `.zshrc` configuration that will reproduce the problem
- The version of zsh you're using (`zsh --version`)
- Which operating system you're running
## Uninstallation ## Uninstallation
1. Remove the code referencing this plugin from `~/.zshrc`. 1. Remove the code referencing this plugin from `~/.zshrc`.
@@ -133,6 +148,29 @@ autosuggest_start
``` ```
## Development
### Build Process
Edit the source files in `src/`. Run `make` to build `zsh-autosuggestions.zsh` from those source files.
### Pull Requests
Pull requests are welcome! If you send a pull request, please:
- Match the existing coding conventions.
- Include helpful comments to keep the barrier-to-entry low for people new to the project.
- Write tests that cover your code as much as possible.
### Testing
Testing is performed with [`shunit2`](https://github.com/kward/shunit2) (v2.1.6). Documentation can be found [here](http://shunit2.googlecode.com/svn/trunk/source/2.1/doc/shunit2.html).
The test script lives at `script/test.zsh`. To run the tests, run `make test`.
## License ## License
This project is licensed under [MIT license](http://opensource.org/licenses/MIT). This project is licensed under [MIT license](http://opensource.org/licenses/MIT).

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") 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 \

View File

@@ -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

View File

@@ -84,4 +84,4 @@ _zsh_autosuggest_widget_clear() {
} }
zle -N autosuggest-accept _zsh_autosuggest_widget_accept zle -N autosuggest-accept _zsh_autosuggest_widget_accept
zle -N autosuggest-clear _zsh_autosuggest_clear zle -N autosuggest-clear _zsh_autosuggest_widget_clear

View File

@@ -0,0 +1 @@
zsh-autosuggestions.zsh

View File

@@ -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.0 # 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
# #
@@ -313,7 +312,7 @@ _zsh_autosuggest_widget_clear() {
} }
zle -N autosuggest-accept _zsh_autosuggest_widget_accept zle -N autosuggest-accept _zsh_autosuggest_widget_accept
zle -N autosuggest-clear _zsh_autosuggest_clear zle -N autosuggest-clear _zsh_autosuggest_widget_clear
#------------# #------------#
# Suggestion # # Suggestion #
@@ -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