Commit a9bdeeb0e0059cf702f63c04affbcb56ecc8a29e

Authored by Jay Berkenbilt
1 parent f0caf5e2

Fix zsh completion arguments (fixes #473)

ChangeLog
  1 +2021-01-03 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Don't include -o nospace with zsh completion setup so file
  4 + completion works normally. Fixes #473.
  5 +
1 6 2021-01-02 Jay Berkenbilt <ejb@ql.org>
2 7  
3 8 * Make QPDFPageObjectHelper methods pipeContents, parseContents,
... ...
1 1 Candidates for upcoming release
2 2 ===============================
3 3  
4   -* Open "next" issues
5   - * bugs
6   - * #473: zsh completion with directories
7   - * Investigate how serverless does completion
8   -
9 4 * Remember to check work `qpdf` project for private issues
10 5 * file with very slow page extraction
11 6 * big page even with --remove-unreferenced-resources=yes, even with --empty
... ...
manual/qpdf-manual.xml
... ... @@ -5021,6 +5021,12 @@ print &quot;\n&quot;;
5021 5021 was broken for pages with multiple content streams.
5022 5022 </para>
5023 5023 </listitem>
  5024 + <listitem>
  5025 + <para>
  5026 + Tweak zsh completion code to behave a little better with
  5027 + respect to path completion.
  5028 + </para>
  5029 + </listitem>
5024 5030 </itemizedlist>
5025 5031 </listitem>
5026 5032 </itemizedlist>
... ...
qpdf/qpdf.cc
... ... @@ -726,6 +726,8 @@ class ArgParser
726 726 OptionEntry oe_optionalParameter(param_arg_handler_t);
727 727 OptionEntry oe_requiredChoices(param_arg_handler_t, char const** choices);
728 728  
  729 + void completionCommon(bool zsh);
  730 +
729 731 void argHelp();
730 732 void argVersion();
731 733 void argCopyright();
... ... @@ -1637,7 +1639,7 @@ ArgParser::argHelp()
1637 1639 }
1638 1640  
1639 1641 void
1640   -ArgParser::argCompletionBash()
  1642 +ArgParser::completionCommon(bool zsh)
1641 1643 {
1642 1644 std::string progname = argv[0];
1643 1645 std::string executable;
... ... @@ -1657,8 +1659,16 @@ ArgParser::argCompletionBash()
1657 1659 progname = appimage;
1658 1660 }
1659 1661 }
1660   - std::cout << "complete -o bashdefault -o default -o nospace"
1661   - << " -C " << progname << " " << whoami << std::endl;
  1662 + if (zsh)
  1663 + {
  1664 + std::cout << "autoload -U +X bashcompinit && bashcompinit && ";
  1665 + }
  1666 + std::cout << "complete -o bashdefault -o default";
  1667 + if (! zsh)
  1668 + {
  1669 + std::cout << " -o nospace";
  1670 + }
  1671 + std::cout << " -C " << progname << " " << whoami << std::endl;
1662 1672 // Put output before error so calling from zsh works properly
1663 1673 std::string path = progname;
1664 1674 size_t slash = path.find('/');
... ... @@ -1670,10 +1680,15 @@ ArgParser::argCompletionBash()
1670 1680 }
1671 1681  
1672 1682 void
  1683 +ArgParser::argCompletionBash()
  1684 +{
  1685 + completionCommon(false);
  1686 +}
  1687 +
  1688 +void
1673 1689 ArgParser::argCompletionZsh()
1674 1690 {
1675   - std::cout << "autoload -U +X bashcompinit && bashcompinit && ";
1676   - argCompletionBash();
  1691 + completionCommon(true);
1677 1692 }
1678 1693 void
1679 1694 ArgParser::argJsonHelp()
... ... @@ -3373,10 +3388,20 @@ ArgParser::addOptionsToCompletions()
3373 3388 iter != this->option_table->end(); ++iter)
3374 3389 {
3375 3390 std::string const& arg = (*iter).first;
  3391 + if (arg == "--")
  3392 + {
  3393 + continue;
  3394 + }
3376 3395 OptionEntry& oe = (*iter).second;
3377 3396 std::string base = "--" + arg;
3378 3397 if (oe.param_arg_handler)
3379 3398 {
  3399 + if (zsh_completion)
  3400 + {
  3401 + // zsh doesn't treat = as a word separator, so add all
  3402 + // the options so we don't get a space after the =.
  3403 + addChoicesToCompletions(arg, base + "=");
  3404 + }
3380 3405 completions.insert(base + "=");
3381 3406 }
3382 3407 if (! oe.parameter_needed)
... ...
qpdf/qtest/qpdf/completion-decode-l-zsh.out 0 → 100644
  1 +--decode-level=all
  2 +!--help
... ...
qpdf/qtest/qpdf/completion-encrypt-40-zsh.out 0 → 100644
  1 +--annotate=n
  2 +!----
  3 +!--force-R5
  4 +!--force-V4
... ...
qpdf/qtest/qpdf/completion-encrypt-40.out
1 1 --annotate=
  2 +!----
2 3 !--force-R5
3 4 !--force-V4
... ...
qpdf/qtest/qpdf/completion-later-arg-zsh.out 0 → 100644
  1 +--check
  2 +--decode-level=all
  3 +--encrypt
  4 +!--completion-bash
  5 +!--copyright
  6 +!--help
  7 +!--version
... ...
qpdf/qtest/qpdf/completion-top-arg-zsh.out 0 → 100644
  1 +--check
  2 +--completion-bash
  3 +--copyright
  4 +--decode-level=none
  5 +--encrypt
  6 +--help
  7 +--version
... ...