Skip to content

Instantly share code, notes, and snippets.

@curioswati
Last active April 22, 2025 08:27
Show Gist options
  • Save curioswati/668e9e120ddd4b6f8d07dc28b5780d22 to your computer and use it in GitHub Desktop.
Save curioswati/668e9e120ddd4b6f8d07dc28b5780d22 to your computer and use it in GitHub Desktop.
To run flatpak installed apps from dmenu.

To run a flatpak app from dmenu, you can create a symlink for the app in /usr/bin. You can find the flatpak apps binary link in /var/lib/flatpak/exports/bin/ on ubuntu. E.g. to run Rocket Chat (installed from flatpak via software center), you can do something like this:

sudo ln -s /var/lib/flatpak/exports/bin/chat.rocket.RocketChat /usr/bin/rocket-chat

This way you will be able to find it in the dmenu.

Resources:

@fislysandi
Copy link

fislysandi commented Dec 7, 2022

hey i did it the other way so the app is named like this FirefoxFlatpak
i just had to change some things and i didnt need cut command

@kliarist
Copy link

Nice one thanks

@fislysandi
Copy link

fislysandi commented Jan 18, 2023

hey does anybody does know how to convert a variable into lowercase? i just need only this and i can post an improved version of flat-bin

the apps will be named like this lowercase(*)flatpak

@alissonzuza
Copy link

alissonzuza commented Feb 13, 2023

In fedora I made this configuration below and when running dmenu it now correctly picks up the bins of the flatpaks
I use i3wm

1.To edit
vi /usr/bin/dmenu_run

  1. Add line export

#!/usr/bin/sh
export PATH=$PATH:/var/lib/flatpak/exports/bin
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &

Here it worked correctly

When in doubt, do a search where the dmenu_run file is
sudo find / -iname "dmenu_run"

@A350
Copy link

A350 commented Aug 17, 2023

Gracias !!!!

@OnePieceJoker
Copy link

Thanks

@revsuine
Copy link

Lifesaver!

@mlaiseca3
Copy link

I found the path to be as follows:
For system installations, the directory is located at /var/lib/flatpak/exports/bin. For user installations, it’s located at ~/.local/share/flatpak/exports/bin.

thus, my dmenu_run file looked like the following (simlar to alissonzuza's)

#!/usr/bin/sh
export PATH=$PATH:~/.local/share/flatpak/exports/bin
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &

for context im using dwm and not i3

@alissonzuza
Copy link

Achei o caminho o seguinte: Para instalações do sistema, o diretório está localizado em /var/lib/flatpak/exports/bin. Para instalações do usuário, ele está localizado em ~/.local/share/flatpak/exports/bin.

assim, o meu dmenu_run arquivo ficou com o seguinte (simlar para alissonzuza)

#!/usr/bin/sh
export PATH=$PATH:~/.local/share/flatpak/exports/bin
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &

para IM de contexto usando DWM e não i3

I believe that to be perfect it could be EXPORT like below
Considering system and user
export PATH=$PATH:/var/lib/flatpak/exports/bin:~/.local/share/flatpak/exports/bin

@flavioipiranga
Copy link

Thank you!

@mondskiez
Copy link

mondskiez commented Oct 9, 2024

The best approach I found was using i3-dmenu-desktop.

1. Search for then change the `dmenu_run` in the i3config or if you have the default config you'll see alternatives slightly below the default line for `dmenu_run`.

2. Adjust accordingly using `rofi` or `i3-dmenu-desktop` by commenting/uncommenting.

Both rofi and i3-dmenu-deskotp ran on my system to display flatpaks without any other changes to the system.

This is the best answer so far.. nothing to do but to add a binding in the config

bindsym $mod+Shift+d exec --no-startup-id i3-dmenu-desktop

then reload config.. then execute the binding and i3-dmenu-desktop give you list of apps that can run in the desktop, INCLUDING the flatpaks..

@PasqualePerilli
Copy link

I have tried using what @alissonzuza and @mlaiseca3 have suggested, and while it works, you have to type in the full name of the application instead of the short name.
For example, if you want to open the flatpak of DBeaver, you have to type in io., which will then make the io.DBeaver.DBeaverCommunity option appear.
If you were to type in DBeaver, it would not appear.

Because I did not like this behavior, I modified my dmenu_run file to be as follows:

#!/bin/zsh

export linkFlatpakFolder="$HOME/.config/flatpak-shortcuts"
export PATH=$PATH:$linkFlatpakFolder
local systemFlatpakFolder="/var/lib/flatpak/exports/bin"
local userFlatpakFolder="$HOME/.local/share/flatpak/exports/bin"


local systemFlatpaks=$(ls -1 -a "$systemFlatpakFolder" 2>/dev/null | grep -v '^\.$' | grep -v '^\.\.$')
local userFlatpaks=$(ls -1 -a "$userFlatpakFolder" 2>/dev/null | grep -v '^\.$' | grep -v '^\.\.$')
# 1 line per flatpak. If any of the two directories does not exist, the variable will be empty


#Let's create syslinks to the flatpak binaries without including the full name
#NOTE: We need to ensure that there are no entries with the same name

rm -rf "$linkFlatpakFolder" 2>/dev/null

mkdir -p "$linkFlatpakFolder"


for (( i=1; i<=$(echo "$systemFlatpaks" | wc -l); i++ )); do
  local currentFlatpak=$(echo "$systemFlatpaks" | head -n $i | tail -n 1) #This is going to contain the full name
  local currentShortName=$(echo "$currentFlatpak" | awk -F. '{print $NF}') #The application name is always last.
  local currentShortName=$(echo "${(L)currentShortName}") #Make first letter of the name lower-case. (Use C instead of L for upper case)
  local fullPathToShortcut="${linkFlatpakFolder}/${currentShortName}"
  local duplicateIndex=1
  while [ -f "$fullPathToShortcut" ]; do #If the shortcut already exists, then add a suffix
    fullPathToShortcut="${fullPathToShortcut}-${duplicateIndex}"
	duplicateIndex=$(( 1 + $duplicateIndex ))
  done
  #Now create the symbolic link
  ln -s "${systemFlatpakFolder}/${currentFlatpak}" "${fullPathToShortcut}"
done

for (( i=1; i<=$(echo "$userFlatpaks" | wc -l); i++ )); do
  local currentFlatpak=$(echo "$userFlatpaks" | head -n $i | tail -n 1) #This is going to contain the full name
  local currentShortName=$(echo "$currentFlatpak" | awk -F. '{print $NF}') #The application name is always last.
  local currentShortName=$(echo "${(L)currentShortName}") #Make first letter of the name lower-case. (Use C instead of L for upper case)
  local fullPathToShortcut="${linkFlatpakFolder}/${currentShortName}"
  local duplicateIndex=1
  while [ -f "$fullPathToShortcut" ]; do #If the shortcut already exists, then add a suffix
    fullPathToShortcut="${fullPathToShortcut}-${duplicateIndex}"
	duplicateIndex=$(( 1 + $duplicateIndex ))
  done
  #Now create the symbolic link
  ln -s "${systemFlatpakFolder}/${currentFlatpak}" "${fullPathToShortcut}"
done

dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &

Then, back in the terminal, I executed the following

rm "$HOME/.cache/dmenu_run" && cd "$HOME/programs/suckless/dmenu" && sudo make clean install 

And boom, it worked.

What the script does is that it creates symbolic links to the real flatpaks. The symbolic links do not carry the entire fully qualified name, but rather just the short name.

This way, I can just type DBeaver, and it will appear listed.

A solution that while not as short and elegant as the two above, works very well for me.

After you install a new flatpak, the link containing the symbolic links will be recreated, so you will always have all the flatpaks listed in dmenu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment