Commit a9bdeeb0e0059cf702f63c04affbcb56ecc8a29e
1 parent
f0caf5e2
Fix zsh completion arguments (fixes #473)
Showing
9 changed files
with
62 additions
and
10 deletions
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 | 2021-01-02 Jay Berkenbilt <ejb@ql.org> | 6 | 2021-01-02 Jay Berkenbilt <ejb@ql.org> |
| 2 | 7 | ||
| 3 | * Make QPDFPageObjectHelper methods pipeContents, parseContents, | 8 | * Make QPDFPageObjectHelper methods pipeContents, parseContents, |
TODO
| 1 | Candidates for upcoming release | 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 | * Remember to check work `qpdf` project for private issues | 4 | * Remember to check work `qpdf` project for private issues |
| 10 | * file with very slow page extraction | 5 | * file with very slow page extraction |
| 11 | * big page even with --remove-unreferenced-resources=yes, even with --empty | 6 | * big page even with --remove-unreferenced-resources=yes, even with --empty |
manual/qpdf-manual.xml
| @@ -5021,6 +5021,12 @@ print "\n"; | @@ -5021,6 +5021,12 @@ print "\n"; | ||
| 5021 | was broken for pages with multiple content streams. | 5021 | was broken for pages with multiple content streams. |
| 5022 | </para> | 5022 | </para> |
| 5023 | </listitem> | 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 | </itemizedlist> | 5030 | </itemizedlist> |
| 5025 | </listitem> | 5031 | </listitem> |
| 5026 | </itemizedlist> | 5032 | </itemizedlist> |
qpdf/qpdf.cc
| @@ -726,6 +726,8 @@ class ArgParser | @@ -726,6 +726,8 @@ class ArgParser | ||
| 726 | OptionEntry oe_optionalParameter(param_arg_handler_t); | 726 | OptionEntry oe_optionalParameter(param_arg_handler_t); |
| 727 | OptionEntry oe_requiredChoices(param_arg_handler_t, char const** choices); | 727 | OptionEntry oe_requiredChoices(param_arg_handler_t, char const** choices); |
| 728 | 728 | ||
| 729 | + void completionCommon(bool zsh); | ||
| 730 | + | ||
| 729 | void argHelp(); | 731 | void argHelp(); |
| 730 | void argVersion(); | 732 | void argVersion(); |
| 731 | void argCopyright(); | 733 | void argCopyright(); |
| @@ -1637,7 +1639,7 @@ ArgParser::argHelp() | @@ -1637,7 +1639,7 @@ ArgParser::argHelp() | ||
| 1637 | } | 1639 | } |
| 1638 | 1640 | ||
| 1639 | void | 1641 | void |
| 1640 | -ArgParser::argCompletionBash() | 1642 | +ArgParser::completionCommon(bool zsh) |
| 1641 | { | 1643 | { |
| 1642 | std::string progname = argv[0]; | 1644 | std::string progname = argv[0]; |
| 1643 | std::string executable; | 1645 | std::string executable; |
| @@ -1657,8 +1659,16 @@ ArgParser::argCompletionBash() | @@ -1657,8 +1659,16 @@ ArgParser::argCompletionBash() | ||
| 1657 | progname = appimage; | 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 | // Put output before error so calling from zsh works properly | 1672 | // Put output before error so calling from zsh works properly |
| 1663 | std::string path = progname; | 1673 | std::string path = progname; |
| 1664 | size_t slash = path.find('/'); | 1674 | size_t slash = path.find('/'); |
| @@ -1670,10 +1680,15 @@ ArgParser::argCompletionBash() | @@ -1670,10 +1680,15 @@ ArgParser::argCompletionBash() | ||
| 1670 | } | 1680 | } |
| 1671 | 1681 | ||
| 1672 | void | 1682 | void |
| 1683 | +ArgParser::argCompletionBash() | ||
| 1684 | +{ | ||
| 1685 | + completionCommon(false); | ||
| 1686 | +} | ||
| 1687 | + | ||
| 1688 | +void | ||
| 1673 | ArgParser::argCompletionZsh() | 1689 | ArgParser::argCompletionZsh() |
| 1674 | { | 1690 | { |
| 1675 | - std::cout << "autoload -U +X bashcompinit && bashcompinit && "; | ||
| 1676 | - argCompletionBash(); | 1691 | + completionCommon(true); |
| 1677 | } | 1692 | } |
| 1678 | void | 1693 | void |
| 1679 | ArgParser::argJsonHelp() | 1694 | ArgParser::argJsonHelp() |
| @@ -3373,10 +3388,20 @@ ArgParser::addOptionsToCompletions() | @@ -3373,10 +3388,20 @@ ArgParser::addOptionsToCompletions() | ||
| 3373 | iter != this->option_table->end(); ++iter) | 3388 | iter != this->option_table->end(); ++iter) |
| 3374 | { | 3389 | { |
| 3375 | std::string const& arg = (*iter).first; | 3390 | std::string const& arg = (*iter).first; |
| 3391 | + if (arg == "--") | ||
| 3392 | + { | ||
| 3393 | + continue; | ||
| 3394 | + } | ||
| 3376 | OptionEntry& oe = (*iter).second; | 3395 | OptionEntry& oe = (*iter).second; |
| 3377 | std::string base = "--" + arg; | 3396 | std::string base = "--" + arg; |
| 3378 | if (oe.param_arg_handler) | 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 | completions.insert(base + "="); | 3405 | completions.insert(base + "="); |
| 3381 | } | 3406 | } |
| 3382 | if (! oe.parameter_needed) | 3407 | if (! oe.parameter_needed) |
qpdf/qtest/qpdf/completion-decode-l-zsh.out
0 → 100644
qpdf/qtest/qpdf/completion-encrypt-40-zsh.out
0 → 100644
qpdf/qtest/qpdf/completion-encrypt-40.out
qpdf/qtest/qpdf/completion-later-arg-zsh.out
0 → 100644