From b8668c657f35c57c8b38ee66527fabd88d1ef514 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 30 Nov 2025 11:17:15 -0500 Subject: [PATCH] Zsh completion: don't autoload bashcompinit unconditionally --- completions/zsh/_qpdf | 10 ++++++++++ libqpdf/QPDFArgParser.cc | 3 +-- manual/release-notes.rst | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/completions/zsh/_qpdf b/completions/zsh/_qpdf index 7c13abf..23fef14 100644 --- a/completions/zsh/_qpdf +++ b/completions/zsh/_qpdf @@ -1,2 +1,12 @@ #compdef qpdf +if (( ! $+functions[_bash_complete] && ! $+functions[complete] && ! $+functions[compgen] )); then + # If the user has not loaded bashcompinit and hasn't otherwise + # defined the functions it defines, load it. This enables zsh + # completion to work out of the box for users with no custom + # configuration. See + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1111509 for + # additional discussion. + autoload -U +X bashcompinit && bashcompinit +fi eval "$(/usr/bin/qpdf --completion-zsh)" +_bash_complete diff --git a/libqpdf/QPDFArgParser.cc b/libqpdf/QPDFArgParser.cc index db56e4d..72f5cc5 100644 --- a/libqpdf/QPDFArgParser.cc +++ b/libqpdf/QPDFArgParser.cc @@ -190,8 +190,7 @@ QPDFArgParser::completionCommon(bool zsh) // latter more characters ("$`\) are a problem and it's // virtually impossible to escape those in a locale-independent // way. - std::cout << "autoload -U +X bashcompinit && bashcompinit &&" - << "complete -o bashdefault -o default -C '" << progname << "' " << m->whoami + std::cout << "complete -o bashdefault -o default -C '" << progname << "' " << m->whoami << "\n"; } else { // we need a function wrapper that discards arguments to avoid diff --git a/manual/release-notes.rst b/manual/release-notes.rst index 73b309a..b2d6da0 100644 --- a/manual/release-notes.rst +++ b/manual/release-notes.rst @@ -63,7 +63,8 @@ more detail. AcroForm, Dests, Outlines, and PageLabels structures. - Fix completion scripts and handling to avoid leaking arguments - into the environment during completion. + into the environment during completion and to correctly handle + ``bashcompinit`` for zsh users. - Other enhancements -- libgit2 0.21.4