Skip to content

zsh completion setup fails with 'parse error near elif' #3277

Closed

Description

@msaipraneeth

When setting up zsh on the back of git for Windows bash shell, zsh throws a parse error when setting up autocomplete.

Note: using this in a Python venv, but other aspects of the zsh command line are working.

The zsh in use is the msys2 release: https://packages.msys2.org/packages/zsh?repo=msys&variant=x86_64

Minimal Reproduction

https://github.com/msaipraneeth/click-tuple-param

Enable autocompletion:

eval "$(_TUPLE_PARAM_COMPLETE=zsh_source tuple-param)"                                                                                                                                                                   
Error:                                  

  zsh: parse error near `elif'                                                                                                                                                                                             

The command should register zsh completion without errors.

Environment:

  • Python version: 3.11
  • Click version: 8.3.1

Activity

  1. azanali-10xe commented on Mar 27, 2026

    @azanali-10xe

    I have been looking into this, @davidism can you let me know why the linked PR was closed?

  2. davidism commented on Mar 27, 2026

    @davidism
    Member

    LLM generated

  3. falkben commented on May 18, 2026

    @falkben
    Contributor

    I was able to reproduce the issue (on mac) by rewriting the shell completion script to use CRLF line endings. With those line endings, zsh fails to parse a fi\r and when it reaches elif you get the parse error.

    tuple-param-zsh-complete-crlf.zsh:18: parse error near elif'`

    This occurs because inside _compat.py, it uses Python’s TextIOWrapper, which translates each written \n to the platform's line separator. So even though the stream contains only \n it gets converted to \r\n on windows.

    I believe the fix in #3279 correctly addresses this issue. The PR avoids emitting text-mode (which turns \n into \r\n) and instead emits output as bytes so there's no newline translation. This should keep the generated zsh script LF-only.

  4. added
    windows
    shell completion
    on May 21, 2026
  5. added this to the 8.4.1 milestone on May 21, 2026
  6. locked as resolved and limited conversation to collaborators on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    shell completionwindows

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions