Commit graph

35 commits

Author SHA1 Message Date
Eric Freese
19e375bbc8 cleanup: Consolidate autoloads 2020-01-26 21:15:47 -07:00
Eric Freese
cf445d08b0
Merge pull request #487 from zsh-users/features/completion-ignore
Allow skipping completion suggestions when buffer matches a pattern
2020-01-04 16:52:35 -07:00
Eric Freese
7afb7364f1 Allow skipping completion suggestions when buffer matches a pattern
Set ZSH_AUTOSUGGEST_COMPLETION_IGNORE to a glob pattern to have the
completion suggestion strategy never make suggestions when the buffer
matches the pattern.

This can be helpful when some completion routines you have are
particularly expensive and you want to prevent them from running
automatically on every keystroke.

See GitHub issue #463.
2019-12-15 08:13:54 -07:00
Eric Freese
0f0f221180 cleanup: Split on null bytes instead of pattern matching
Follow-up to technique tried in commit d94475c after I learned about the
`@` flag to keep empty strings in the array.
2019-09-30 12:12:52 -06:00
Eric Freese
b87a4972c8 Allow configuring to ignore history entries matching a pattern
Set ZSH_AUTOSUGGEST_HISTORY_IGNORE to a glob pattern to have the history
and match_prev_cmd suggestion strategies never make suggestions matching
that pattern.

For example, set to "cd *" to never suggest any `cd` commands from
history (see issues #340 and #425). Or set to "?(#c50,)" to never
suggest anything 50 characters or longer (see issue #429).
2019-07-02 21:46:17 -06:00
Eric Freese
adb02c44a2 Prefix custom _complete implementation with "function" keyword
For some reason, when `_complete` is aliased before sourcing the plugin,
zsh was blowing up with a parse error. Adding "function" keyword makes
it parse successfully.

See similar issue: https://github.com/robbyrussell/oh-my-zsh/issues/6723#issuecomment-381220834

Fixes GitHub #442
2019-06-17 22:04:31 -06:00
Eric Freese
f543ba08c3 Fix cr/lf handling in completion strategy 2019-06-15 21:17:58 -06:00
Eric Freese
d94475ca1b Simplify logic to extract suggestion from between null bytes
Just remove up to and including the first null byte and after and
including the last null byte.

I also looked into using `${${(0)line}[2]}`, but it fails when `$line`
starts with a null byte, since the first split string will be empty and
thus not included in the resulting array.
2019-06-15 21:17:58 -06:00
Eric Freese
c04e015d13 Add to explanation of extra stuff after zpty -r 2019-06-15 21:17:58 -06:00
Eric Freese
e9ce05c4c1 Ensure that kill succeeds even in older buggy versions of zsh
See https://unix.stackexchange.com/a/477647/156673
2019-06-15 21:17:58 -06:00
Eric Freese
fdf4502c5c We need to autoload is-at-least for it to be available
This error was hidden inside the zpty
2019-06-15 21:17:58 -06:00
Eric Freese
7e048c3f53 Fix error that was hidden in zpty
Without the quotes, this was blowing up with:
  _zsh_autosuggest_capture_postcompletion:unset:5: not enough arguments
2019-06-15 21:17:58 -06:00
Eric Freese
2b05f5ed2d Add a comment explaining post-completion hook 2019-06-15 21:17:58 -06:00
Eric Freese
c1910348c7 Implement completion suggestion strategy (#111)
Based on https://github.com/Valodim/zsh-capture-completion

`zpty -r` with a pattern seems to have some funky behavior on older
versions, giving unpredictable results

Don't use `-s` option to `zmodload`. It is not available in zsh versions
older than 5.3

If running in sync mode and a completion takes a long time, the user can
^C out of it. We need to use `always` in the strategy function or the
pty will not be destroyed in this case and the next time we go to create
it, it will fail, making the shell unusable.

User can have many different completion styles set that will modify what
they've already typed. These styles will result in suggestions that
don't match what the user has already typed. We try our best to unset
some of the more problematic ones, but add some code to fetch to
invalidate suggestions that don't match what the user's already typed.
2019-04-11 09:53:55 -06:00
Eric Freese
70f36c007d Finish renaming "default" strategy to "history" 2018-11-24 15:07:08 -07:00
Eric Freese
62f5f14f2f default => history 2018-11-24 09:56:00 -07:00
Eric Freese
4ea825faf8 Fix #247 and #248 without using (b) flag
To support older versions of zsh (< 5.0.8).

We were missing the EXTENDED_GLOB option that allows use of `(#m)` flag.
2017-12-06 08:09:14 -07:00
Eric Freese
a1babef972 Revert "Simplify escaping of pattern and fix match_prev_cmd strategy"
This reverts commit 7f8ff2867c.
2017-12-06 08:08:53 -07:00
Eric Freese
256293cbb6 Use typeset -g to avoid warnnestedvar warnings
Fixes github issue #271
2017-09-27 13:24:06 -06:00
Stefan Siegel
7f8ff2867c Simplify escaping of pattern and fix match_prev_cmd strategy
Maybe this is also a fix for #247, #248 and #258. Supersedes #267.

Testcase:
Using match_prev_cmd strategy and with these lines in history:
echo '1^'
echo '2^'
echo '1^'

type:
echo       (unexpected suggestion echo '1^' instead of echo '2^')
echo '1^1  (wrong suggestion echo '1^1echo '1^')
echo '1^#  (error "bad math expression")
2017-09-10 04:35:19 +02:00
Eric Freese
ed8056c5e8 Lots of async changes 2017-02-16 19:19:30 -07:00
Eric Freese
e3eb286ea2 Lots of little async cleanups 2017-01-27 15:18:26 -07:00
Eric Freese
50e6832b8c Escape the prefix passed into the match_prev_cmd strategy 2017-01-24 23:06:41 -07:00
Eric Freese
0305908adf Revert fc usage in calculating suggestion
As far as I know, `fc` makes it impossible to tell whether history items
used an actual newline character or the string "\n". Pulling from the
`$history` array gives a more accurate representation of the actual
command that was run.
2017-01-24 23:04:07 -07:00
Eric Freese
e33eb570c4 Send only the prefix to the suggestion server 2017-01-24 20:01:11 -07:00
Eric Freese
63816c5da8 Fix #164: Use fc builtin instead of $history array for lookup
According to a few tests, the `fc` builtin appears to be quite a bit
faster than searching through the `$history` associative array when
dealing with large history files (500K+).
2016-06-10 13:52:24 -06:00
Tassilo Horn
ca70612d3c Document caveats of match_prev_cmd strategy
This strategy relies on the history being exactly in the order in which
commands have been entered.  Therefore, options like suppressing
duplicates or expiring duplicates first will lead to unexpected
suggestions.
2016-05-28 21:23:35 +02:00
Eric Freese
011d8bdfd1 Refactor to remove prev cmd function and simplify escaping 2016-04-25 14:19:26 -06:00
Eric Freese
46d5fe174d Remove extra newline 2016-03-14 18:02:16 -06:00
Eric Freese
a314a01a6a Fix various bugs found while testing 2016-03-14 16:51:27 -06:00
Eric Freese
ab0f4c0bd0 Grammar and formatting 2016-03-14 16:51:20 -06:00
Eric Freese
ee6dde9ee8 Rename escape command function 2016-03-14 16:51:20 -06:00
Geza Lore
73f774bd5d Add match_prev_cmd strategy.
A new suggestion strategy 'match_prev_cmd' is available. This is a bit
more context aware variaton on the default strategy.
The suggestion will be:
- The newest history entry that matches the current prefix, AND
- Whose preceding history entry also matches the previously executed
command.

See src/strategies/match_prev_cmd.zsh for an example.
2016-03-14 16:51:20 -06:00
Geza Lore
976acc708c Fix default suggestion strategy and add testing 2016-03-14 16:51:20 -06:00
Eric Freese
83f78d0760 Add suggestion "strategy" concept with default strategy 2016-03-14 16:51:20 -06:00