mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-06 23:30:39 +01:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0a745576f | ||
|
|
8935a39e9b | ||
|
|
c7c9929490 | ||
|
|
985de56f6e | ||
|
|
0a42f872b8 | ||
|
|
dd54925b06 | ||
|
|
c761dc8150 | ||
|
|
cc921994e6 | ||
|
|
0242c7eff1 | ||
|
|
9d100f4f32 | ||
|
|
ddb7284852 | ||
|
|
2a5791710a | ||
|
|
03fac1f0d7 | ||
|
|
aa859a282d | ||
|
|
f08a5a1baa | ||
|
|
70438d233d | ||
|
|
ba029e83d0 | ||
|
|
acc129de6c | ||
|
|
aa5ceee256 | ||
|
|
113ca0ad10 |
22
README.md
22
README.md
@@ -4,6 +4,8 @@ _[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
|
|||||||
|
|
||||||
It suggests commands as you type, based on command history.
|
It suggests commands as you type, based on command history.
|
||||||
|
|
||||||
|
<a href="https://asciinema.org/a/37390" target="_blank"><img src="https://asciinema.org/a/37390.png" width="400" /></a>
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ It suggests commands as you type, based on command history.
|
|||||||
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
|
||||||
git clone git://github.com/tarruda/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
|
git clone git://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Add the following to your `.zshrc`:
|
2. Add the following to your `.zshrc`:
|
||||||
@@ -29,7 +31,7 @@ It suggests commands as you type, based on command history.
|
|||||||
1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`)
|
1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone git://github.com/tarruda/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
|
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Add the plugin to the list of plugins for Oh My Zsh to load:
|
2. Add the plugin to the list of plugins for Oh My Zsh to load:
|
||||||
@@ -89,21 +91,9 @@ bindkey '^ ' autosuggest-accept
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Compatibility With Other ZLE Plugins
|
|
||||||
|
|
||||||
### [`zsh-history-substring-search`](https://github.com/zsh-users/zsh-history-substring-search)
|
|
||||||
|
|
||||||
The `history-substring-search-up` and `history-substring-search-down` widgets are not bound by default. You'll probably want to add them to `ZSH_AUTOSUGGEST_CLEAR_WIDGETS` so that the suggestion will be cleared when you start searching through history:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# Add history-substring-search-* widgets to list of widgets that clear the autosuggestion
|
|
||||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Troubleshooting
|
## 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.
|
If you have a problem, please search through [the list of issues on GitHub](https://github.com/zsh-users/zsh-autosuggestions/issues) to see if someone else has already reported it.
|
||||||
|
|
||||||
|
|
||||||
### Reporting an Issue
|
### Reporting an Issue
|
||||||
@@ -112,7 +102,7 @@ Before reporting an issue, please try temporarily disabling sections of your con
|
|||||||
|
|
||||||
When reporting an issue, please include:
|
When reporting an issue, please include:
|
||||||
|
|
||||||
- The smallest, simplest `.zshrc` configuration that will reproduce the problem. See [this comment](https://github.com/tarruda/zsh-autosuggestions/issues/102#issuecomment-180944764) for a good example of what this means.
|
- The smallest, simplest `.zshrc` configuration that will reproduce the problem. See [this comment](https://github.com/zsh-users/zsh-autosuggestions/issues/102#issuecomment-180944764) for a good example of what this means.
|
||||||
- The version of zsh you're using (`zsh --version`)
|
- The version of zsh you're using (`zsh --version`)
|
||||||
- Which operating system you're running
|
- Which operating system you're running
|
||||||
|
|
||||||
|
|||||||
2
URL
2
URL
@@ -1 +1 @@
|
|||||||
https://github.com/tarruda/zsh-autosuggestions
|
https://github.com/zsh-users/zsh-autosuggestions
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ testWidgetFunctionModify() {
|
|||||||
POSTDISPLAY=""
|
POSTDISPLAY=""
|
||||||
|
|
||||||
stub_and_eval \
|
stub_and_eval \
|
||||||
_zsh_autosuggest_invoke_original_widget \
|
_zsh_autosuggest_invoke_original_widget \
|
||||||
'BUFFER+="e"'
|
'BUFFER+="e"'
|
||||||
|
|
||||||
stub_and_echo \
|
stub_and_echo \
|
||||||
@@ -281,6 +281,43 @@ testWidgetClear() {
|
|||||||
"stub_called _zsh_autosuggest_highlight_apply"
|
"stub_called _zsh_autosuggest_highlight_apply"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testEscapeCommandPrefix() {
|
||||||
|
assertEquals \
|
||||||
|
"Did not escape single backslash" \
|
||||||
|
"\\\\" \
|
||||||
|
"$(_zsh_autosuggest_escape_command_prefix "\\")"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
"Did not escape two backslashes" \
|
||||||
|
"\\\\\\\\" \
|
||||||
|
"$(_zsh_autosuggest_escape_command_prefix "\\\\")"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
"Did not escape parentheses" \
|
||||||
|
"\\(\\)" \
|
||||||
|
"$(_zsh_autosuggest_escape_command_prefix "()")"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
"Did not escape square brackets" \
|
||||||
|
"\\[\\]" \
|
||||||
|
"$(_zsh_autosuggest_escape_command_prefix "[]")"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
"Did not escape pipe" \
|
||||||
|
"\\|" \
|
||||||
|
"$(_zsh_autosuggest_escape_command_prefix "|")"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
"Did not escape star" \
|
||||||
|
"\\*" \
|
||||||
|
"$(_zsh_autosuggest_escape_command_prefix "*")"
|
||||||
|
|
||||||
|
assertEquals \
|
||||||
|
"Did not escape question mark" \
|
||||||
|
"\\?" \
|
||||||
|
"$(_zsh_autosuggest_escape_command_prefix "?")"
|
||||||
|
}
|
||||||
|
|
||||||
# For zsh compatibility
|
# For zsh compatibility
|
||||||
setopt shwordsplit
|
setopt shwordsplit
|
||||||
SHUNIT_PARENT=$0
|
SHUNIT_PARENT=$0
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
|
|
||||||
# Given the name of an original widget and args, invoke it, if it exists
|
# Given the name of an original widget and args, invoke it, if it exists
|
||||||
_zsh_autosuggest_invoke_original_widget() {
|
_zsh_autosuggest_invoke_original_widget() {
|
||||||
|
# Do nothing unless called with at least one arg
|
||||||
|
[ $# -gt 0 ] || return
|
||||||
|
|
||||||
local original_widget_name=$1
|
local original_widget_name=$1
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
|||||||
history-search-backward
|
history-search-backward
|
||||||
history-beginning-search-forward
|
history-beginning-search-forward
|
||||||
history-beginning-search-backward
|
history-beginning-search-backward
|
||||||
|
history-substring-search-up
|
||||||
|
history-substring-search-down
|
||||||
up-line-or-history
|
up-line-or-history
|
||||||
down-line-or-history
|
down-line-or-history
|
||||||
accept-line
|
accept-line
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ _zsh_autosuggest_check_deprecated_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_deprecated_start_widget() {
|
_zsh_autosuggest_deprecated_start_widget() {
|
||||||
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/tarruda/zsh-autosuggestions."
|
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/zsh-users/zsh-autosuggestions."
|
||||||
zle -D autosuggest-start
|
zle -D autosuggest-start
|
||||||
eval "zle-line-init() {
|
eval "zle-line-init() {
|
||||||
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')
|
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ _zsh_autosuggest_highlight_reset() {
|
|||||||
_zsh_autosuggest_highlight_apply() {
|
_zsh_autosuggest_highlight_apply() {
|
||||||
if [ $#POSTDISPLAY -gt 0 ]; then
|
if [ $#POSTDISPLAY -gt 0 ]; then
|
||||||
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
||||||
region_highlight+=($_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT)
|
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
||||||
else
|
else
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -5,15 +5,19 @@
|
|||||||
|
|
||||||
# Get a suggestion from history that matches a given prefix
|
# Get a suggestion from history that matches a given prefix
|
||||||
_zsh_autosuggest_suggestion() {
|
_zsh_autosuggest_suggestion() {
|
||||||
setopt localoptions extendedglob
|
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
|
||||||
|
|
||||||
# Escape the prefix (requires EXTENDED_GLOB)
|
|
||||||
local prefix="${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}"
|
|
||||||
|
|
||||||
# Get all history items (reversed) that match pattern $prefix*
|
# Get all history items (reversed) that match pattern $prefix*
|
||||||
local history_matches
|
local history_matches
|
||||||
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
||||||
|
|
||||||
# Echo the first item that matches
|
# Echo the first item that matches
|
||||||
echo "$history_matches[1]"
|
echo -E "$history_matches[1]"
|
||||||
|
}
|
||||||
|
|
||||||
|
_zsh_autosuggest_escape_command_prefix() {
|
||||||
|
setopt localoptions EXTENDED_GLOB
|
||||||
|
|
||||||
|
# Escape special chars in the string (requires EXTENDED_GLOB)
|
||||||
|
echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +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/zsh-users/zsh-autosuggestions
|
||||||
# v0.2.10
|
# v0.2.17
|
||||||
# Copyright (c) 2013 Thiago de Arruda
|
# Copyright (c) 2013 Thiago de Arruda
|
||||||
# Copyright (c) 2016 Eric Freese
|
# Copyright (c) 2016 Eric Freese
|
||||||
#
|
#
|
||||||
@@ -43,6 +43,8 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
|||||||
history-search-backward
|
history-search-backward
|
||||||
history-beginning-search-forward
|
history-beginning-search-forward
|
||||||
history-beginning-search-backward
|
history-beginning-search-backward
|
||||||
|
history-substring-search-up
|
||||||
|
history-substring-search-down
|
||||||
up-line-or-history
|
up-line-or-history
|
||||||
down-line-or-history
|
down-line-or-history
|
||||||
accept-line
|
accept-line
|
||||||
@@ -92,7 +94,7 @@ _zsh_autosuggest_check_deprecated_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_deprecated_start_widget() {
|
_zsh_autosuggest_deprecated_start_widget() {
|
||||||
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/tarruda/zsh-autosuggestions."
|
_zsh_autosuggest_deprecated_warning "The autosuggest-start widget is deprecated. For more info, see the README at https://github.com/zsh-users/zsh-autosuggestions."
|
||||||
zle -D autosuggest-start
|
zle -D autosuggest-start
|
||||||
eval "zle-line-init() {
|
eval "zle-line-init() {
|
||||||
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')
|
$(echo $functions[${widgets[zle-line-init]#*:}] | sed -e 's/zle autosuggest-start//g')
|
||||||
@@ -168,6 +170,9 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
|
|
||||||
# Given the name of an original widget and args, invoke it, if it exists
|
# Given the name of an original widget and args, invoke it, if it exists
|
||||||
_zsh_autosuggest_invoke_original_widget() {
|
_zsh_autosuggest_invoke_original_widget() {
|
||||||
|
# Do nothing unless called with at least one arg
|
||||||
|
[ $# -gt 0 ] || return
|
||||||
|
|
||||||
local original_widget_name=$1
|
local original_widget_name=$1
|
||||||
|
|
||||||
shift
|
shift
|
||||||
@@ -193,7 +198,7 @@ _zsh_autosuggest_highlight_reset() {
|
|||||||
_zsh_autosuggest_highlight_apply() {
|
_zsh_autosuggest_highlight_apply() {
|
||||||
if [ $#POSTDISPLAY -gt 0 ]; then
|
if [ $#POSTDISPLAY -gt 0 ]; then
|
||||||
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
||||||
region_highlight+=($_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT)
|
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
||||||
else
|
else
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
fi
|
fi
|
||||||
@@ -288,17 +293,21 @@ zle -N autosuggest-clear _zsh_autosuggest_widget_clear
|
|||||||
|
|
||||||
# Get a suggestion from history that matches a given prefix
|
# Get a suggestion from history that matches a given prefix
|
||||||
_zsh_autosuggest_suggestion() {
|
_zsh_autosuggest_suggestion() {
|
||||||
setopt localoptions extendedglob
|
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
|
||||||
|
|
||||||
# Escape the prefix (requires EXTENDED_GLOB)
|
|
||||||
local prefix="${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}"
|
|
||||||
|
|
||||||
# Get all history items (reversed) that match pattern $prefix*
|
# Get all history items (reversed) that match pattern $prefix*
|
||||||
local history_matches
|
local history_matches
|
||||||
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
||||||
|
|
||||||
# Echo the first item that matches
|
# Echo the first item that matches
|
||||||
echo "$history_matches[1]"
|
echo -E "$history_matches[1]"
|
||||||
|
}
|
||||||
|
|
||||||
|
_zsh_autosuggest_escape_command_prefix() {
|
||||||
|
setopt localoptions EXTENDED_GLOB
|
||||||
|
|
||||||
|
# Escape special chars in the string (requires EXTENDED_GLOB)
|
||||||
|
echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
|
|||||||
Reference in New Issue
Block a user