Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading