Score:3

How to make firefox command autcomplete SVG file paths when I press tab key

lu flag

I have Mozilla Firefox 95.0.1 running on Ubuntu 20.04. I need to open some SVG files that contain animations in the firefox browser using the command line as follows:

firefox <Tab Key>

The filenames are generally long and I don't want to copy paste them or type them manually, so when I press Tab key multiple time I would like the filenmae to be autocompleted but in my case nothing happens.

How can I make firefox command on the terminal autocomplete SVG file paths by Pressing Tab key?

Score:4
in flag

You can do this by modifying the bash-completions definition for Firefox. If you need autocomplete support for a limited number of files, then something like this would work:

  1. Open Terminal (if it's not already open)

  2. Open the appropriate completions file for Firefox with sudo:

    sudo {editor of choice} /usr/share/bash-completion/completions/firefox
    

    Note: Be sure to replace {editor of choice} with your editor of choice.

  3. Around line 42, you will see this:

    _filedir "@(?([xs])htm?(l)|pdf)"
    

    This is the line that controls what sort of file extensions are available as an autocomplete for Firefox. Here we can see support for .htm, .html, .xhtm, .xtml, .xshtm, .xshtml, and .pdf. You can add additional file extensions after pdf:

    _filedir "@(?([xs])htm?(l)|pdf|svg|jpg|jpeg|png|gif)"
    

    Here I've added .svg, .jpg, .jpeg, .png, and .gif. Feel free to add/remove as needed.

  4. Save the file.

  5. Reload your bash source:

    source ~/.bashrc
    

    Note: Alternatively, you can close the terminal and re-open it. If you have any other Terminal windows (or SSH connections) open, then the source will need to be reloaded in each before they can use this autocompletion.

Additionally ...

If you would like autocomplete to allow any file to work with Firefox regardless of the browser's ability to render the information, then you can remove everything after _filedir to leave a blank:

_filedir

This will allow you to autocomplete nonsensical things like:

firefox ~/Documents/backup.sql.gz
vanadium avatar
cn flag
Looks very nice, but you are changing system files controlled by the APT system. Probably copying the file to `/etc/bash_completion.d` and changing that copy will be a better approach: that file will take precedence and will not to be reverted by future updates.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.