mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-06 23:30:39 +01:00
Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7c796719e | ||
|
|
aa0b10db44 | ||
|
|
72ccee33b4 | ||
|
|
c113e49fe2 | ||
|
|
3b39b9561c | ||
|
|
b003b2238a | ||
|
|
df5fb858aa | ||
|
|
726bc4eb5c | ||
|
|
59c72c6805 | ||
|
|
393f7b8bb9 | ||
|
|
42f5a06f7f | ||
|
|
51fef255da | ||
|
|
19ad3ba7cd | ||
|
|
b2b9bf3b8c | ||
|
|
67a364bc17 | ||
|
|
afc14f79cc | ||
|
|
60aff2d944 | ||
|
|
6dfe9c8cd8 | ||
|
|
3136700ccf | ||
|
|
2202ed7bac | ||
|
|
c978004c0e | ||
|
|
c7d4a85031 | ||
|
|
15931f04ff | ||
|
|
9f1046727a | ||
|
|
f462410b3c | ||
|
|
4ea825faf8 | ||
|
|
a1babef972 | ||
|
|
be8bba6f38 | ||
|
|
dda220f140 | ||
|
|
9f9237ab8a | ||
|
|
29257230fe | ||
|
|
940e10a691 | ||
|
|
9f1f322979 | ||
|
|
680ce21f26 | ||
|
|
256293cbb6 | ||
|
|
977e70e21b | ||
|
|
218acf2fbe | ||
|
|
0681a1c121 | ||
|
|
9e3f1bd359 | ||
|
|
ae4c344e82 | ||
|
|
7f8ff2867c | ||
|
|
33b91a9dea | ||
|
|
802f53a10a | ||
|
|
5e4487ed4a | ||
|
|
9e110406fa | ||
|
|
1915e28882 | ||
|
|
d6d9a46981 | ||
|
|
706499838c | ||
|
|
e304365745 | ||
|
|
4e72f7a91e |
28
CHANGELOG.md
28
CHANGELOG.md
@@ -1,14 +1,34 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v0.4.3
|
||||||
|
- Avoid bell when accepting suggestions with `autosuggest-accept` (#228)
|
||||||
|
- Don't fetch suggestions after [up,down]-line-or-beginning-search (#227, #241)
|
||||||
|
- We are now running CI against new 5.5.1 version
|
||||||
|
- Fix partial-accept in vi mode (#188)
|
||||||
|
- Fix suggestion disappearing on fast movement after switching to `vicmd` mode (#290)
|
||||||
|
- Fix issue rotating through kill ring with `yank-pop` (#301)
|
||||||
|
- Fix issue creating new pty for async mode when previous pty is not properly cleaned up (#249)
|
||||||
|
|
||||||
|
## v0.4.2
|
||||||
|
- Fix bug in zsh versions older than 5.0.8 (#296)
|
||||||
|
- Officially support back to zsh v4.3.11
|
||||||
|
|
||||||
|
## v0.4.1
|
||||||
|
- Switch to [[ and (( conditionals instead of [ (#257)
|
||||||
|
- Avoid warnnestedvar warnings with `typeset -g` (#275)
|
||||||
|
- Replace tabs with spaces in yaml (#268)
|
||||||
|
- Clean up and fix escaping of special characters (#267)
|
||||||
|
- Add `emacs-forward-word` to default list of partial accept widgets (#246)
|
||||||
|
|
||||||
## v0.4.0
|
## v0.4.0
|
||||||
- High-level integration tests using RSpec and tmux
|
- High-level integration tests using RSpec and tmux
|
||||||
- Add continuous integration with Circle CI
|
- Add continuous integration with Circle CI
|
||||||
- Experimental support for asynchronous suggestions (#)
|
- Experimental support for asynchronous suggestions (#170)
|
||||||
- Fix problems with multi-line suggestions (#)
|
- 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 (#)
|
- 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)
|
||||||
- Add enable/disable/toggle widgets to disable/enable suggestions (#219)
|
- Add enable/disable/toggle widgets to disable/enable suggestions (#219)
|
||||||
|
|
||||||
|
|||||||
67
INSTALL.md
Normal file
67
INSTALL.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
## Installation
|
||||||
|
|
||||||
|
### Manual (Git Clone)
|
||||||
|
|
||||||
|
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Add the following to your `.zshrc`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||||
|
```
|
||||||
|
|
||||||
|
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 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-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.
|
||||||
|
|
||||||
|
### Arch Linux
|
||||||
|
|
||||||
|
1. Install [`zsh-autosuggestions`](https://www.archlinux.org/packages/community/any/zsh-autosuggestions/) from the `community` repository.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pacman -S zsh-autosuggestions
|
||||||
|
```
|
||||||
|
|
||||||
|
or, to use a package based on the `master` branch, install [`zsh-autosuggestions-git`](https://aur.archlinux.org/packages/zsh-autosuggestions-git/) from the [AUR](https://wiki.archlinux.org/index.php/Arch_User_Repository).
|
||||||
|
|
||||||
|
2. Add the following to your `.zshrc`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Start a new terminal session.
|
||||||
|
|
||||||
|
### macOS via Homebrew
|
||||||
|
1. Install the `zsh-autosuggestions` package using [Homebrew](https://brew.sh/).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
brew install zsh-autosuggestions
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Add the following to your `.zshrc`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Start a new terminal session.
|
||||||
|
|
||||||
2
LICENSE
2
LICENSE
@@ -1,5 +1,5 @@
|
|||||||
Copyright (c) 2013 Thiago de Arruda
|
Copyright (c) 2013 Thiago de Arruda
|
||||||
Copyright (c) 2016-2017 Eric Freese
|
Copyright (c) 2016-2018 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
|
||||||
|
|||||||
35
README.md
35
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.
|
||||||
|
|
||||||
|
Requirements: Zsh v4.3.11 or later
|
||||||
|
|
||||||
[](https://circleci.com/gh/zsh-users/zsh-autosuggestions)
|
[](https://circleci.com/gh/zsh-users/zsh-autosuggestions)
|
||||||
|
|
||||||
<a href="https://asciinema.org/a/37390" target="_blank"><img src="https://asciinema.org/a/37390.png" width="400" /></a>
|
<a href="https://asciinema.org/a/37390" target="_blank"><img src="https://asciinema.org/a/37390.png" width="400" /></a>
|
||||||
@@ -11,38 +13,7 @@ It suggests commands as you type, based on command history.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Manual
|
See [INSTALL.md](INSTALL.md).
|
||||||
|
|
||||||
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git clone git://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Add the following to your `.zshrc`:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
|
|
||||||
```
|
|
||||||
|
|
||||||
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/zsh-users/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.
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
machine:
|
machine:
|
||||||
environment:
|
environment:
|
||||||
ZSH_VERSIONS: 5.0.8 5.1.1 5.2 5.3.1
|
ZSH_VERSIONS: zsh-dev/4.3.11 zsh/5.0.2 zsh/5.0.8 zsh/5.1.1 zsh/5.2 zsh/5.3.1 zsh/5.4.2 zsh/5.5.1
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
pre:
|
pre:
|
||||||
- for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do wget https://sourceforge.net/projects/zsh/files/zsh/$v/zsh-$v.tar.gz && tar xzf zsh-$v.tar.gz && cd zsh-$v && ./configure && sudo make install || exit 1; done
|
- for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do wget https://sourceforge.net/projects/zsh/files/$v/zsh-${v#*/}.tar.gz && tar xzf zsh-${v#*/}.tar.gz && pushd zsh-${v#*/} && ./configure && sudo make install && popd || exit 1; done
|
||||||
|
|
||||||
test:
|
test:
|
||||||
override:
|
override:
|
||||||
- for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do TEST_ZSH_BIN=/usr/local/bin/zsh-$v make test || exit 1; done:
|
- for v in $(echo $ZSH_VERSIONS | awk "{ for (i=$((1+CIRCLE_NODE_INDEX));i<=NF;i+=$CIRCLE_NODE_TOTAL) print \$i }"); do TEST_ZSH_BIN=/usr/local/bin/zsh-${v#*/} make test || exit 1; done:
|
||||||
parallel: true
|
parallel: true
|
||||||
|
|||||||
41
spec/async_spec.rb
Normal file
41
spec/async_spec.rb
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
context 'with asynchronous suggestions enabled' do
|
||||||
|
let(:options) { ["ZSH_AUTOSUGGEST_USE_ASYNC="] }
|
||||||
|
|
||||||
|
describe '`up-line-or-beginning-search`' do
|
||||||
|
let(:before_sourcing) do
|
||||||
|
-> do
|
||||||
|
session.
|
||||||
|
run_command('autoload -U up-line-or-beginning-search').
|
||||||
|
run_command('zle -N up-line-or-beginning-search').
|
||||||
|
send_string('bindkey "').
|
||||||
|
send_keys('C-v').send_keys('up').
|
||||||
|
send_string('" up-line-or-beginning-search').
|
||||||
|
send_keys('enter')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should show previous history entries' do
|
||||||
|
with_history(
|
||||||
|
'echo foo',
|
||||||
|
'echo bar',
|
||||||
|
'echo baz'
|
||||||
|
) do
|
||||||
|
session.clear_screen
|
||||||
|
3.times { session.send_keys('up') }
|
||||||
|
wait_for { session.content }.to eq("echo foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'exiting a subshell' do
|
||||||
|
it 'should not cause error messages to be printed' do
|
||||||
|
session.run_command('$(exit)')
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
expect(session.content).to eq('$(exit)')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -23,14 +23,5 @@ describe 'pasting using bracketed-paste-magic' do
|
|||||||
expect(session.content).to eq("echo #{'a' * 60}")
|
expect(session.content).to eq("echo #{'a' * 60}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows a suggestion after a non-modifying keystroke' do
|
|
||||||
with_history('echo hello') do
|
|
||||||
session.paste_string('echo')
|
|
||||||
sleep 1
|
|
||||||
session.send_keys('left')
|
|
||||||
wait_for { session.content }.to eq('echo hello')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
13
spec/integrations/rebound_bracket_spec.rb
Normal file
13
spec/integrations/rebound_bracket_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
describe 'rebinding [' do
|
||||||
|
context 'initialized before sourcing the plugin' do
|
||||||
|
before do
|
||||||
|
session.run_command("function [ { $commands[\\[] \"$@\" }")
|
||||||
|
session.clear_screen
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'executes the custom behavior and the built-in behavior' do
|
||||||
|
session.send_string('asdf')
|
||||||
|
wait_for { session.content }.to eq('asdf')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
67
spec/integrations/vi_mode_spec.rb
Normal file
67
spec/integrations/vi_mode_spec.rb
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
describe 'when using vi mode' do
|
||||||
|
let(:before_sourcing) do
|
||||||
|
-> do
|
||||||
|
session.run_command('bindkey -v')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'moving the cursor after exiting insert mode' do
|
||||||
|
it 'should not clear the current suggestion' do
|
||||||
|
with_history('foobar foo') do
|
||||||
|
session.
|
||||||
|
send_string('foo').
|
||||||
|
send_keys('escape').
|
||||||
|
send_keys('h')
|
||||||
|
|
||||||
|
wait_for { session.content }.to eq('foobar foo')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '`vi-forward-word-end`' do
|
||||||
|
it 'should accept through the end of the current word' do
|
||||||
|
with_history('foobar foo') do
|
||||||
|
session.
|
||||||
|
send_string('foo').
|
||||||
|
send_keys('escape').
|
||||||
|
send_keys('e'). # vi-forward-word-end
|
||||||
|
send_keys('a'). # vi-add-next
|
||||||
|
send_string('baz')
|
||||||
|
|
||||||
|
wait_for { session.content }.to eq('foobarbaz')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '`vi-forward-word`' do
|
||||||
|
it 'should accept through the first character of the next word' do
|
||||||
|
with_history('foobar foo') do
|
||||||
|
session.
|
||||||
|
send_string('foo').
|
||||||
|
send_keys('escape').
|
||||||
|
send_keys('w'). # vi-forward-word
|
||||||
|
send_keys('a'). # vi-add-next
|
||||||
|
send_string('az')
|
||||||
|
|
||||||
|
wait_for { session.content }.to eq('foobar faz')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '`vi-find-next-char`' do
|
||||||
|
it 'should accept through the next occurrence of the character' do
|
||||||
|
with_history('foobar foo') do
|
||||||
|
session.
|
||||||
|
send_string('foo').
|
||||||
|
send_keys('escape').
|
||||||
|
send_keys('f'). # vi-find-next-char
|
||||||
|
send_keys('o').
|
||||||
|
send_keys('a'). # vi-add-next
|
||||||
|
send_string('b')
|
||||||
|
|
||||||
|
wait_for { session.content }.to eq('foobar fob')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
23
spec/kill_ring_spec.rb
Normal file
23
spec/kill_ring_spec.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
context 'with some items in the kill ring' do
|
||||||
|
before do
|
||||||
|
session.
|
||||||
|
send_string('echo foo').
|
||||||
|
send_keys('C-u').
|
||||||
|
send_string('echo bar').
|
||||||
|
send_keys('C-u')
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '`yank-pop`' do
|
||||||
|
it 'should cycle through all items in the kill ring' do
|
||||||
|
session.send_keys('C-y')
|
||||||
|
wait_for { session.content }.to eq('echo bar')
|
||||||
|
|
||||||
|
session.send_keys('escape').send_keys('y')
|
||||||
|
wait_for { session.content }.to eq('echo foo')
|
||||||
|
|
||||||
|
session.send_keys('escape').send_keys('y')
|
||||||
|
wait_for { session.content }.to eq('echo bar')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
describe 'a special character in the buffer' do
|
|
||||||
it 'should be treated like any other character' do
|
|
||||||
with_history('echo "hello*"', 'echo "hello."') do
|
|
||||||
session.send_string('echo "hello*')
|
|
||||||
wait_for { session.content }.to eq('echo "hello*"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "hello?"', 'echo "hello."') do
|
|
||||||
session.send_string('echo "hello?')
|
|
||||||
wait_for { session.content }.to eq('echo "hello?"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "hello\nworld"') do
|
|
||||||
session.send_string('echo "hello\\')
|
|
||||||
wait_for { session.content }.to eq('echo "hello\nworld"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "\\\\"') do
|
|
||||||
session.send_string('echo "\\\\')
|
|
||||||
wait_for { session.content }.to eq('echo "\\\\"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo ~/foo') do
|
|
||||||
session.send_string('echo ~')
|
|
||||||
wait_for { session.content }.to eq('echo ~/foo')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "$(ls foo)"') do
|
|
||||||
session.send_string('echo "$(')
|
|
||||||
wait_for { session.content }.to eq('echo "$(ls foo)"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "$history[123]"') do
|
|
||||||
session.send_string('echo "$history[')
|
|
||||||
wait_for { session.content }.to eq('echo "$history[123]"')
|
|
||||||
session.send_string('123]')
|
|
||||||
wait_for { session.content }.to eq('echo "$history[123]"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "#yolo"') do
|
|
||||||
session.send_string('echo "#')
|
|
||||||
wait_for { session.content }.to eq('echo "#yolo"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "#foo"', 'echo $#abc') do
|
|
||||||
session.send_string('echo "#')
|
|
||||||
wait_for { session.content }.to eq('echo "#foo"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('echo "^A"', 'echo "^B"') do
|
|
||||||
session.send_string('echo "^A')
|
|
||||||
wait_for { session.content }.to eq('echo "^A"')
|
|
||||||
end
|
|
||||||
|
|
||||||
with_history('-foo() {}') do
|
|
||||||
session.send_string('-')
|
|
||||||
wait_for { session.content }.to eq('-foo() {}')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
require 'strategies/special_characters_helper'
|
||||||
|
|
||||||
describe 'the default suggestion strategy' do
|
describe 'the default suggestion strategy' do
|
||||||
it 'suggests the last matching history entry' do
|
it 'suggests the last matching history entry' do
|
||||||
with_history('ls foo', 'ls bar', 'echo baz') do
|
with_history('ls foo', 'ls bar', 'echo baz') do
|
||||||
@@ -5,4 +7,6 @@ describe 'the default suggestion strategy' do
|
|||||||
wait_for { session.content }.to eq('ls bar')
|
wait_for { session.content }.to eq('ls bar')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include_examples 'special characters'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
require 'strategies/special_characters_helper'
|
||||||
|
|
||||||
describe 'the match_prev_cmd strategy' do
|
describe 'the match_prev_cmd strategy' do
|
||||||
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=match_prev_cmd'] }
|
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=match_prev_cmd'] }
|
||||||
|
|
||||||
@@ -14,4 +16,6 @@ describe 'the match_prev_cmd strategy' do
|
|||||||
wait_for { session.content }.to eq('ls bar')
|
wait_for { session.content }.to eq('ls bar')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include_examples 'special characters'
|
||||||
end
|
end
|
||||||
|
|||||||
62
spec/strategies/special_characters_helper.rb
Normal file
62
spec/strategies/special_characters_helper.rb
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
shared_examples 'special characters' do
|
||||||
|
describe 'a special character in the buffer' do
|
||||||
|
it 'should be treated like any other character' do
|
||||||
|
with_history('echo "hello*"', 'echo "hello."') do
|
||||||
|
session.send_string('echo "hello*')
|
||||||
|
wait_for { session.content }.to eq('echo "hello*"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "hello?"', 'echo "hello."') do
|
||||||
|
session.send_string('echo "hello?')
|
||||||
|
wait_for { session.content }.to eq('echo "hello?"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "hello\nworld"') do
|
||||||
|
session.send_string('echo "hello\\')
|
||||||
|
wait_for { session.content }.to eq('echo "hello\nworld"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "\\\\"') do
|
||||||
|
session.send_string('echo "\\\\')
|
||||||
|
wait_for { session.content }.to eq('echo "\\\\"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo ~/foo') do
|
||||||
|
session.send_string('echo ~')
|
||||||
|
wait_for { session.content }.to eq('echo ~/foo')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "$(ls foo)"') do
|
||||||
|
session.send_string('echo "$(')
|
||||||
|
wait_for { session.content }.to eq('echo "$(ls foo)"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "$history[123]"') do
|
||||||
|
session.send_string('echo "$history[')
|
||||||
|
wait_for { session.content }.to eq('echo "$history[123]"')
|
||||||
|
session.send_string('123]')
|
||||||
|
wait_for { session.content }.to eq('echo "$history[123]"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "#yolo"') do
|
||||||
|
session.send_string('echo "#')
|
||||||
|
wait_for { session.content }.to eq('echo "#yolo"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "#foo"', 'echo $#abc') do
|
||||||
|
session.send_string('echo "#')
|
||||||
|
wait_for { session.content }.to eq('echo "#foo"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('echo "^A"', 'echo "^B"') do
|
||||||
|
session.send_string('echo "^A')
|
||||||
|
wait_for { session.content }.to eq('echo "^A"')
|
||||||
|
end
|
||||||
|
|
||||||
|
with_history('-foo() {}') do
|
||||||
|
session.send_string('-')
|
||||||
|
wait_for { session.content }.to eq('-foo() {}')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -77,6 +77,10 @@ class TerminalSession
|
|||||||
map(&:to_i)
|
map(&:to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attach!
|
||||||
|
tmux_command('attach-session')
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :opts
|
attr_reader :opts
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ _zsh_autosuggest_async_server() {
|
|||||||
# Silence any error messages
|
# Silence any error messages
|
||||||
exec 2>/dev/null
|
exec 2>/dev/null
|
||||||
|
|
||||||
local strategy=$1
|
|
||||||
local last_pid
|
local last_pid
|
||||||
|
|
||||||
while IFS='' read -r -d $'\0' query; do
|
while IFS='' read -r -d $'\0' query; do
|
||||||
@@ -63,14 +62,14 @@ _zsh_autosuggest_async_pty_create() {
|
|||||||
typeset -h REPLY
|
typeset -h REPLY
|
||||||
|
|
||||||
# If we won't get a fd back from zpty, try to guess it
|
# If we won't get a fd back from zpty, try to guess it
|
||||||
if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then
|
if (( ! $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD )); then
|
||||||
integer -l zptyfd
|
integer -l zptyfd
|
||||||
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
||||||
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fork a zpty process running the server function
|
# Fork a zpty process running the server function
|
||||||
zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "_zsh_autosuggest_async_server _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
|
zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME _zsh_autosuggest_async_server
|
||||||
|
|
||||||
# Store the fd so we can remove the handler later
|
# Store the fd so we can remove the handler later
|
||||||
if (( REPLY )); then
|
if (( REPLY )); then
|
||||||
@@ -84,13 +83,11 @@ _zsh_autosuggest_async_pty_create() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_async_pty_destroy() {
|
_zsh_autosuggest_async_pty_destroy() {
|
||||||
if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then
|
|
||||||
# Remove the input handler
|
# Remove the input handler
|
||||||
zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null
|
zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null
|
||||||
|
|
||||||
# Destroy the zpty
|
# Destroy the zpty
|
||||||
zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null
|
zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_async_pty_recreate() {
|
_zsh_autosuggest_async_pty_recreate() {
|
||||||
|
|||||||
18
src/bind.zsh
18
src/bind.zsh
@@ -10,14 +10,14 @@ _zsh_autosuggest_incr_bind_count() {
|
|||||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1
|
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_get_bind_count() {
|
_zsh_autosuggest_get_bind_count() {
|
||||||
if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
|
if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
|
||||||
bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
||||||
else
|
else
|
||||||
bind_count=0
|
typeset -gi bind_count=0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,13 +88,13 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
|
|
||||||
# Find every widget we might want to bind and bind it appropriately
|
# Find every widget we might want to bind and bind it appropriately
|
||||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
||||||
if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget clear
|
_zsh_autosuggest_bind_widget $widget clear
|
||||||
elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget accept
|
_zsh_autosuggest_bind_widget $widget accept
|
||||||
elif [ ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget execute
|
_zsh_autosuggest_bind_widget $widget execute
|
||||||
elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||||
else
|
else
|
||||||
# Assume any unspecified widget might modify the buffer
|
# Assume any unspecified widget might modify the buffer
|
||||||
@@ -106,13 +106,13 @@ _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
|
# Do nothing unless called with at least one arg
|
||||||
[ $# -gt 0 ] || return
|
(( $# )) || return 0
|
||||||
|
|
||||||
local original_widget_name="$1"
|
local original_widget_name="$1"
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ $widgets[$original_widget_name] ]; then
|
if (( ${+widgets[$original_widget_name]} )); then
|
||||||
zle $original_widget_name -- $@
|
zle $original_widget_name -- $@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
|||||||
history-beginning-search-backward
|
history-beginning-search-backward
|
||||||
history-substring-search-up
|
history-substring-search-up
|
||||||
history-substring-search-down
|
history-substring-search-down
|
||||||
|
up-line-or-beginning-search
|
||||||
|
down-line-or-beginning-search
|
||||||
up-line-or-history
|
up-line-or-history
|
||||||
down-line-or-history
|
down-line-or-history
|
||||||
accept-line
|
accept-line
|
||||||
@@ -42,10 +44,13 @@ ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
|||||||
# Widgets that accept the suggestion as far as the cursor moves
|
# Widgets that accept the suggestion as far as the cursor moves
|
||||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||||
forward-word
|
forward-word
|
||||||
|
emacs-forward-word
|
||||||
vi-forward-word
|
vi-forward-word
|
||||||
vi-forward-word-end
|
vi-forward-word-end
|
||||||
vi-forward-blank-word
|
vi-forward-blank-word
|
||||||
vi-forward-blank-word-end
|
vi-forward-blank-word-end
|
||||||
|
vi-find-next-char
|
||||||
|
vi-find-next-char-skip
|
||||||
)
|
)
|
||||||
|
|
||||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
# Widgets that should be ignored (globbing supported but must be escaped)
|
||||||
@@ -56,6 +61,7 @@ ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
|||||||
set-local-history
|
set-local-history
|
||||||
which-command
|
which-command
|
||||||
yank
|
yank
|
||||||
|
yank-pop
|
||||||
)
|
)
|
||||||
|
|
||||||
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
|
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
_zsh_autosuggest_highlight_reset() {
|
_zsh_autosuggest_highlight_reset() {
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
|
|
||||||
if [ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]; then
|
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
||||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
fi
|
fi
|
||||||
@@ -17,8 +17,8 @@ _zsh_autosuggest_highlight_reset() {
|
|||||||
_zsh_autosuggest_highlight_apply() {
|
_zsh_autosuggest_highlight_apply() {
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
|
|
||||||
if [ $#POSTDISPLAY -gt 0 ]; then
|
if (( $#POSTDISPLAY )); then
|
||||||
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
typeset -g _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
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ _zsh_autosuggest_start() {
|
|||||||
# to the widget list variables to take effect on the next precmd.
|
# to the widget list variables to take effect on the next precmd.
|
||||||
add-zsh-hook precmd _zsh_autosuggest_bind_widgets
|
add-zsh-hook precmd _zsh_autosuggest_bind_widgets
|
||||||
|
|
||||||
if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then
|
if [[ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]]; then
|
||||||
_zsh_autosuggest_async_start
|
_zsh_autosuggest_async_start
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ _zsh_autosuggest_strategy_default() {
|
|||||||
# Escape backslashes and all of the glob operators so we can use
|
# Escape backslashes and all of the glob operators so we can use
|
||||||
# this string as a pattern to search the $history associative array.
|
# this string as a pattern to search the $history associative array.
|
||||||
# - (#m) globbing flag enables setting references for match data
|
# - (#m) globbing flag enables setting references for match data
|
||||||
|
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||||
|
|
||||||
# Get the history items that match
|
# Get the history items that match
|
||||||
# - (r) subscript flag makes the pattern match on values
|
# - (r) subscript flag makes the pattern match on values
|
||||||
suggestion="${history[(r)$prefix*]}"
|
typeset -g suggestion="${history[(r)${prefix}*]}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,14 @@
|
|||||||
# `HIST_EXPIRE_DUPS_FIRST`.
|
# `HIST_EXPIRE_DUPS_FIRST`.
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_match_prev_cmd() {
|
_zsh_autosuggest_strategy_match_prev_cmd() {
|
||||||
local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}"
|
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||||
|
emulate -L zsh
|
||||||
|
|
||||||
|
# Enable globbing flags so that we can use (#m)
|
||||||
|
setopt EXTENDED_GLOB
|
||||||
|
|
||||||
|
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||||
|
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||||
|
|
||||||
# Get all history event numbers that correspond to history
|
# Get all history event numbers that correspond to history
|
||||||
# entries that match pattern $prefix*
|
# entries that match pattern $prefix*
|
||||||
@@ -48,5 +55,5 @@ _zsh_autosuggest_strategy_match_prev_cmd() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Give back the matched history entry
|
# Give back the matched history entry
|
||||||
suggestion="$history[$histkey]"
|
typeset -g suggestion="$history[$histkey]"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ _zsh_autosuggest_disable() {
|
|||||||
_zsh_autosuggest_enable() {
|
_zsh_autosuggest_enable() {
|
||||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
unset _ZSH_AUTOSUGGEST_DISABLED
|
||||||
|
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if (( $#BUFFER )); then
|
||||||
_zsh_autosuggest_fetch
|
_zsh_autosuggest_fetch
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
# Toggle suggestions (enable/disable)
|
||||||
_zsh_autosuggest_toggle() {
|
_zsh_autosuggest_toggle() {
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
_zsh_autosuggest_enable
|
_zsh_autosuggest_enable
|
||||||
else
|
else
|
||||||
_zsh_autosuggest_disable
|
_zsh_autosuggest_disable
|
||||||
@@ -39,7 +39,7 @@ _zsh_autosuggest_clear() {
|
|||||||
_zsh_autosuggest_modify() {
|
_zsh_autosuggest_modify() {
|
||||||
local -i retval
|
local -i retval
|
||||||
|
|
||||||
# Only added to zsh very recently
|
# Only available in zsh >= 5.4
|
||||||
local -i KEYS_QUEUED_COUNT
|
local -i KEYS_QUEUED_COUNT
|
||||||
|
|
||||||
# Save the contents of the buffer/postdisplay
|
# Save the contents of the buffer/postdisplay
|
||||||
@@ -54,35 +54,36 @@ _zsh_autosuggest_modify() {
|
|||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||||
if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then
|
if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then
|
||||||
|
POSTDISPLAY="$orig_postdisplay"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Optimize if manually typing in the suggestion
|
# Optimize if manually typing in the suggestion
|
||||||
if [ $#BUFFER -gt $#orig_buffer ]; then
|
if (( $#BUFFER > $#orig_buffer )); then
|
||||||
local added=${BUFFER#$orig_buffer}
|
local added=${BUFFER#$orig_buffer}
|
||||||
|
|
||||||
# If the string added matches the beginning of the postdisplay
|
# If the string added matches the beginning of the postdisplay
|
||||||
if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then
|
if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then
|
||||||
POSTDISPLAY="${orig_postdisplay:$#added}"
|
POSTDISPLAY="${orig_postdisplay:$#added}"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don't fetch a new suggestion if the buffer hasn't changed
|
# Don't fetch a new suggestion if the buffer hasn't changed
|
||||||
if [ "$BUFFER" = "$orig_buffer" ]; then
|
if [[ "$BUFFER" = "$orig_buffer" ]]; then
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
POSTDISPLAY="$orig_postdisplay"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
# Bail out if suggestions are disabled
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if (( $#BUFFER > 0 )); then
|
||||||
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
|
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
||||||
_zsh_autosuggest_fetch
|
_zsh_autosuggest_fetch
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -105,7 +106,7 @@ _zsh_autosuggest_fetch() {
|
|||||||
_zsh_autosuggest_suggest() {
|
_zsh_autosuggest_suggest() {
|
||||||
local suggestion="$1"
|
local suggestion="$1"
|
||||||
|
|
||||||
if [ -n "$suggestion" ] && [ $#BUFFER -gt 0 ]; then
|
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||||
else
|
else
|
||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
@@ -118,12 +119,12 @@ _zsh_autosuggest_accept() {
|
|||||||
|
|
||||||
# When vicmd keymap is active, the cursor can't move all the way
|
# When vicmd keymap is active, the cursor can't move all the way
|
||||||
# to the end of the buffer
|
# to the end of the buffer
|
||||||
if [ "$KEYMAP" = "vicmd" ]; then
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
max_cursor_pos=$((max_cursor_pos - 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
# Only accept if the cursor is at the end of the buffer
|
||||||
if [ $CURSOR -eq $max_cursor_pos ]; then
|
if [[ $CURSOR = $max_cursor_pos ]]; then
|
||||||
# Add the suggestion to the buffer
|
# Add the suggestion to the buffer
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ _zsh_autosuggest_execute() {
|
|||||||
|
|
||||||
# Partially accept the suggestion
|
# Partially accept the suggestion
|
||||||
_zsh_autosuggest_partial_accept() {
|
_zsh_autosuggest_partial_accept() {
|
||||||
local -i retval
|
local -i retval cursor_loc
|
||||||
|
|
||||||
# Save the contents of the buffer so we can restore later if needed
|
# Save the contents of the buffer so we can restore later if needed
|
||||||
local original_buffer="$BUFFER"
|
local original_buffer="$BUFFER"
|
||||||
@@ -164,13 +165,19 @@ _zsh_autosuggest_partial_accept() {
|
|||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
|
# Normalize cursor location across vi/emacs modes
|
||||||
|
cursor_loc=$CURSOR
|
||||||
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
|
cursor_loc=$((cursor_loc + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
# If we've moved past the end of the original buffer
|
# If we've moved past the end of the original buffer
|
||||||
if [ $CURSOR -gt $#original_buffer ]; then
|
if (( $cursor_loc > $#original_buffer )); then
|
||||||
# Set POSTDISPLAY to text right of the cursor
|
# Set POSTDISPLAY to text right of the cursor
|
||||||
POSTDISPLAY="$RBUFFER"
|
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
|
||||||
|
|
||||||
# Clip the buffer at the cursor
|
# Clip the buffer at the cursor
|
||||||
BUFFER="$LBUFFER"
|
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||||
else
|
else
|
||||||
# Restore the original buffer
|
# Restore the original buffer
|
||||||
BUFFER="$original_buffer"
|
BUFFER="$original_buffer"
|
||||||
|
|||||||
@@ -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.4.0
|
# v0.4.3
|
||||||
# Copyright (c) 2013 Thiago de Arruda
|
# Copyright (c) 2013 Thiago de Arruda
|
||||||
# Copyright (c) 2016-2017 Eric Freese
|
# Copyright (c) 2016-2018 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
|
||||||
@@ -57,6 +57,8 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
|||||||
history-beginning-search-backward
|
history-beginning-search-backward
|
||||||
history-substring-search-up
|
history-substring-search-up
|
||||||
history-substring-search-down
|
history-substring-search-down
|
||||||
|
up-line-or-beginning-search
|
||||||
|
down-line-or-beginning-search
|
||||||
up-line-or-history
|
up-line-or-history
|
||||||
down-line-or-history
|
down-line-or-history
|
||||||
accept-line
|
accept-line
|
||||||
@@ -78,10 +80,13 @@ ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
|||||||
# Widgets that accept the suggestion as far as the cursor moves
|
# Widgets that accept the suggestion as far as the cursor moves
|
||||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||||
forward-word
|
forward-word
|
||||||
|
emacs-forward-word
|
||||||
vi-forward-word
|
vi-forward-word
|
||||||
vi-forward-word-end
|
vi-forward-word-end
|
||||||
vi-forward-blank-word
|
vi-forward-blank-word
|
||||||
vi-forward-blank-word-end
|
vi-forward-blank-word-end
|
||||||
|
vi-find-next-char
|
||||||
|
vi-find-next-char-skip
|
||||||
)
|
)
|
||||||
|
|
||||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
# Widgets that should be ignored (globbing supported but must be escaped)
|
||||||
@@ -92,6 +97,7 @@ ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
|||||||
set-local-history
|
set-local-history
|
||||||
which-command
|
which-command
|
||||||
yank
|
yank
|
||||||
|
yank-pop
|
||||||
)
|
)
|
||||||
|
|
||||||
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
|
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
|
||||||
@@ -141,14 +147,14 @@ _zsh_autosuggest_incr_bind_count() {
|
|||||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1
|
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_get_bind_count() {
|
_zsh_autosuggest_get_bind_count() {
|
||||||
if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
|
if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
|
||||||
bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
||||||
else
|
else
|
||||||
bind_count=0
|
typeset -gi bind_count=0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,13 +225,13 @@ _zsh_autosuggest_bind_widgets() {
|
|||||||
|
|
||||||
# Find every widget we might want to bind and bind it appropriately
|
# Find every widget we might want to bind and bind it appropriately
|
||||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
||||||
if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget clear
|
_zsh_autosuggest_bind_widget $widget clear
|
||||||
elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget accept
|
_zsh_autosuggest_bind_widget $widget accept
|
||||||
elif [ ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget execute
|
_zsh_autosuggest_bind_widget $widget execute
|
||||||
elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||||
else
|
else
|
||||||
# Assume any unspecified widget might modify the buffer
|
# Assume any unspecified widget might modify the buffer
|
||||||
@@ -237,13 +243,13 @@ _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
|
# Do nothing unless called with at least one arg
|
||||||
[ $# -gt 0 ] || return
|
(( $# )) || return 0
|
||||||
|
|
||||||
local original_widget_name="$1"
|
local original_widget_name="$1"
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ $widgets[$original_widget_name] ]; then
|
if (( ${+widgets[$original_widget_name]} )); then
|
||||||
zle $original_widget_name -- $@
|
zle $original_widget_name -- $@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -256,7 +262,7 @@ _zsh_autosuggest_invoke_original_widget() {
|
|||||||
_zsh_autosuggest_highlight_reset() {
|
_zsh_autosuggest_highlight_reset() {
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
|
|
||||||
if [ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]; then
|
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
||||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
fi
|
fi
|
||||||
@@ -266,8 +272,8 @@ _zsh_autosuggest_highlight_reset() {
|
|||||||
_zsh_autosuggest_highlight_apply() {
|
_zsh_autosuggest_highlight_apply() {
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||||
|
|
||||||
if [ $#POSTDISPLAY -gt 0 ]; then
|
if (( $#POSTDISPLAY )); then
|
||||||
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
typeset -g _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
|
||||||
@@ -288,14 +294,14 @@ _zsh_autosuggest_disable() {
|
|||||||
_zsh_autosuggest_enable() {
|
_zsh_autosuggest_enable() {
|
||||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
unset _ZSH_AUTOSUGGEST_DISABLED
|
||||||
|
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if (( $#BUFFER )); then
|
||||||
_zsh_autosuggest_fetch
|
_zsh_autosuggest_fetch
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
# Toggle suggestions (enable/disable)
|
||||||
_zsh_autosuggest_toggle() {
|
_zsh_autosuggest_toggle() {
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
_zsh_autosuggest_enable
|
_zsh_autosuggest_enable
|
||||||
else
|
else
|
||||||
_zsh_autosuggest_disable
|
_zsh_autosuggest_disable
|
||||||
@@ -314,7 +320,7 @@ _zsh_autosuggest_clear() {
|
|||||||
_zsh_autosuggest_modify() {
|
_zsh_autosuggest_modify() {
|
||||||
local -i retval
|
local -i retval
|
||||||
|
|
||||||
# Only added to zsh very recently
|
# Only available in zsh >= 5.4
|
||||||
local -i KEYS_QUEUED_COUNT
|
local -i KEYS_QUEUED_COUNT
|
||||||
|
|
||||||
# Save the contents of the buffer/postdisplay
|
# Save the contents of the buffer/postdisplay
|
||||||
@@ -329,35 +335,36 @@ _zsh_autosuggest_modify() {
|
|||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||||
if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then
|
if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then
|
||||||
|
POSTDISPLAY="$orig_postdisplay"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Optimize if manually typing in the suggestion
|
# Optimize if manually typing in the suggestion
|
||||||
if [ $#BUFFER -gt $#orig_buffer ]; then
|
if (( $#BUFFER > $#orig_buffer )); then
|
||||||
local added=${BUFFER#$orig_buffer}
|
local added=${BUFFER#$orig_buffer}
|
||||||
|
|
||||||
# If the string added matches the beginning of the postdisplay
|
# If the string added matches the beginning of the postdisplay
|
||||||
if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then
|
if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then
|
||||||
POSTDISPLAY="${orig_postdisplay:$#added}"
|
POSTDISPLAY="${orig_postdisplay:$#added}"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don't fetch a new suggestion if the buffer hasn't changed
|
# Don't fetch a new suggestion if the buffer hasn't changed
|
||||||
if [ "$BUFFER" = "$orig_buffer" ]; then
|
if [[ "$BUFFER" = "$orig_buffer" ]]; then
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
POSTDISPLAY="$orig_postdisplay"
|
||||||
return $retval
|
return $retval
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
# Bail out if suggestions are disabled
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
# Get a new suggestion if the buffer is not empty after modification
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
if (( $#BUFFER > 0 )); then
|
||||||
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
|
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
||||||
_zsh_autosuggest_fetch
|
_zsh_autosuggest_fetch
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -380,7 +387,7 @@ _zsh_autosuggest_fetch() {
|
|||||||
_zsh_autosuggest_suggest() {
|
_zsh_autosuggest_suggest() {
|
||||||
local suggestion="$1"
|
local suggestion="$1"
|
||||||
|
|
||||||
if [ -n "$suggestion" ] && [ $#BUFFER -gt 0 ]; then
|
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||||
else
|
else
|
||||||
unset POSTDISPLAY
|
unset POSTDISPLAY
|
||||||
@@ -393,12 +400,12 @@ _zsh_autosuggest_accept() {
|
|||||||
|
|
||||||
# When vicmd keymap is active, the cursor can't move all the way
|
# When vicmd keymap is active, the cursor can't move all the way
|
||||||
# to the end of the buffer
|
# to the end of the buffer
|
||||||
if [ "$KEYMAP" = "vicmd" ]; then
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
max_cursor_pos=$((max_cursor_pos - 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
# Only accept if the cursor is at the end of the buffer
|
||||||
if [ $CURSOR -eq $max_cursor_pos ]; then
|
if [[ $CURSOR = $max_cursor_pos ]]; then
|
||||||
# Add the suggestion to the buffer
|
# Add the suggestion to the buffer
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
BUFFER="$BUFFER$POSTDISPLAY"
|
||||||
|
|
||||||
@@ -427,7 +434,7 @@ _zsh_autosuggest_execute() {
|
|||||||
|
|
||||||
# Partially accept the suggestion
|
# Partially accept the suggestion
|
||||||
_zsh_autosuggest_partial_accept() {
|
_zsh_autosuggest_partial_accept() {
|
||||||
local -i retval
|
local -i retval cursor_loc
|
||||||
|
|
||||||
# Save the contents of the buffer so we can restore later if needed
|
# Save the contents of the buffer so we can restore later if needed
|
||||||
local original_buffer="$BUFFER"
|
local original_buffer="$BUFFER"
|
||||||
@@ -439,13 +446,19 @@ _zsh_autosuggest_partial_accept() {
|
|||||||
_zsh_autosuggest_invoke_original_widget $@
|
_zsh_autosuggest_invoke_original_widget $@
|
||||||
retval=$?
|
retval=$?
|
||||||
|
|
||||||
|
# Normalize cursor location across vi/emacs modes
|
||||||
|
cursor_loc=$CURSOR
|
||||||
|
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||||
|
cursor_loc=$((cursor_loc + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
# If we've moved past the end of the original buffer
|
# If we've moved past the end of the original buffer
|
||||||
if [ $CURSOR -gt $#original_buffer ]; then
|
if (( $cursor_loc > $#original_buffer )); then
|
||||||
# Set POSTDISPLAY to text right of the cursor
|
# Set POSTDISPLAY to text right of the cursor
|
||||||
POSTDISPLAY="$RBUFFER"
|
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
|
||||||
|
|
||||||
# Clip the buffer at the cursor
|
# Clip the buffer at the cursor
|
||||||
BUFFER="$LBUFFER"
|
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||||
else
|
else
|
||||||
# Restore the original buffer
|
# Restore the original buffer
|
||||||
BUFFER="$original_buffer"
|
BUFFER="$original_buffer"
|
||||||
@@ -497,12 +510,12 @@ _zsh_autosuggest_strategy_default() {
|
|||||||
# Escape backslashes and all of the glob operators so we can use
|
# Escape backslashes and all of the glob operators so we can use
|
||||||
# this string as a pattern to search the $history associative array.
|
# this string as a pattern to search the $history associative array.
|
||||||
# - (#m) globbing flag enables setting references for match data
|
# - (#m) globbing flag enables setting references for match data
|
||||||
|
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||||
|
|
||||||
# Get the history items that match
|
# Get the history items that match
|
||||||
# - (r) subscript flag makes the pattern match on values
|
# - (r) subscript flag makes the pattern match on values
|
||||||
suggestion="${history[(r)$prefix*]}"
|
typeset -g suggestion="${history[(r)${prefix}*]}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
@@ -527,7 +540,14 @@ _zsh_autosuggest_strategy_default() {
|
|||||||
# `HIST_EXPIRE_DUPS_FIRST`.
|
# `HIST_EXPIRE_DUPS_FIRST`.
|
||||||
|
|
||||||
_zsh_autosuggest_strategy_match_prev_cmd() {
|
_zsh_autosuggest_strategy_match_prev_cmd() {
|
||||||
local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}"
|
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||||
|
emulate -L zsh
|
||||||
|
|
||||||
|
# Enable globbing flags so that we can use (#m)
|
||||||
|
setopt EXTENDED_GLOB
|
||||||
|
|
||||||
|
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||||
|
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||||
|
|
||||||
# Get all history event numbers that correspond to history
|
# Get all history event numbers that correspond to history
|
||||||
# entries that match pattern $prefix*
|
# entries that match pattern $prefix*
|
||||||
@@ -554,7 +574,7 @@ _zsh_autosuggest_strategy_match_prev_cmd() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Give back the matched history entry
|
# Give back the matched history entry
|
||||||
suggestion="$history[$histkey]"
|
typeset -g suggestion="$history[$histkey]"
|
||||||
}
|
}
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
#--------------------------------------------------------------------#
|
||||||
@@ -581,7 +601,6 @@ _zsh_autosuggest_async_server() {
|
|||||||
# Silence any error messages
|
# Silence any error messages
|
||||||
exec 2>/dev/null
|
exec 2>/dev/null
|
||||||
|
|
||||||
local strategy=$1
|
|
||||||
local last_pid
|
local last_pid
|
||||||
|
|
||||||
while IFS='' read -r -d $'\0' query; do
|
while IFS='' read -r -d $'\0' query; do
|
||||||
@@ -621,14 +640,14 @@ _zsh_autosuggest_async_pty_create() {
|
|||||||
typeset -h REPLY
|
typeset -h REPLY
|
||||||
|
|
||||||
# If we won't get a fd back from zpty, try to guess it
|
# If we won't get a fd back from zpty, try to guess it
|
||||||
if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then
|
if (( ! $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD )); then
|
||||||
integer -l zptyfd
|
integer -l zptyfd
|
||||||
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
||||||
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fork a zpty process running the server function
|
# Fork a zpty process running the server function
|
||||||
zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "_zsh_autosuggest_async_server _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
|
zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME _zsh_autosuggest_async_server
|
||||||
|
|
||||||
# Store the fd so we can remove the handler later
|
# Store the fd so we can remove the handler later
|
||||||
if (( REPLY )); then
|
if (( REPLY )); then
|
||||||
@@ -642,13 +661,11 @@ _zsh_autosuggest_async_pty_create() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_async_pty_destroy() {
|
_zsh_autosuggest_async_pty_destroy() {
|
||||||
if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then
|
|
||||||
# Remove the input handler
|
# Remove the input handler
|
||||||
zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null
|
zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null
|
||||||
|
|
||||||
# Destroy the zpty
|
# Destroy the zpty
|
||||||
zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null
|
zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_zsh_autosuggest_async_pty_recreate() {
|
_zsh_autosuggest_async_pty_recreate() {
|
||||||
@@ -682,7 +699,7 @@ _zsh_autosuggest_start() {
|
|||||||
# to the widget list variables to take effect on the next precmd.
|
# to the widget list variables to take effect on the next precmd.
|
||||||
add-zsh-hook precmd _zsh_autosuggest_bind_widgets
|
add-zsh-hook precmd _zsh_autosuggest_bind_widgets
|
||||||
|
|
||||||
if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then
|
if [[ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]]; then
|
||||||
_zsh_autosuggest_async_start
|
_zsh_autosuggest_async_start
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user