From 3be7de77ac14c1da1cf3c3fa7eaa95da008c7157 Mon Sep 17 00:00:00 2001 From: re2zero Date: Wed, 27 May 2026 11:56:58 +0800 Subject: [PATCH] Use builtin echo to avoid conflicts with user aliases When users have an alias or function that shadows 'echo', it can break autosuggestions by either printing wrong suggestions or executing unwanted functions. This commit replaces all 'echo' calls with 'builtin echo' to ensure the shell's built-in echo is always used. Fixes: #843 --- src/async.zsh | 4 ++-- src/strategies/completion.zsh | 2 +- src/util.zsh | 2 +- zsh-autosuggestions.zsh | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/async.zsh b/src/async.zsh index e179734..874a160 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -34,12 +34,12 @@ _zsh_autosuggest_async_request() { # Fork a process to fetch a suggestion and open a pipe to read from it builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}< <( # Tell parent process our pid - echo $sysparams[pid] + builtin echo $sysparams[pid] # Fetch and print the suggestion local suggestion _zsh_autosuggest_fetch_suggestion "$1" - echo -nE "$suggestion" + builtin echo -nE "$suggestion" ) # There's a weird bug here where ^C stops working unless we force a fork diff --git a/src/strategies/completion.zsh b/src/strategies/completion.zsh index e2d114c..68417ef 100644 --- a/src/strategies/completion.zsh +++ b/src/strategies/completion.zsh @@ -39,7 +39,7 @@ _zsh_autosuggest_capture_completion_widget() { fi # The completion has been added, print the buffer as the suggestion - echo -nE - $'\0'$BUFFER$'\0' + builtin echo -nE - $'\0'$BUFFER$'\0' } zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget diff --git a/src/util.zsh b/src/util.zsh index 1f55d36..859ed35 100644 --- a/src/util.zsh +++ b/src/util.zsh @@ -7,5 +7,5 @@ _zsh_autosuggest_escape_command() { setopt localoptions EXTENDED_GLOB # Escape special chars in the string (requires EXTENDED_GLOB) - echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" + builtin echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index e780225..24b0212 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -128,7 +128,7 @@ _zsh_autosuggest_escape_command() { setopt localoptions EXTENDED_GLOB # Escape special chars in the string (requires EXTENDED_GLOB) - echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" + builtin echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" } #--------------------------------------------------------------------# @@ -534,7 +534,7 @@ _zsh_autosuggest_capture_completion_widget() { fi # The completion has been added, print the buffer as the suggestion - echo -nE - $'\0'$BUFFER$'\0' + builtin echo -nE - $'\0'$BUFFER$'\0' } zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget @@ -791,12 +791,12 @@ _zsh_autosuggest_async_request() { # Fork a process to fetch a suggestion and open a pipe to read from it builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}< <( # Tell parent process our pid - echo $sysparams[pid] + builtin echo $sysparams[pid] # Fetch and print the suggestion local suggestion _zsh_autosuggest_fetch_suggestion "$1" - echo -nE "$suggestion" + builtin echo -nE "$suggestion" ) # There's a weird bug here where ^C stops working unless we force a fork