Skip to content

Instantly share code, notes, and snippets.

@GGORG0
Last active March 10, 2023 10:37
Show Gist options
  • Save GGORG0/89a2048e143f9ff255b52ff1edc75331 to your computer and use it in GitHub Desktop.
Save GGORG0/89a2048e143f9ff255b52ff1edc75331 to your computer and use it in GitHub Desktop.
Install Flathub apps directly in the terminal (ft. appstream: URIs)

Have you ever thought "How can I install Flathub apps without all the hassle? I hate Gnome Software, searching for flatpaks in the terminal is a nightmare (app ids), and what even is the .flatpakref file???"

I have the solution for you.

Note: I haven't studied appstream: URIs a lot so this may be (really) buggy when not using flathub

Installation

  1. Get flatline

for Firefox for Chrome

  1. Install ~/.local/share/applications/AppStreamDirectFlatpakInstall.desktop (note: modify the handler.py path later)
[Desktop Entry]
Type=Application
Name=AppStream Direct Flatpak Install
Exec=/PATH/TO/YOUR/handler.py %u
StartupNotify=false
MimeType=x-scheme-handler/appstream;
  1. Install handler.py (note: replace YOURTERMINAL - for example the new Gnome Console is kgx)
#!/usr/bin/env python3

import subprocess
from urllib.parse import urlparse
import sys

TERMINAL = ["YOURTERMINAL", "-e", "flatpak install "]

uri = sys.argv[1]
o = urlparse(uri)
if o.scheme != "appstream":
    sys.exit(1)

appid = o.path or o.netloc
TERMINAL[-1] += appid
subprocess.Popen(TERMINAL)
  1. Make the file executable (chmod +x handler.py) and replace the path in step 2

  2. Finally, set the handler for appstream: URIs

xdg-mime default ~/.local/share/applications/AppStreamDirectFlatpakInstall.desktop x-scheme-handler/appstream
  1. Test it out by going to https://flathub.org or https://beta.flathub.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment