diff --git a/Makefile b/Makefile index b89ff04..f6d13a7 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ SRC_DIR := ./src SRC_FILES := \ - $(SRC_DIR)/setup.zsh \ $(SRC_DIR)/config.zsh \ $(SRC_DIR)/util.zsh \ - $(SRC_DIR)/features.zsh \ $(SRC_DIR)/bind.zsh \ $(SRC_DIR)/highlight.zsh \ $(SRC_DIR)/widgets.zsh \ diff --git a/README.md b/README.md index 4507c6b..dc7d21f 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to configure the style that the suggestion - `history`: Chooses the most recent match from history. - `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches the most recently executed command ([more info](src/strategies/match_prev_cmd.zsh)). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`. -- `completion`: (experimental) Chooses a suggestion based on what tab-completion would suggest. +- `completion`: (experimental) Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` and `zutil` modules) For example, setting `ZSH_AUTOSUGGEST_STRATEGY=(history completion)` will first try to find a suggestion from your history, but, if it can't find a match, will find a suggestion from the completion engine. diff --git a/src/features.zsh b/src/features.zsh deleted file mode 100644 index 7a5248f..0000000 --- a/src/features.zsh +++ /dev/null @@ -1,19 +0,0 @@ - -#--------------------------------------------------------------------# -# Feature Detection # -#--------------------------------------------------------------------# - -_zsh_autosuggest_feature_detect_zpty_returns_fd() { - typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD - typeset -h REPLY - - zpty zsh_autosuggest_feature_detect '{ zshexit() { kill -KILL $$; sleep 1 } }' - - if (( REPLY )); then - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1 - else - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0 - fi - - zpty -d zsh_autosuggest_feature_detect -} diff --git a/src/setup.zsh b/src/setup.zsh deleted file mode 100644 index c74489f..0000000 --- a/src/setup.zsh +++ /dev/null @@ -1,10 +0,0 @@ - -#--------------------------------------------------------------------# -# Setup # -#--------------------------------------------------------------------# - -# Precmd hooks for initializing the library and starting pty's -autoload -Uz add-zsh-hook - -# Asynchronous suggestions are generated in a pty -zmodload zsh/zpty diff --git a/src/start.zsh b/src/start.zsh index a73ee3b..ff93fdf 100644 --- a/src/start.zsh +++ b/src/start.zsh @@ -17,4 +17,5 @@ _zsh_autosuggest_start() { } # Start the autosuggestion widgets on the next precmd +autoload -Uz add-zsh-hook add-zsh-hook precmd _zsh_autosuggest_start diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index 422f4cc..5f71d98 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -87,6 +87,8 @@ _zsh_autosuggest_capture_buffer() { } _zsh_autosuggest_capture_completion() { + zmodload zsh/zpty 2>/dev/null || return + typeset -g completion local line REPLY diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index 4b617cc..41c659f 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -25,16 +25,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. -#--------------------------------------------------------------------# -# Setup # -#--------------------------------------------------------------------# - -# Precmd hooks for initializing the library and starting pty's -autoload -Uz add-zsh-hook - -# Asynchronous suggestions are generated in a pty -zmodload zsh/zpty - #--------------------------------------------------------------------# # Global Configuration Variables # #--------------------------------------------------------------------# @@ -122,25 +112,6 @@ _zsh_autosuggest_escape_command() { echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" } -#--------------------------------------------------------------------# -# Feature Detection # -#--------------------------------------------------------------------# - -_zsh_autosuggest_feature_detect_zpty_returns_fd() { - typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD - typeset -h REPLY - - zpty zsh_autosuggest_feature_detect '{ zshexit() { kill -KILL $$; sleep 1 } }' - - if (( REPLY )); then - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1 - else - _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0 - fi - - zpty -d zsh_autosuggest_feature_detect -} - #--------------------------------------------------------------------# # Widget Helpers # #--------------------------------------------------------------------# @@ -586,6 +557,8 @@ _zsh_autosuggest_capture_buffer() { } _zsh_autosuggest_capture_completion() { + zmodload zsh/zpty 2>/dev/null || return + typeset -g completion local line REPLY @@ -799,4 +772,5 @@ _zsh_autosuggest_start() { } # Start the autosuggestion widgets on the next precmd +autoload -Uz add-zsh-hook add-zsh-hook precmd _zsh_autosuggest_start