2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-03 19:00:51 +00:00

Fix zsh completion arguments (fixes #473)

This commit is contained in:
Jay Berkenbilt 2021-01-03 16:46:54 -05:00
parent f0caf5e22d
commit a9bdeeb0e0
9 changed files with 62 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2021-01-03 Jay Berkenbilt <ejb@ql.org>
* Don't include -o nospace with zsh completion setup so file
completion works normally. Fixes #473.
2021-01-02 Jay Berkenbilt <ejb@ql.org> 2021-01-02 Jay Berkenbilt <ejb@ql.org>
* Make QPDFPageObjectHelper methods pipeContents, parseContents, * Make QPDFPageObjectHelper methods pipeContents, parseContents,

5
TODO
View File

@ -1,11 +1,6 @@
Candidates for upcoming release Candidates for upcoming release
=============================== ===============================
* Open "next" issues
* bugs
* #473: zsh completion with directories
* Investigate how serverless does completion
* Remember to check work `qpdf` project for private issues * Remember to check work `qpdf` project for private issues
* file with very slow page extraction * file with very slow page extraction
* big page even with --remove-unreferenced-resources=yes, even with --empty * big page even with --remove-unreferenced-resources=yes, even with --empty

View File

@ -5021,6 +5021,12 @@ print "\n";
was broken for pages with multiple content streams. was broken for pages with multiple content streams.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
Tweak zsh completion code to behave a little better with
respect to path completion.
</para>
</listitem>
</itemizedlist> </itemizedlist>
</listitem> </listitem>
</itemizedlist> </itemizedlist>

View File

@ -726,6 +726,8 @@ class ArgParser
OptionEntry oe_optionalParameter(param_arg_handler_t); OptionEntry oe_optionalParameter(param_arg_handler_t);
OptionEntry oe_requiredChoices(param_arg_handler_t, char const** choices); OptionEntry oe_requiredChoices(param_arg_handler_t, char const** choices);
void completionCommon(bool zsh);
void argHelp(); void argHelp();
void argVersion(); void argVersion();
void argCopyright(); void argCopyright();
@ -1637,7 +1639,7 @@ ArgParser::argHelp()
} }
void void
ArgParser::argCompletionBash() ArgParser::completionCommon(bool zsh)
{ {
std::string progname = argv[0]; std::string progname = argv[0];
std::string executable; std::string executable;
@ -1657,8 +1659,16 @@ ArgParser::argCompletionBash()
progname = appimage; progname = appimage;
} }
} }
std::cout << "complete -o bashdefault -o default -o nospace" if (zsh)
<< " -C " << progname << " " << whoami << std::endl; {
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 // Put output before error so calling from zsh works properly
std::string path = progname; std::string path = progname;
size_t slash = path.find('/'); size_t slash = path.find('/');
@ -1669,11 +1679,16 @@ ArgParser::argCompletionBash()
} }
} }
void
ArgParser::argCompletionBash()
{
completionCommon(false);
}
void void
ArgParser::argCompletionZsh() ArgParser::argCompletionZsh()
{ {
std::cout << "autoload -U +X bashcompinit && bashcompinit && "; completionCommon(true);
argCompletionBash();
} }
void void
ArgParser::argJsonHelp() ArgParser::argJsonHelp()
@ -3373,10 +3388,20 @@ ArgParser::addOptionsToCompletions()
iter != this->option_table->end(); ++iter) iter != this->option_table->end(); ++iter)
{ {
std::string const& arg = (*iter).first; std::string const& arg = (*iter).first;
if (arg == "--")
{
continue;
}
OptionEntry& oe = (*iter).second; OptionEntry& oe = (*iter).second;
std::string base = "--" + arg; std::string base = "--" + arg;
if (oe.param_arg_handler) 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 + "="); completions.insert(base + "=");
} }
if (! oe.parameter_needed) if (! oe.parameter_needed)

View File

@ -0,0 +1,2 @@
--decode-level=all
!--help

View File

@ -0,0 +1,4 @@
--annotate=n
!----
!--force-R5
!--force-V4

View File

@ -1,3 +1,4 @@
--annotate= --annotate=
!----
!--force-R5 !--force-R5
!--force-V4 !--force-V4

View File

@ -0,0 +1,7 @@
--check
--decode-level=all
--encrypt
!--completion-bash
!--copyright
!--help
!--version

View File

@ -0,0 +1,7 @@
--check
--completion-bash
--copyright
--decode-level=none
--encrypt
--help
--version