mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2026-11-11 11:01:51 -05:00
Compare commits
43
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
146020d9b2 | ||
|
|
0636a39b51 | ||
|
|
6769c941ba | ||
|
|
371d6441c0 | ||
|
|
78e4379711 | ||
|
|
c80605595c | ||
|
|
cb52adf429 | ||
|
|
cdf6be4f06 | ||
|
|
66a6de3fb5 | ||
|
|
2498dbab75 | ||
|
|
676aebdf44 | ||
|
|
ec43fcfccf | ||
|
|
f5236c4351 | ||
|
|
d27983b7ca | ||
|
|
d14b17fb09 | ||
|
|
b24b607fbf | ||
|
|
a437544cc5 | ||
|
|
112dd3e3c7 | ||
|
|
8a812bdfd2 | ||
|
|
f178efb847 | ||
|
|
48ffc1bf92 | ||
|
|
adb02c44a2 | ||
|
|
3654b83ec0 | ||
|
|
b3b34eab49 | ||
|
|
19c976f62a | ||
|
|
3250778ce8 | ||
|
|
43ba841742 | ||
|
|
86f64c30ca | ||
|
|
f543ba08c3 | ||
|
|
68343c8de4 | ||
|
|
e263845bed | ||
|
|
d94475ca1b | ||
|
|
c04e015d13 | ||
|
|
e9ce05c4c1 | ||
|
|
fdf4502c5c | ||
|
|
7e048c3f53 | ||
|
|
2b05f5ed2d | ||
|
|
5339d2703d | ||
|
|
0d3bbaf8e6 | ||
|
|
848aa741f4 | ||
|
|
1c3e3fd939 | ||
|
|
527fd17ffc | ||
|
|
1912726460 |
+18
-1
@@ -1,5 +1,22 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v0.6.3
|
||||||
|
- Fixed bug moving cursor to end of buffer after accepting suggestion (#453)
|
||||||
|
|
||||||
|
## v0.6.2
|
||||||
|
- Fixed bug deleting the last character in the buffer in vi mode (#450)
|
||||||
|
- Degrade gracefully when user doesn't have `zsh/system` module installed (#447)
|
||||||
|
|
||||||
|
## v0.6.1
|
||||||
|
- Fixed bug occurring when `_complete` had been aliased (#443)
|
||||||
|
|
||||||
|
## v0.6.0
|
||||||
|
- Added `completion` suggestion strategy powered by completion system (#111)
|
||||||
|
- Allow setting `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an empty string (#422)
|
||||||
|
- Don't fetch suggestions after copy-earlier-word (#439)
|
||||||
|
- Allow users to unignore zle-\* widgets (e.g. zle-line-init) (#432)
|
||||||
|
|
||||||
|
|
||||||
## v0.5.2
|
## v0.5.2
|
||||||
- Allow disabling automatic widget re-binding for better performance (#418)
|
- Allow disabling automatic widget re-binding for better performance (#418)
|
||||||
- Fix async suggestions when `SH_WORD_SPLIT` is set
|
- Fix async suggestions when `SH_WORD_SPLIT` is set
|
||||||
@@ -46,7 +63,7 @@
|
|||||||
- Experimental support for asynchronous suggestions (#170)
|
- Experimental support for asynchronous suggestions (#170)
|
||||||
- Fix problems with multi-line suggestions (#225)
|
- Fix problems with multi-line suggestions (#225)
|
||||||
- Optimize case where manually typing in suggestion
|
- Optimize case where manually typing in suggestion
|
||||||
- Avoid wrapping any zle-* widgets (#206)
|
- Avoid wrapping any zle-\* widgets (#206)
|
||||||
- Remove support for deprecated options from v0.0.x
|
- Remove support for deprecated options from v0.0.x
|
||||||
- Handle history entries that begin with dashes
|
- Handle history entries that begin with dashes
|
||||||
- Gracefully handle being sourced multiple times (#126)
|
- Gracefully handle being sourced multiple times (#126)
|
||||||
|
|||||||
+13
-7
@@ -1,6 +1,12 @@
|
|||||||
## Installation
|
# Installation
|
||||||
|
|
||||||
### Manual (Git Clone)
|
* [Manual](#manual-git-clone)
|
||||||
|
* [Antigen](#antigen)
|
||||||
|
* [Oh My Zsh](#oh-my-zsh)
|
||||||
|
* [Arch Linux](#arch-linux)
|
||||||
|
* [macOS via Homebrew](#macos-via-homebrew)
|
||||||
|
|
||||||
|
## Manual (Git Clone)
|
||||||
|
|
||||||
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`.
|
||||||
|
|
||||||
@@ -16,7 +22,7 @@
|
|||||||
|
|
||||||
3. Start a new terminal session.
|
3. Start a new terminal session.
|
||||||
|
|
||||||
### Antigen
|
## Antigen
|
||||||
|
|
||||||
1. Add the following to your `.zshrc`:
|
1. Add the following to your `.zshrc`:
|
||||||
|
|
||||||
@@ -26,7 +32,7 @@
|
|||||||
|
|
||||||
2. Start a new terminal session.
|
2. Start a new terminal session.
|
||||||
|
|
||||||
### Oh My Zsh
|
## Oh My Zsh
|
||||||
|
|
||||||
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`)
|
||||||
|
|
||||||
@@ -42,7 +48,7 @@
|
|||||||
|
|
||||||
3. Start a new terminal session.
|
3. Start a new terminal session.
|
||||||
|
|
||||||
### Arch Linux
|
## Arch Linux
|
||||||
|
|
||||||
1. Install [`zsh-autosuggestions`](https://www.archlinux.org/packages/community/any/zsh-autosuggestions/) from the `community` repository.
|
1. Install [`zsh-autosuggestions`](https://www.archlinux.org/packages/community/any/zsh-autosuggestions/) from the `community` repository.
|
||||||
|
|
||||||
@@ -60,7 +66,8 @@
|
|||||||
|
|
||||||
3. Start a new terminal session.
|
3. Start a new terminal session.
|
||||||
|
|
||||||
### macOS via Homebrew
|
## macOS via Homebrew
|
||||||
|
|
||||||
1. Install the `zsh-autosuggestions` package using [Homebrew](https://brew.sh/).
|
1. Install the `zsh-autosuggestions` package using [Homebrew](https://brew.sh/).
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -74,4 +81,3 @@
|
|||||||
```
|
```
|
||||||
|
|
||||||
3. Start a new terminal session.
|
3. Start a new terminal session.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Copyright (c) 2013 Thiago de Arruda
|
Copyright (c) 2013 Thiago de Arruda
|
||||||
Copyright (c) 2016-2018 Eric Freese
|
Copyright (c) 2016-2019 Eric Freese
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
Permission is hereby granted, free of charge, to any person
|
||||||
obtaining a copy of this software and associated documentation
|
obtaining a copy of this software and associated documentation
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
_[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
|
_[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
|
||||||
|
|
||||||
It suggests commands as you type.
|
It suggests commands as you type based on history and completions.
|
||||||
|
|
||||||
Requirements: Zsh v4.3.11 or later
|
Requirements: Zsh v4.3.11 or later
|
||||||
|
|
||||||
@@ -44,6 +44,8 @@ ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"
|
|||||||
|
|
||||||
For more info, read the Character Highlighting section of the zsh manual: `man zshzle` or [online](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting).
|
For more info, read the Character Highlighting section of the zsh manual: `man zshzle` or [online](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting).
|
||||||
|
|
||||||
|
**Note:** Some iTerm2 users have reported [not being able to see the suggestions](https://github.com/zsh-users/zsh-autosuggestions/issues/416#issuecomment-486516333). If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black are **different**.
|
||||||
|
|
||||||
|
|
||||||
### Suggestion Strategy
|
### Suggestion Strategy
|
||||||
|
|
||||||
@@ -106,8 +108,7 @@ bindkey '^ ' autosuggest-accept
|
|||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
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.
|
If you have a problem, please search through [the list of issues on GitHub](https://github.com/zsh-users/zsh-autosuggestions/issues?q=) to see if someone else has already reported it.
|
||||||
|
|
||||||
|
|
||||||
### Reporting an Issue
|
### Reporting an Issue
|
||||||
|
|
||||||
|
|||||||
@@ -63,5 +63,18 @@ describe 'when using vi mode' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
describe '`vi-delete`' do
|
||||||
|
it 'should be able to remove the last character in the buffer' do
|
||||||
|
skip 'deleting last char did not work below zsh version 5.0.8' if session.zsh_version < Gem::Version.new('5.0.8')
|
||||||
|
|
||||||
|
session.
|
||||||
|
send_string('echo foo').
|
||||||
|
send_keys('escape').
|
||||||
|
send_keys('d').
|
||||||
|
send_keys('l')
|
||||||
|
|
||||||
|
wait_for { session.content }.to eq('echo fo')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
context 'with zle-line-init unignored' do
|
||||||
|
let(:after_sourcing) do
|
||||||
|
-> do
|
||||||
|
session.
|
||||||
|
run_command('setopt extendedglob').
|
||||||
|
run_command('ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(${(@)ZSH_AUTOSUGGEST_IGNORE_WIDGETS:#zle-\*} zle-\^line-init)').
|
||||||
|
run_command('zle-line-init() { BUFFER="echo" }')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fetch a suggestion on each line initialization' do
|
||||||
|
with_history('echo foo') do
|
||||||
|
session.run_command('zle -N zle-line-init')
|
||||||
|
wait_for { session.content }.to end_with('echo foo')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,12 +5,13 @@ describe 'a zle widget' do
|
|||||||
context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
|
context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
|
||||||
let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] }
|
let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] }
|
||||||
|
|
||||||
it 'accepts the suggestion when invoked' do
|
it 'accepts the suggestion and moves the cursor to the end of the buffer when invoked' do
|
||||||
with_history('echo hello') do
|
with_history('echo hello') do
|
||||||
session.send_string('e')
|
session.send_string('e')
|
||||||
wait_for { session.content }.to eq('echo hello')
|
wait_for { session.content }.to eq('echo hello')
|
||||||
session.send_keys('C-b')
|
session.send_keys('C-b')
|
||||||
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
||||||
|
wait_for { session.cursor }.to eq([10, 0])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ describe 'the `completion` suggestion strategy' do
|
|||||||
-> do
|
-> do
|
||||||
session.
|
session.
|
||||||
run_command('autoload compinit && compinit').
|
run_command('autoload compinit && compinit').
|
||||||
run_command('_foo() { compadd bar }').
|
run_command('_foo() { compadd bar; compadd bat }').
|
||||||
run_command('compdef _foo baz')
|
run_command('compdef _foo baz')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -14,6 +14,29 @@ describe 'the `completion` suggestion strategy' do
|
|||||||
wait_for { session.content }.to eq('baz bar')
|
wait_for { session.content }.to eq('baz bar')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not add extra carriage returns when prefix has a line feed' do
|
||||||
|
skip '`stty` does not work inside zpty below zsh version 5.0.3' if session.zsh_version < Gem::Version.new('5.0.3')
|
||||||
|
session.send_string('baz \\').send_keys('C-v', 'C-j')
|
||||||
|
wait_for { session.content }.to eq("baz \\\nbar")
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when `_complete` is aliased' do
|
||||||
|
let(:before_sourcing) do
|
||||||
|
-> do
|
||||||
|
session.
|
||||||
|
run_command('autoload compinit && compinit').
|
||||||
|
run_command('_foo() { compadd bar; compadd bat }').
|
||||||
|
run_command('compdef _foo baz').
|
||||||
|
run_command('alias _complete=_complete')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'suggests the first completion result' do
|
||||||
|
session.send_string('baz ')
|
||||||
|
wait_for { session.content }.to eq('baz bar')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when async mode is enabled' do
|
context 'when async mode is enabled' do
|
||||||
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }
|
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }
|
||||||
|
|
||||||
@@ -21,6 +44,12 @@ describe 'the `completion` suggestion strategy' do
|
|||||||
session.send_string('baz ')
|
session.send_string('baz ')
|
||||||
wait_for { session.content }.to eq('baz bar')
|
wait_for { session.content }.to eq('baz bar')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not add extra carriage returns when prefix has a line feed' do
|
||||||
|
skip '`stty` does not work inside zpty below zsh version 5.0.3' if session.zsh_version < Gem::Version.new('5.0.3')
|
||||||
|
session.send_string('baz \\').send_keys('C-v', 'C-j')
|
||||||
|
wait_for { session.content }.to eq("baz \\\nbar")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+20
-14
@@ -3,9 +3,9 @@
|
|||||||
# Async #
|
# Async #
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
|
|
||||||
zmodload zsh/system
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_request() {
|
_zsh_autosuggest_async_request() {
|
||||||
|
zmodload zsh/system 2>/dev/null # For `$sysparams`
|
||||||
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
||||||
|
|
||||||
# If we've got a pending request, cancel it
|
# If we've got a pending request, cancel it
|
||||||
@@ -14,17 +14,20 @@ _zsh_autosuggest_async_request() {
|
|||||||
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
||||||
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||||
|
|
||||||
# Zsh will make a new process group for the child process only if job
|
# We won't know the pid unless the user has zsh/system module installed
|
||||||
# control is enabled (MONITOR option)
|
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
|
||||||
if [[ -o MONITOR ]]; then
|
# Zsh will make a new process group for the child process only if job
|
||||||
# Send the signal to the process group to kill any processes that may
|
# control is enabled (MONITOR option)
|
||||||
# have been forked by the suggestion strategy
|
if [[ -o MONITOR ]]; then
|
||||||
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
# Send the signal to the process group to kill any processes that may
|
||||||
else
|
# have been forked by the suggestion strategy
|
||||||
# Kill just the child process since it wasn't placed in a new process
|
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||||
# group. If the suggestion strategy forked any child processes they may
|
else
|
||||||
# be orphaned and left behind.
|
# Kill just the child process since it wasn't placed in a new process
|
||||||
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
# group. If the suggestion strategy forked any child processes they may
|
||||||
|
# be orphaned and left behind.
|
||||||
|
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -56,9 +59,12 @@ _zsh_autosuggest_async_request() {
|
|||||||
_zsh_autosuggest_async_response() {
|
_zsh_autosuggest_async_response() {
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
|
local suggestion
|
||||||
|
|
||||||
if [[ -z "$2" || "$2" == "hup" ]]; then
|
if [[ -z "$2" || "$2" == "hup" ]]; then
|
||||||
# Read everything from the fd and give it as a suggestion
|
# Read everything from the fd and give it as a suggestion
|
||||||
zle autosuggest-suggest -- "$(cat <&$1)"
|
IFS='' read -rd '' -u $1 suggestion
|
||||||
|
zle autosuggest-suggest -- "$suggestion"
|
||||||
|
|
||||||
# Close the fd
|
# Close the fd
|
||||||
exec {1}<&-
|
exec {1}<&-
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
ignore_widgets=(
|
ignore_widgets=(
|
||||||
.\*
|
.\*
|
||||||
_\*
|
_\*
|
||||||
zle-\*
|
|
||||||
autosuggest-\*
|
autosuggest-\*
|
||||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
|||||||
which-command
|
which-command
|
||||||
yank
|
yank
|
||||||
yank-pop
|
yank-pop
|
||||||
|
zle-\*
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,13 @@ _zsh_autosuggest_capture_postcompletion() {
|
|||||||
compstate[insert]=1
|
compstate[insert]=1
|
||||||
|
|
||||||
# Don't list completions
|
# Don't list completions
|
||||||
unset compstate[list]
|
unset 'compstate[list]'
|
||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_widget() {
|
_zsh_autosuggest_capture_completion_widget() {
|
||||||
|
# Add a post-completion hook to be called after all completions have been
|
||||||
|
# gathered. The hook can modify compstate to affect what is done with the
|
||||||
|
# gathered completions.
|
||||||
local -a +h comppostfuncs
|
local -a +h comppostfuncs
|
||||||
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
||||||
|
|
||||||
@@ -25,6 +28,16 @@ _zsh_autosuggest_capture_completion_widget() {
|
|||||||
# after autosuggestions is initialized.
|
# after autosuggestions is initialized.
|
||||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
||||||
|
|
||||||
|
if is-at-least 5.0.3; then
|
||||||
|
# Don't do any cr/lf transformations. We need to do this immediately before
|
||||||
|
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
||||||
|
# vared in the async code path. There is a bug in zpty module in older versions
|
||||||
|
# where the tty is not properly attached to the pty slave, resulting in stty
|
||||||
|
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
||||||
|
# commit f75904a38
|
||||||
|
stty -onlcr -ocrnl -F /dev/tty
|
||||||
|
fi
|
||||||
|
|
||||||
# The completion has been added, print the buffer as the suggestion
|
# The completion has been added, print the buffer as the suggestion
|
||||||
echo -nE - $'\0'$BUFFER$'\0'
|
echo -nE - $'\0'$BUFFER$'\0'
|
||||||
}
|
}
|
||||||
@@ -32,6 +45,8 @@ _zsh_autosuggest_capture_completion_widget() {
|
|||||||
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
||||||
|
|
||||||
_zsh_autosuggest_capture_setup() {
|
_zsh_autosuggest_capture_setup() {
|
||||||
|
autoload -Uz is-at-least
|
||||||
|
|
||||||
# There is a bug in zpty module in older zsh versions by which a
|
# There is a bug in zpty module in older zsh versions by which a
|
||||||
# zpty that exits will kill all zpty processes that were forked
|
# zpty that exits will kill all zpty processes that were forked
|
||||||
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
||||||
@@ -39,8 +54,12 @@ _zsh_autosuggest_capture_setup() {
|
|||||||
# zpty processes.
|
# zpty processes.
|
||||||
if ! is-at-least 5.4; then
|
if ! is-at-least 5.4; then
|
||||||
zshexit() {
|
zshexit() {
|
||||||
kill -KILL $$
|
# The zsh builtin `kill` fails sometimes in older versions
|
||||||
sleep 1 # Block for long enough for the signal to come through
|
# https://unix.stackexchange.com/a/477647/156673
|
||||||
|
kill -KILL $$ 2>&- || command kill -KILL $$
|
||||||
|
|
||||||
|
# Block for long enough for the signal to come through
|
||||||
|
sleep 1
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -67,7 +86,7 @@ _zsh_autosuggest_capture_completion_async() {
|
|||||||
# https://stackoverflow.com/a/7057118/154703
|
# https://stackoverflow.com/a/7057118/154703
|
||||||
autoload +X _complete
|
autoload +X _complete
|
||||||
functions[_original_complete]=$functions[_complete]
|
functions[_original_complete]=$functions[_complete]
|
||||||
_complete () {
|
function _complete() {
|
||||||
unset 'compstate[vared]'
|
unset 'compstate[vared]'
|
||||||
_original_complete "$@"
|
_original_complete "$@"
|
||||||
}
|
}
|
||||||
@@ -99,9 +118,11 @@ _zsh_autosuggest_strategy_completion() {
|
|||||||
# content between the first two null bytes.
|
# content between the first two null bytes.
|
||||||
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
||||||
|
|
||||||
# On older versions of zsh, we sometimes get extra bytes after the
|
# Extract the suggestion from between the null bytes. On older
|
||||||
# second null byte, so trim those off the end
|
# versions of zsh (older than 5.3), we sometimes get extra bytes after
|
||||||
suggestion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}"
|
# the second null byte, so trim those off the end.
|
||||||
|
# See http://www.zsh.org/mla/workers/2015/msg03290.html
|
||||||
|
suggestion="${${line#*$'\0'}%$'\0'*}"
|
||||||
} always {
|
} always {
|
||||||
# Destroy the pty
|
# Destroy the pty
|
||||||
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
||||||
|
|||||||
+5
-1
@@ -136,7 +136,11 @@ _zsh_autosuggest_accept() {
|
|||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
|
|
||||||
# Move the cursor to the end of the buffer
|
# Move the cursor to the end of the buffer
|
||||||
CURSOR=${#BUFFER}
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
|
CURSOR=$(($#BUFFER - 1))
|
||||||
|
else
|
||||||
|
CURSOR=$#BUFFER
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
|
|||||||
+56
-25
@@ -1,8 +1,8 @@
|
|||||||
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
||||||
# https://github.com/zsh-users/zsh-autosuggestions
|
# https://github.com/zsh-users/zsh-autosuggestions
|
||||||
# v0.5.2
|
# v0.6.3
|
||||||
# Copyright (c) 2013 Thiago de Arruda
|
# Copyright (c) 2013 Thiago de Arruda
|
||||||
# Copyright (c) 2016-2018 Eric Freese
|
# Copyright (c) 2016-2019 Eric Freese
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person
|
# Permission is hereby granted, free of charge, to any person
|
||||||
# obtaining a copy of this software and associated documentation
|
# obtaining a copy of this software and associated documentation
|
||||||
@@ -110,6 +110,7 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
|||||||
which-command
|
which-command
|
||||||
yank
|
yank
|
||||||
yank-pop
|
yank-pop
|
||||||
|
zle-\*
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +199,6 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
ignore_widgets=(
|
ignore_widgets=(
|
||||||
.\*
|
.\*
|
||||||
_\*
|
_\*
|
||||||
zle-\*
|
|
||||||
autosuggest-\*
|
autosuggest-\*
|
||||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||||
@@ -398,7 +398,11 @@ _zsh_autosuggest_accept() {
|
|||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
|
|
||||||
# Move the cursor to the end of the buffer
|
# Move the cursor to the end of the buffer
|
||||||
CURSOR=${#BUFFER}
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
|
CURSOR=$(($#BUFFER - 1))
|
||||||
|
else
|
||||||
|
CURSOR=$#BUFFER
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
@@ -492,10 +496,13 @@ _zsh_autosuggest_capture_postcompletion() {
|
|||||||
compstate[insert]=1
|
compstate[insert]=1
|
||||||
|
|
||||||
# Don't list completions
|
# Don't list completions
|
||||||
unset compstate[list]
|
unset 'compstate[list]'
|
||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_capture_completion_widget() {
|
_zsh_autosuggest_capture_completion_widget() {
|
||||||
|
# Add a post-completion hook to be called after all completions have been
|
||||||
|
# gathered. The hook can modify compstate to affect what is done with the
|
||||||
|
# gathered completions.
|
||||||
local -a +h comppostfuncs
|
local -a +h comppostfuncs
|
||||||
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
||||||
|
|
||||||
@@ -507,6 +514,16 @@ _zsh_autosuggest_capture_completion_widget() {
|
|||||||
# after autosuggestions is initialized.
|
# after autosuggestions is initialized.
|
||||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
||||||
|
|
||||||
|
if is-at-least 5.0.3; then
|
||||||
|
# Don't do any cr/lf transformations. We need to do this immediately before
|
||||||
|
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
||||||
|
# vared in the async code path. There is a bug in zpty module in older versions
|
||||||
|
# where the tty is not properly attached to the pty slave, resulting in stty
|
||||||
|
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
||||||
|
# commit f75904a38
|
||||||
|
stty -onlcr -ocrnl -F /dev/tty
|
||||||
|
fi
|
||||||
|
|
||||||
# The completion has been added, print the buffer as the suggestion
|
# The completion has been added, print the buffer as the suggestion
|
||||||
echo -nE - $'\0'$BUFFER$'\0'
|
echo -nE - $'\0'$BUFFER$'\0'
|
||||||
}
|
}
|
||||||
@@ -514,6 +531,8 @@ _zsh_autosuggest_capture_completion_widget() {
|
|||||||
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
||||||
|
|
||||||
_zsh_autosuggest_capture_setup() {
|
_zsh_autosuggest_capture_setup() {
|
||||||
|
autoload -Uz is-at-least
|
||||||
|
|
||||||
# There is a bug in zpty module in older zsh versions by which a
|
# There is a bug in zpty module in older zsh versions by which a
|
||||||
# zpty that exits will kill all zpty processes that were forked
|
# zpty that exits will kill all zpty processes that were forked
|
||||||
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
||||||
@@ -521,8 +540,12 @@ _zsh_autosuggest_capture_setup() {
|
|||||||
# zpty processes.
|
# zpty processes.
|
||||||
if ! is-at-least 5.4; then
|
if ! is-at-least 5.4; then
|
||||||
zshexit() {
|
zshexit() {
|
||||||
kill -KILL $$
|
# The zsh builtin `kill` fails sometimes in older versions
|
||||||
sleep 1 # Block for long enough for the signal to come through
|
# https://unix.stackexchange.com/a/477647/156673
|
||||||
|
kill -KILL $$ 2>&- || command kill -KILL $$
|
||||||
|
|
||||||
|
# Block for long enough for the signal to come through
|
||||||
|
sleep 1
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -549,7 +572,7 @@ _zsh_autosuggest_capture_completion_async() {
|
|||||||
# https://stackoverflow.com/a/7057118/154703
|
# https://stackoverflow.com/a/7057118/154703
|
||||||
autoload +X _complete
|
autoload +X _complete
|
||||||
functions[_original_complete]=$functions[_complete]
|
functions[_original_complete]=$functions[_complete]
|
||||||
_complete () {
|
function _complete() {
|
||||||
unset 'compstate[vared]'
|
unset 'compstate[vared]'
|
||||||
_original_complete "$@"
|
_original_complete "$@"
|
||||||
}
|
}
|
||||||
@@ -581,9 +604,11 @@ _zsh_autosuggest_strategy_completion() {
|
|||||||
# content between the first two null bytes.
|
# content between the first two null bytes.
|
||||||
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
||||||
|
|
||||||
# On older versions of zsh, we sometimes get extra bytes after the
|
# Extract the suggestion from between the null bytes. On older
|
||||||
# second null byte, so trim those off the end
|
# versions of zsh (older than 5.3), we sometimes get extra bytes after
|
||||||
suggestion="${${${(M)line:#*$'\0'*$'\0'*}#*$'\0'}%%$'\0'*}"
|
# the second null byte, so trim those off the end.
|
||||||
|
# See http://www.zsh.org/mla/workers/2015/msg03290.html
|
||||||
|
suggestion="${${line#*$'\0'}%$'\0'*}"
|
||||||
} always {
|
} always {
|
||||||
# Destroy the pty
|
# Destroy the pty
|
||||||
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
||||||
@@ -705,9 +730,9 @@ _zsh_autosuggest_fetch_suggestion() {
|
|||||||
# Async #
|
# Async #
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
|
|
||||||
zmodload zsh/system
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_request() {
|
_zsh_autosuggest_async_request() {
|
||||||
|
zmodload zsh/system 2>/dev/null # For `$sysparams`
|
||||||
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
||||||
|
|
||||||
# If we've got a pending request, cancel it
|
# If we've got a pending request, cancel it
|
||||||
@@ -716,17 +741,20 @@ _zsh_autosuggest_async_request() {
|
|||||||
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
||||||
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||||
|
|
||||||
# Zsh will make a new process group for the child process only if job
|
# We won't know the pid unless the user has zsh/system module installed
|
||||||
# control is enabled (MONITOR option)
|
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
|
||||||
if [[ -o MONITOR ]]; then
|
# Zsh will make a new process group for the child process only if job
|
||||||
# Send the signal to the process group to kill any processes that may
|
# control is enabled (MONITOR option)
|
||||||
# have been forked by the suggestion strategy
|
if [[ -o MONITOR ]]; then
|
||||||
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
# Send the signal to the process group to kill any processes that may
|
||||||
else
|
# have been forked by the suggestion strategy
|
||||||
# Kill just the child process since it wasn't placed in a new process
|
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||||
# group. If the suggestion strategy forked any child processes they may
|
else
|
||||||
# be orphaned and left behind.
|
# Kill just the child process since it wasn't placed in a new process
|
||||||
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
# group. If the suggestion strategy forked any child processes they may
|
||||||
|
# be orphaned and left behind.
|
||||||
|
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -758,9 +786,12 @@ _zsh_autosuggest_async_request() {
|
|||||||
_zsh_autosuggest_async_response() {
|
_zsh_autosuggest_async_response() {
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
|
||||||
|
local suggestion
|
||||||
|
|
||||||
if [[ -z "$2" || "$2" == "hup" ]]; then
|
if [[ -z "$2" || "$2" == "hup" ]]; then
|
||||||
# Read everything from the fd and give it as a suggestion
|
# Read everything from the fd and give it as a suggestion
|
||||||
zle autosuggest-suggest -- "$(cat <&$1)"
|
IFS='' read -rd '' -u $1 suggestion
|
||||||
|
zle autosuggest-suggest -- "$suggestion"
|
||||||
|
|
||||||
# Close the fd
|
# Close the fd
|
||||||
exec {1}<&-
|
exec {1}<&-
|
||||||
|
|||||||
Reference in New Issue
Block a user