zsh-users / zsh-completions

Additional completion definitions for Zsh.
Other
6.87k stars 712 forks source link

fix(yarn): use `builtin cd` in yarn completion #1077

Closed hwknsj closed 4 months ago

hwknsj commented 4 months ago

fix(yarn): use builtin cd in yarn completion to avoid infinite loop

This is a clone of my pull request on the oh-my-zsh repository which has been merged into production branch.

This simply replaces 3 instances of cd in the _yarn completion script with builtin cd to avoid issues in the case that cd has been aliased or redefined. While this may sound like an unusual situation, consider the example below.

Example: cd is 'enhanced' to list contents of the new directory, e.g.

function cd () {
    builtin cd "$1"
    ls -laFhGT
}

Chaos ensues on invoking completion, yarn ⇥ tab

asciinema of yarn completion bug

Here is a video screen recording if asciinema link goes away:

Standards checklist:

Changes:

Other comments:

I can't really think of a better way to do this. I considered /bin/cd, but we can pretty safely assume that the user's shell is zsh and builtin cd always works.

syohex commented 4 months ago

Thanks