Well, it’s a bit silly, but I got nerd-sniped by how it was taking a little over six seconds to regenerate my Flatpak CLI wrappers with the shell script version I just announced yesterday, so I rewrote it in Python.
(Still the same GitHub Gist URL)
The new version completes basically instantly after the split-second pause to start the Python interpreter, thanks to using PyGObject to go straight to
libflatpak so it doesn’t have to launch a whole new copy of
flatpak info to query each package.
Other enhancements the rewrite brought are:
- Flatpak info parsing is now done using
Glib.KeyFile, which is a proper parser for the format
- Command lines are now extracted from the
Gio.DesktopAppInfo, but with a forced fallback to the old
flatpak rungenerator if the upstream devs omitted
--file-forwardingto ensure that things like ScummVM don’t regress in their ability to invoke them with command-line arguments.
EXTRA_CMDSnow takes a list of commands, so you can expose more than one secondary command from each package.
CMD_REMAPPINGSNow maps from flatpak package IDs rather than internal command names so that there’s no risk of collisions if the undesired name is undesired because it’s something generic like
- The template for wrapper scripts is now using a proper multi-line string for easy auditing and editing.
- The script checks if
BIN_DIRis in your path and, if not, warns you that you’ll need to add it, which has the side benefit of telling you what
BIN_DIRis set to without needing to read the source.
- There’s now basic collision resolution where the first Flatpak package to claim a name wins and a message is printed asking you to add an entry to
CMD_REMAPPINGSto resolve the problem.
- There’s now collision detection where, whether or not this script is responsible for both of them, a warning will be printed indicating which command from which package is colliding and whether your PATH will favour the Flatpak version or the external version.
Yeah, aside from the lack of manpages (which I can’t solve if they’re just not in the package), the sledgehammer-y approach of just expecting that it’s allowed full freedom to blow away all files inside the
BIN_DIR it creates and manages, and the fact that you have to edit constants in the source code rather than an external config file, this is now about as perfect as I can think to make it… maybe I’ll rewrite it in Rust next time the mood hits me.
UPDATE: I’ll also need to add autodetection for when a Flatpak is exporting secondary launchers so
EXTRA_CMDS is only necessary for things like
mednafen that are present but not exported.