Skip to content

Shadowing default echo with an alias/function can break autosuggestions #843

@Fruchix

Description

@Fruchix

Describe the bug

If the shell builtin "echo" is shadowed by an alias or a function, it is the alias/function that will be used by zsh-autosuggestions, which can break the autosuggestion by either printing a wrong suggestion, or executing an unwanted function.

To Reproduce

Steps to reproduce the behavior:

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
zsh -df
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

# example of printing the wrong suggestion
alias echo="builtin echo 'DEBUG: '"

# example of executing unwanted function
alias echo="ls; builtin echo 'DEBUG: '"

Expected behavior

I feel like zsh autosuggestions should always use the builtin echo, an being able to change the echo command is not a feature that could be beneficial.

Especially in src/async.zsh, the following "echo"s are vulnerable:

# 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]

		# Fetch and print the suggestion
		local suggestion
		_zsh_autosuggest_fetch_suggestion "$1"
		echo -nE "$suggestion"
	)

Screenshots

Image Image

In the second screenshot, I believe the number 29970 comes from echo $sysparams[pid].

Desktop

  • OS + distribution: MacOS Sequoia
  • Zsh version: 5.9
  • Plugin version: 85919cd (latest tag is v0.7.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions