[xdg-open] Prevent specific application from opening any filetype by default

You have an annoying application, which sets itself to open everything and fuck everything up. But the default application in your DE is not good enough to remove it, and xdg-mime doesn't allow you to remove an application completely.

Use this fish script. (Requires fish shell 3.x)

Run it with your own user once, and run it with sudo one more time.

#!/bin/fish

set desktop_to_remove $argv[1]
echo "$desktop_to_remove" | grep -F .desktop ; or begin
    echo "Usage: ./this-program.fish xxx.desktop"
    exit 1
end
echo "Removing $desktop_to_remove from all xdg-open files..."

set xdgfiles (env XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default nonexist/nonexist 2>| string replace ' and ' \n | string replace 'Checking ' '')

for fl in $xdgfiles
    test -f $fl ; or continue

    test -f $fl.backup ; and begin
        read -P "Overwrite $fl.backup ? (y/n) " | grep -i y > /dev/null
        or exit 2
    end

    echo "Modifying $fl, creating backup $fl.backup ..."
    cp $fl $fl.backup
    and cat $fl | string replace "$desktop_to_remove;" '' | string replace -r '^[a-zA-Z0-9_/-]=$' '' > /tmp/.1
    mv /tmp/.1 $fl
    or exit $status
end