1

I am using graphViz under bash / Cygwin, but somehow when calling it, bash tab autocomplete does not do anything.

Example files:

  • myGraph.graphviz is the input file
  • myGraph.graphviz.png should be the output file.

The command to make the graphic is

dot -T png -o myGraph.graphviz.png myGraph.graphviz

Of course I want to input

dot -T png -o myTab.png myTab

to autocomplete these file names, but nothing happens! I can enter cat myTab and it gives cat myGraph.graphviz, but why doesn't it work after dot? Does bash need an extra autocomplete module for every command I could enter?

2

I created the example files in my Debian. Indeed, dot -T png -o myTab doesn't work. Then (after completing manually) dot -T png -o myGraph.graphviz.png myTab also doesn't work. There are two separate issues.


The general manual for Graphviz programs specifies:

-ooutfile
Write output to file outfile. […]

Bash completion in my Debian obeys this literally: it supports -ooutfile, not -o outfile. Even if the latter works with dot (and I don't know this), the completion doesn't support it. You should proceed like this:

dot -T png -omyTab

without any space after -o. In my tests the above works.


To make the second Tab work I inspected /usr/share/bash-completion/completions/dot. The relevant line near the end is:

_filedir dot

This will offer you directories to descend into and files to specify, but only files with names ending with .dot or .DOT. Probably you can manually provide a file not matching this pattern and nothing bad will happen, yet if you rely on the completion mechanism then the file name should end properly.

In fact I don't know dot at all, I know Bash completions a little. Maybe the requirement doesn't make sense and the completion for dot would be more helpful if it allowed any file. In such case I copy the original file to /etc/bash_completion.d/ and modify the copy, so the line

_filedir dot

at the end of the function becomes

_filedir

This is a system-wide change. The change will not affect existing shells, so start a new bash to test it. If you cannot (or don't want to) modify /etc/bash_completion.d/ then see this answer. It provides a way to have your private (user-specific) bash_completion.d/.

Note this change will allow you to type dot -T png -o myTab and the completion will work. However in this particular case it has nothing to do with -o internally, it's the general completion for operands and it would work even after some unexpected or invalid option (e.g. dot -T png -: myTab).

|improve this answer|||||
  • This is cool, I did not know dot wants a dot file. I just edited the line in /usr/share/bash-completion/completions/dot, since this is my personal cygwin installation, and it works!! – Bowi Sep 23 '19 at 8:33
  • 1
    @Bowi OK. In general I expect files in /usr/share/bash-completion/completions/ to be updated without warning (if you ever update/upgrade), so your edit may be reverted in the future. A copy in /etc/bash_completion.d/ will most likely stay untouched. – Kamil Maciorowski Sep 23 '19 at 8:39
  • Very good point. Copied it. =) – Bowi Sep 23 '19 at 8:45
0

This can happen if there is another dot command on the system for which a real autocomplete definition is installed, and that command doesn't expect a file at that point. You get file auto-completion on all parameters by default for unknown commands, but specific commands can set their own specific auto-completion. Check /etc/bash_completion and /etc/bash_completion.d/.

PS: Another explanation is that the dot auto-completion script isn't coherent with the doc, or that you made a mistake in your arguments.

|improve this answer|||||
  • I do not have an /etc/bash_completion, only a /etc/bash_completion.d/ with a few files in it. grep -Ri "dot" does not bring up anyting though... – Bowi Sep 20 '19 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.