Opening a zipped coverage report with one click

Image

Tested on Ubunut 22.04

1. Opener script

  • Create a file ~/.local/bin/coverage_zip_opener with:
#!/bin/bash

tmp_folder="/tmp/coverage-report-opener"

if [ -z "$1" ]
then
 echo "Usage: coverage_zip_opener [filename]"
 exit -1
fi

if ! [[ "$1" =~ ^.*Pipeline.*Coverage.*\.zip$ || "$1" =~ ^.*merged_coverage_report.*\.zip$ ]]; then
 file-roller "$1"
 exit 0
fi

rm -Rf $tmp_folder

unzip -qq "$1" -d $tmp_folder
index_filename=$(find /tmp/coverage-report-opener -name "index.html" | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2- | head -1)

if [ -z "$index_filename" ]
then
 echo "No index file has been found within the zip $1"
 exit -1
fi

xdg-open "$index_filename"
  • Make it executable chmod +x ~/.local/bin/coverage_zip_opener
  • Make sure ~/.local/bin/ is contained in your $PATH" or put the script somewhere in your $PATH"
  • If you are not using the default archive extractor from ubuntu replace file-roller with your preferred application

2. Desktop file

  • Create a file ~/.local/share/applications/coverage-zip-opener.desktop with this content:
[Desktop Entry]
Type=Application
MimeType=application/zip
Name=Coverage Zip Opener
Exec=coverage_zip_opener %f

Now you should be able to right click a file like Pipeline_76154_Merged_Coverage.zip and select Coverage Zip Opener. The coverage report should open in a browser window.


3. (optional) Set as the default for opening *.zip files

If you dont want to right click, open with all the time, you can set this script as the default for *.zip files. The script tries to match the filename to a coverage report zip file and will fall back to a real unzipper if there is no match.

  • Right click any .zip files
  • Click Properties
  • Switch tab to Open With
  • Select Coverage Zip Opener
  • Click Set as default
Martin Schaflitzl