订阅内容

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!


关于作者

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

按频道浏览

automation icon

自动化

有关技术、团队和环境 IT 自动化的最新信息

AI icon

人工智能

平台更新使客户可以在任何地方运行人工智能工作负载

open hybrid cloud icon

开放混合云

了解我们如何利用混合云构建更灵活的未来

security icon

安全防护

有关我们如何跨环境和技术减少风险的最新信息

edge icon

边缘计算

简化边缘运维的平台更新

Infrastructure icon

基础架构

全球领先企业 Linux 平台的最新动态

application development icon

应用领域

我们针对最严峻的应用挑战的解决方案

Original series icon

原创节目

关于企业技术领域的创客和领导者们有趣的故事