Nicer Terminal Commands For Flatpak-Installed Applications

If you’re like me, you probably like to launch your GUI applications from the terminal at least occasionally… or from scripts… or from a quick launcher which doesn’t search .desktop names because you find it annoying to have your intent second-guessed by poor ergonomics in “multiple things match” situations.

However, as shown by the Flatpak developers closing #1188: Improve cli application experience and then locking it because real-world reports of how awkward the current situation is (eg. for invoking a Flatpak-installed copy of Meld from git merge) are apparently “abusive comments”, /var/lib/flatpak/exports/bin is the best we’ll get out of them, and I don’t like typing org.inkscape.Inkscape in the terminal.

I still think Flatpak is the best solution for a lot of other things which I don’t want to have to do myself (especially when paired with using Flatseal to lock down app permissions further), but this is ugly, it’s a usability regression, and it doesn’t even tab-complete well.

Fortunately, since I’m an end-user who doesn’t have to solve all the edge-cases, it’s easy for me to hack together a solution that works in all my use-cases.

Just…

  1. Query Flatpak for the list of installed application IDs (flatpak list --columns=ref)
  2. Run flatpak info -m on each application ID and parse out the application’s actual command name (if one exists) from the .ini-esque output (not perfect, since some app developers/maintainers will use/omit launcher wrappers when they don’t expect you to have to type the name, but it gets you 99% of the way. For example, Flatseal‘s actual binary name is com.github.tchx84.Flatseal, not flatseal, and Flatpak is a perfect way to distrust something like JDownloader that you still need to use, but its command is jd-wrapper.)
  3. Add a folder to the end of your PATH containing exec flatpak run ... "$@" scripts named after the extracted command names. (Better than using alias because you don’t have to coordinate re-source-ing the file in each open terminal for updates to apply.)

…and so, I present to you a proof of concept. It’s got shortcomings, but those are all fixable when I have time to come back to it and rewrite it in a language with a proper .ini parser:

CC BY-SA 4.0 Nicer Terminal Commands For Flatpak-Installed Applications by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.

All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.