From 78ba07179a38584ed6756307f329d64da03b0638 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Thu, 26 Jan 2017 16:35:33 -0700 Subject: [PATCH] Add feature detection Checks whether `zpty` gives a file descriptor, which was not the case in older versions of zsh. Based on https://github.com/mafredri/zsh-async/blob/a4b2f81c966a00eeb38876d505d97423cc8addfd/async.zsh#L395-L401 --- Makefile | 1 + src/features.zsh | 19 +++++++++++++++++++ src/start.zsh | 1 + zsh-autosuggestions.zsh | 20 ++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/features.zsh diff --git a/Makefile b/Makefile index 2ea2763..63d8020 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ SRC_FILES := \ $(SRC_DIR)/setup.zsh \ $(SRC_DIR)/config.zsh \ $(SRC_DIR)/util.zsh \ + $(SRC_DIR)/features.zsh \ $(SRC_DIR)/deprecated.zsh \ $(SRC_DIR)/bind.zsh \ $(SRC_DIR)/highlight.zsh \ diff --git a/src/features.zsh b/src/features.zsh new file mode 100644 index 0000000..cd960e5 --- /dev/null +++ b/src/features.zsh @@ -0,0 +1,19 @@ + +#--------------------------------------------------------------------# +# Feature Detection # +#--------------------------------------------------------------------# + +_zsh_autosuggest_feature_detect() { + typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD + typeset -h REPLY + + zpty $ZSH_AUTOSUGGEST_PTY_NAME : + + if (( REPLY )); then + _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1 + else + _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0 + fi + + zpty -d $ZSH_AUTOSUGGEST_PTY_NAME +} diff --git a/src/start.zsh b/src/start.zsh index ab60afe..0633da3 100644 --- a/src/start.zsh +++ b/src/start.zsh @@ -7,6 +7,7 @@ _zsh_autosuggest_start() { add-zsh-hook -d precmd _zsh_autosuggest_start + _zsh_autosuggest_feature_detect _zsh_autosuggest_check_deprecated_config _zsh_autosuggest_bind_widgets } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index c635630..0d17ef7 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -111,6 +111,25 @@ _zsh_autosuggest_escape_command() { echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" } +#--------------------------------------------------------------------# +# Feature Detection # +#--------------------------------------------------------------------# + +_zsh_autosuggest_feature_detect() { + typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD + typeset -h REPLY + + zpty $ZSH_AUTOSUGGEST_PTY_NAME : + + if (( REPLY )); then + _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1 + else + _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0 + fi + + zpty -d $ZSH_AUTOSUGGEST_PTY_NAME +} + #--------------------------------------------------------------------# # Handle Deprecated Variables/Widgets # #--------------------------------------------------------------------# @@ -570,6 +589,7 @@ add-zsh-hook precmd _zsh_autosuggest_async_recreate_pty _zsh_autosuggest_start() { add-zsh-hook -d precmd _zsh_autosuggest_start + _zsh_autosuggest_feature_detect _zsh_autosuggest_check_deprecated_config _zsh_autosuggest_bind_widgets }