Managing Flatpak applications

λ August 1, 2019
Tags: linux, shell

It’s been a while since I posted (nobody noticed I know) but I’ve been really busy learning Mercury. However, I’ve also been starting to make some video tutorials for YouTube and I installed kdenlive with Flatpak and soon got irritated with the command line support!

So I decided to fix it with a shell script. Like you do.

I use Flatpak for some things as I just like to be able to download and install and know it is going to work out of the box. However, I find the output of the list command to be overly verbose and also it irritates me that I have to type the full name to run an application even though there is only ever going to be one installed with that name.

To that end, I came up with two absolutely tiny but useful shell scripts that I place into my ~/bin file and now life is that much easier!

Listing Installed applications

I saved this in ~/bin/fpl …if you should already have a script or application with the name then just call it something else!

flatpak list --app | cut -f 1 | cut -f1 -d / | nl

First it runs the flatpak list command which produces something like this, it shows applications and libraries which I don’t really care about when I am looking for a program to run:

io.github.OpenToonz/x86_64/stable                   system,current
org.kde.kdenlive/x86_64/stable                      system,current
org.kde.krita/x86_64/stable                         system,current

Then we pass each result through cut -f 1 which defaults to using the space character as the field separator and then outputs the first field, giving us this:


Finally we need to obtain just the actual application name minus the architecture and release, so again we pipe the output through another cut, this time using the / as the field separator and again keeping just the first field, giving:


The final step is to number the lines so that the sister script fpr can do the same steps but know which application name to extract and run, using nl gives us this:

1	io.github.OpenToonz
2	org.kde.kdenlive
3	org.kde.krita

Having run fpl it’s now a simple matter of passing the number to fpr, here is the script for ~/bin/fpr:

APPNAME=`flatpak list --app | cut -f 1 | cut -f1 -d / | head -$1 | tail -1`
flatpak run $APPNAME

Sure I could have done it as a one liner but, readability!

$ fpl
1	io.github.OpenToonz
2	org.kde.kdenlive
3	org.kde.krita

$ fpr 3

So there you go, now when I run it on my machine it looks like this and works just fine!