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 }