diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-01-03 22:46:54 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-01-04 21:17:35 +0100 |
commit | a9bdeeb0e0059cf702f63c04affbcb56ecc8a29e (patch) | |
tree | f7c8dabc61cb58d567c86932fc48a3b5703dcb7d /qpdf | |
parent | f0caf5e22d22f27fa7153a22a3507cca7129f18e (diff) | |
download | qpdf-a9bdeeb0e0059cf702f63c04affbcb56ecc8a29e.tar.zst |
Fix zsh completion arguments (fixes #473)
Diffstat (limited to 'qpdf')
-rw-r--r-- | qpdf/qpdf.cc | 35 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/completion-decode-l-zsh.out | 2 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/completion-encrypt-40-zsh.out | 4 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/completion-encrypt-40.out | 1 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/completion-later-arg-zsh.out | 7 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/completion-top-arg-zsh.out | 7 |
6 files changed, 51 insertions, 5 deletions
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index c11f2486..0d1ab988 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -726,6 +726,8 @@ class ArgParser OptionEntry oe_optionalParameter(param_arg_handler_t); OptionEntry oe_requiredChoices(param_arg_handler_t, char const** choices); + void completionCommon(bool zsh); + void argHelp(); void argVersion(); void argCopyright(); @@ -1637,7 +1639,7 @@ ArgParser::argHelp() } void -ArgParser::argCompletionBash() +ArgParser::completionCommon(bool zsh) { std::string progname = argv[0]; std::string executable; @@ -1657,8 +1659,16 @@ ArgParser::argCompletionBash() progname = appimage; } } - std::cout << "complete -o bashdefault -o default -o nospace" - << " -C " << progname << " " << whoami << std::endl; + if (zsh) + { + std::cout << "autoload -U +X bashcompinit && bashcompinit && "; + } + std::cout << "complete -o bashdefault -o default"; + if (! zsh) + { + std::cout << " -o nospace"; + } + std::cout << " -C " << progname << " " << whoami << std::endl; // Put output before error so calling from zsh works properly std::string path = progname; size_t slash = path.find('/'); @@ -1670,10 +1680,15 @@ ArgParser::argCompletionBash() } void +ArgParser::argCompletionBash() +{ + completionCommon(false); +} + +void ArgParser::argCompletionZsh() { - std::cout << "autoload -U +X bashcompinit && bashcompinit && "; - argCompletionBash(); + completionCommon(true); } void ArgParser::argJsonHelp() @@ -3373,10 +3388,20 @@ ArgParser::addOptionsToCompletions() iter != this->option_table->end(); ++iter) { std::string const& arg = (*iter).first; + if (arg == "--") + { + continue; + } OptionEntry& oe = (*iter).second; std::string base = "--" + arg; if (oe.param_arg_handler) { + if (zsh_completion) + { + // zsh doesn't treat = as a word separator, so add all + // the options so we don't get a space after the =. + addChoicesToCompletions(arg, base + "="); + } completions.insert(base + "="); } if (! oe.parameter_needed) diff --git a/qpdf/qtest/qpdf/completion-decode-l-zsh.out b/qpdf/qtest/qpdf/completion-decode-l-zsh.out new file mode 100644 index 00000000..131a2470 --- /dev/null +++ b/qpdf/qtest/qpdf/completion-decode-l-zsh.out @@ -0,0 +1,2 @@ +--decode-level=all +!--help diff --git a/qpdf/qtest/qpdf/completion-encrypt-40-zsh.out b/qpdf/qtest/qpdf/completion-encrypt-40-zsh.out new file mode 100644 index 00000000..82541e98 --- /dev/null +++ b/qpdf/qtest/qpdf/completion-encrypt-40-zsh.out @@ -0,0 +1,4 @@ +--annotate=n +!---- +!--force-R5 +!--force-V4 diff --git a/qpdf/qtest/qpdf/completion-encrypt-40.out b/qpdf/qtest/qpdf/completion-encrypt-40.out index 3a184a6b..a45c605f 100644 --- a/qpdf/qtest/qpdf/completion-encrypt-40.out +++ b/qpdf/qtest/qpdf/completion-encrypt-40.out @@ -1,3 +1,4 @@ --annotate= +!---- !--force-R5 !--force-V4 diff --git a/qpdf/qtest/qpdf/completion-later-arg-zsh.out b/qpdf/qtest/qpdf/completion-later-arg-zsh.out new file mode 100644 index 00000000..e4ed848c --- /dev/null +++ b/qpdf/qtest/qpdf/completion-later-arg-zsh.out @@ -0,0 +1,7 @@ +--check +--decode-level=all +--encrypt +!--completion-bash +!--copyright +!--help +!--version diff --git a/qpdf/qtest/qpdf/completion-top-arg-zsh.out b/qpdf/qtest/qpdf/completion-top-arg-zsh.out new file mode 100644 index 00000000..ce613a59 --- /dev/null +++ b/qpdf/qtest/qpdf/completion-top-arg-zsh.out @@ -0,0 +1,7 @@ +--check +--completion-bash +--copyright +--decode-level=none +--encrypt +--help +--version |