#928704 dgit: add bash completion for command-line options

Package:
src:dgit
Source:
dgit
Submitter:
Colin Watson
Date:
2025-01-04 10:09:02 UTC
Severity:
wishlist
Tags:
#928704#5
Date:
2019-05-09 09:15:37 UTC
From:
To:
dgit has a number of rather long option names (for example though not
limited to the --deliberately-* family).  Having to type these out by
hand makes me wish for bash completion support, similar to the generally
excellent completion provided by git itself, so that I could
tab-complete option names.

I'm aware that writing shell completion files is sometimes a rather
open-ended task, so for the purposes of this bug I'm just requesting
completion over options.

Thanks,

#928704#10
Date:
2019-05-09 09:43:06 UTC
From:
To:
Colin Watson writes ("Bug#928704: dgit: add bash completion for command-line options"):

This is a fine idea.

However I don't use bash-completion because I personally find it
annoying, and I have no idea how to do this.  I would welcome
contributions, even in the form of a skeleton or initial version which
I could keep up to date.

Thanks,
Ian.

#928704#17
Date:
2019-05-09 09:52:04 UTC
From:
To:
Yes, I'm afraid that while I use it and (with some exceptions) generally
like it, I have never actually rolled up my sleeves and worked out how
to write the things myself, so this would be a learning curve for me
too.  It'll go on my to-do list somewhere but quite a long way down, so
if anyone else wants to tackle it then that might be better ...

I believe that in general terms the two strategies are to enumerate all
the possible options separately or to have some way to ask the program
which options it supports.  The bash-completion file for git appears to
take the former strategy for the relatively small number of options
supported by the top-level git program, and the latter strategy for git
subcommands (see e.g. "git checkout --git-completion-helper").

Thanks,

#928704#22
Date:
2019-05-09 10:00:02 UTC
From:
To:
Colin Watson writes ("Re: Bug#928704: dgit: add bash completion for command-line options"):

In the case of dgit, the command line parser is not table driven
(although it does have some tables) so the latter strategy won't work.

But I think the option parser perl code could be scanned by some
ad-hoc perl code, at package build time.  It's mostly quite formulaic.

I can probably implement something like that, given a hand-coded
completion file (perhaps a partial one) and someone to ask questions.

Ian.

#928704#27
Date:
2019-12-27 18:04:56 UTC
From:
To:
Hi,

I’m attaching a bash completion script which performs completion for many, but
not all options and commands.

Specifically, it autocompletes the most common subcommands, but only provides
arguments autocompletion for only two of them, import-dsc and rpush, for
practical reasons.

For dgit options, it provides two-level completion for the most popular options,
excluding rarely used or dangerous ("use when you know what you’re doing") options.
The two-levels work in a way to not overwhelm the user with options when they Tab
twice, so only some but not all arguments to e.g. --quilt= are shown:

$ dgit --
--baredebian                                 --force-import-gitapply-no-absurd
--baredebian+git                             --force-reusing-version
--baredebian+tarball                         --force-unrepresentable
--build-products-dir=                        --force-unsupported-source-format
--clean                                      --force-uploading-binaries
--clean=dpkg-source                          --force-uploading-source-only
--clean=git                                  --gbp
--clean=git-ff                               --include-dirty
--damp-run                                   --new
--delayed=                                   --no-rm-on-error
--deliberately-fresh-repo                    --no-sign
--deliberately-include-questionable-history  --overwrite
--deliberately-not-fast-forward              --package
--dep14tag                                   --quilt
--distro=                                    --quilt=auto
--dpm                                        --quilt=linear
--dry-run                                    --rm-old-changes
--force-changes-origs-exactly                --save-dgit-view=
--force-dsc-changes-mismatch                 --split-view=
--force-import-dsc-with-dgit-field           --upstream-commitish=
--force-import-gitapply-absurd               

However, when the user types --quilt=, the rest of them is shown:

$ dgit --quilt=
auto            baredebian+git      dpm      linear       nofix      unapplied
baredebian      baredebian+tarball  gbp      nocheck      smash

For --upstream-commitish= the script autocompletes some tags, starting with tags
with the matching version, and the rest sorted by version:

$ dgit --upstream-commitish=upstream/1.
upstream/1.11.0  upstream/1.6.0

For options accepting both = and space (--quilt, --clean, --package) the completion
is performed for both versions; the list of all options above shows the "spaced" (--clean)
version and a couple of commonly used versions with = and an argument. For options
only accepting =, the option ends with = to allow the user to start typing the argument
directly after that.

#928704#32
Date:
2021-10-05 08:29:55 UTC
From:
To:
Hi Ian,

Is there anything I can do to help you with this? I also considered
submitting the script to the bash-completion project, but it seems
they’d have preferred if dgit shipped it rather them.

#928704#37
Date:
2021-10-06 19:28:51 UTC
From:
To:
Andrej Shadura writes ("Bug#928704: dgit: add bash completion for command-line options"):

I agree that it would better live in src:dgit.

But I have a concern about how to keep it up to date.  That's why I
suggested autogenerating it from the option parser.

However, I looked at the attachment
https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=928704;filename=dgit_completion;msg=27
and well, I'm really not sure I can do something sane to generate
that from the source code.

Do you have any suggestions ?  Surely users of bash completion[1]
wouldn't like it if new options didn't autocomplete just because the
completions hadn't been updated.

Ian.

[1] This generally doesn't include me precisely because IME things
often turn out not to complete properly.  So maybe I am being too
precious.