Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Proof of concept for making Flatpak-installed GUI apps available in the terminal through their normal command names
#!/bin/sh
# Flatpak CLI Shortcut Proof of Concept
# Copyright 2021 Stephan Sokolow (deitarion/SSokolow)
#
# License: MIT
#
# Known shortcomings in this quick and dirty PoC:
# * Assumes command name collisions will never happen
# (A proper implementation would need to prompt the user to resolve conflicts
# if encountered.)
# * Just uses `grep command= | cut -d= -f2` to "parse" the INI-style output
# of `flatpak info -m`
# (A proper implementation needs to make sure it's from the right section of
# the file to ensure there's no risk of multiple lines matching.)
# * Uses the sledgehammer approach of just removing all non-folders from the
# target directory before generating new launchers to clear out stale entries.
# (A proper solution would keep track of which ones it created)
# * No means of overriding Flatseal's decision to use
# "com.github.tchx84.Flatseal" as its internal binary name rather than
# "flatseal"
# Add this to the end of your $PATH
BIN_DIR=~/.local/bin/flatpak
# Remove any stale launch scripts
rm -f "$BIN_DIR"/*
mkdir -p "$BIN_DIR"
for X in $(flatpak list --columns=ref); do
app_command="$(flatpak info -m "$X" | grep command= | cut -d= -f2)"
cmd_path="$BIN_DIR"/"$app_command"
if [ -n "$app_command" ]; then
printf '#!/bin/sh\nexec flatpak run "%s" "$@"' "$X" >"$cmd_path"
chmod +x "$cmd_path"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment