I have an alias for okular installed with flatpak that is set up like this:

alias okular="org.kde.okular"

It opens up okular from the terminal. However if I try to open a file from the terminal with that alias e.g:

okular document.pdf

Then it doesn't work. What am I doing wrong?

Is there a way to open a file in the terminal using okular flatpak, rather than using the GUI?


So I found this link:

--file-forwarding If this option is specified, the remaining arguments are scanned, and all arguments that are enclosed between a pair of '@@' arguments are interpreted as file paths, exported in the document store, and passed to the command in the form of the resulting document path. Arguments between '@@u' and '@@' are considered uris, and any file: uris are exported. The exports are non-persistent and with read and write permissions for the application.

Surely this doesn't mean the only way to open files in the terminal using okular flatpak is to do something like this:

flatpak run okular.kde.org --file-forwarding @/home/user/documents/document.pdf@

I can't do this for every pdf I want to open. How can I add this as an alias so that I dont't need to type very long commands when opening different pdfs?


Well… you already found the solution.

As for the alias, that is a standard Linux thing (i.e. not related to flatpak), so this should work:

alias okular='echo flatpak run okular.kde.org --file-forwarding'

A shell function that calls flatpak in the way that you show, and adds @ before and after the given (single) argument (untested as I don't run flatpak):

okular () {
    flatpak run okular.kde.org --file-forwarding "@$1@"

This would be put wherever you put your ordinary aliases, and you would use it as

okular /home/user/documents/document.pdf

on the command line.

To make the function take an arbitrary number of arguments, you would use something like

okular () {
    for arg do
        set -- "$@" "@$arg@"

    flatpak run okular.kde.org --file-forwarding "$@"

The loop adds @ to the beginning and end of each command line argument.

This would enable you to use it as

okular *.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.