Iscriviti al feed

I support various multimedia applications, and earlier this year, I started recommending that my clients install many of them as Flatpaks. I did this mostly because the Flatpak releases of these applications were quicker at integrating support for media codecs than the packages available elsewhere, and that's an essential feature for content creators using the latest gear on set. The results have been uniformly successful, but for one snag: Launching a Flatpak from the terminal isn't always the easiest thing to do.

The issue is well documented, but in short, a Flatpak application's formal name is essentially a reverse domain name. However, there's no standard for details like capitalization or naming schemes. That can make it difficult to remember, and the command itself isn't exactly terse:

$ flatpak run io.atom.Atom

A name like io.atom.Atom is relatively easy to remember (though not as easy as just atom), but then there are names like org.gimp.GIMP (easy to understand, but what gets capitalized and what doesn't?) or org.eclipse.Java or fr.handbrake.ghb. There's endless variety for very pragmatic reasons, but it's hard to commit them to memory as part of a command.

Bash scripting is a unique power that Linux provides its users, though, and it's with that power that I came up with a simple workaround to help my users easily launch a Flatpak from a terminal.

Meet Fuzzpak

This is actually a workaround for a workaround. I've already written a solution for Flatpak launching, which I call pakrat. It takes its inspiration from the alternative command and implements Bash aliases for installing Flatpaks. However, it's a manual process, and I assumed at the time that the sysadmin would install the Flatpaks, create Bash aliases, and the users would never know the difference.

That was back before I fully appreciated the flexibility of Flatpak, especially since users could install Flatpaks to their own home directory. Allowing users to install their own applications is nice, but it seems strange to a user that they can't then launch the application they've installed from a terminal. My pakrat solution would work for them, but it's an added step that many didn't seem to relish doing.

And so I wrote Fuzzpak, a script that does a "fuzzy" search on user-installed Flatpaks and launches the first one it finds containing the string provided. For example, to launch GIMP:

$ fuzzpak gimp

Ideally, you want to give Fuzzpak the proper application name you want to launch. For instance, to launch the video editor Kdenlive, you use fuzzpak kdenlive rather than, say, fuzzpak kde because the string kde appears in all KDE apps, such as org.kde.digikam, org.kde.krita, org.kde.kblocks, and so on. The same goes for GNOME projects or projects referencing GitLab or GitHub.

Set the Flatpak directory

By default, Fuzzpak looks at the user's home directory (~/.var/app) for installed Flatpaks. You can use the --directory option (-d for short) to set an alternate location:

$ fuzzpak --directory /var/lib/flatpak/app krita

Examine the Fuzzpak script

The script is simple:

#!/usr/bin/env bash
#GPLv3

DIR=${DIR:-$HOME/.var/app}
CMD=${CMD:-flatpak run}

launch_app() {
    find "${DIR}" -mindepth 1 -maxdepth 1 \
     -type d -iname "*$1*" -printf '%f\n' \
    | xargs $CMD
}

# parse opts
while [ True ]; do
if [ "$1" = "--help" -o "$1" = "-h" ]; then
    echo " "
    echo "$0 [OPTIONS]"
    echo "--directory, -d   Location of flatpaks (default: $HOME/.var/app"
    echo " "
    exit
elif [ "$1" = "--directory" -o "$1" = "-d" ]; then
    DIR=$DIR
    shift 2
else
    break
fi
done

# main
launch_app "${1}"

It's actually just a single find command that looks through the target directory for a matching string pattern and then launches the first one that it finds. The rest of the script just sets the location of the Flatpaks and parses options.

It's not sophisticated, and I can certainly imagine a Python or Go solution that finds all potential matches and gives weight to the final position in the Flatpak name when choosing what to launch. However, I've found that it's effective, and I've been using it happily for about three months without incident.

Install Fuzzpak

If you want to install the script locally:

  1. Copy and paste the script into a file called fuzzpak (or whatever you want the command to be).
  2. Save the file into ~/.local/bin. (That's a hidden directory, so show hidden files in your file manager, or save it using the terminal.)
  3. Make the script executable:
    $ chmod +x ~/.local/bin/fuzzpak

Otherwise, you can just place fuzzpak somewhere on your user's path. Now you're ready to install Flatpaks with Fuzzpak. Enjoy!


Sull'autore

Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

Ricerca per canale

automation icon

Automazione

Novità sull'automazione IT di tecnologie, team e ambienti

AI icon

Intelligenza artificiale

Aggiornamenti sulle piattaforme che consentono alle aziende di eseguire carichi di lavoro IA ovunque

open hybrid cloud icon

Hybrid cloud open source

Scopri come affrontare il futuro in modo più agile grazie al cloud ibrido

security icon

Sicurezza

Le ultime novità sulle nostre soluzioni per ridurre i rischi nelle tecnologie e negli ambienti

edge icon

Edge computing

Aggiornamenti sulle piattaforme che semplificano l'operatività edge

Infrastructure icon

Infrastruttura

Le ultime novità sulla piattaforma Linux aziendale leader a livello mondiale

application development icon

Applicazioni

Approfondimenti sulle nostre soluzioni alle sfide applicative più difficili

Original series icon

Serie originali

Raccontiamo le interessanti storie di leader e creatori di tecnologie pensate per le aziende