19

I want to run a shell script ~/.local/bin/test.sh via dmenu. If I run dmenu via $mod+D and browse for the entry test.sh I couldn't find it.

The path ~/.local/bin is already set to my $PATH variable in ~/.profile

$ echo $PATH
/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

I also removed ~/.cache/dmenu_run and restart i3. What can I do to launch the test script via dmenu?

4 Answers 4

14

Delete ~/.cache/dmenu_run or ~/dmenu_cache, depending on which you have, and log back in. After your PATH is reloaded from .profile after logging in, dmenu should regenerate the cache from $PATH. dmenu seems to be bad about renewing its own cache, and needs to be forced to do it sometimes.

Also check that you have enabled the executable bit for script:

$ ls -l ~/.local/bin/test.sh
-rwxrwxrwx 1 user group 152 Jan 11 04:09 /home/user/.local/bin/test.sh
3
  • Sorry, I forgot to mention that I already removed ~/.cache/dmenu_run and restart the i3 but it doesn't affects the behavior of dmenu.
    – Hölderlin
    Jan 7, 2017 at 13:58
  • @Hölderlin It's important that you logout, and log back in to reload ~/.profile Jan 7, 2017 at 18:12
  • This may be a manjaro-only thing (it comes with a custom dmenu), but you may also have to remove the~/.cache/dmenu-recent directory. Nov 4, 2020 at 23:36
6

I post the full algorithm:

  1. Place env vars in ~/.profile or ~/.xprofile (Create if doesn't exist), not in ~/.bashrc
  2. rm -f ~/.cache/dmenu_run
  3. Log out and log in

To debug env vars type:

  1. In dmenu: echo $PATH > /tmp/path
  2. In terminal: cat /tmp/path
4

I had the same problem.

This Arch Linux forum post describes the problem:

Setting $PATH in ~/.bashrc doesn't ensure your WM/dmenu will inherit this env.
A more relevant question to ask is, "How do you login?" Usually the env exported in ~/.bash_profile or ~/.profile are available in your X applications.
Launch dmenu_run as you normally do, then in dmenu, type
echo $PATH > /tmp/path
Then in a terminal, cat /tmp/path to see what that $PATH is.

In my case, $PATH directories set in my ~/.profile weren't picked up by dmenu. My window manager is started from .xinitrc, and adding an additional export PATH=$PATH:/dir/of/interest in the .xinitrc file before the exec my_wm line fixed the problem. It is a bit clunky though.

As noted previously, I had to remove the ~/.cache/dmenu_run file and log in again after making the change to get it to work.

4
  • 2
    For some trying echo $SHELL > /tmp/shell could also be worth it. I thought mine was using bash but it turns out it used zsh so it checked different config files. Also tried putting it in xinitrc and i3 config but neither of those worked - but /etc/zprofile did! The local ~/.zshrc was not enough. /etc/profile may work as well in both zsh and bash.
    – miyalys
    Oct 6, 2019 at 22:53
  • In my case it was not xinitrc but ~/.xsession
    – Guillermo
    Sep 17, 2020 at 16:44
  • How do you work out which .xsession or .bashrc or zprofile is what's needed? I've added a lot in a similar issue and unable to work out which - unix.stackexchange.com/questions/739031/… Mar 10, 2023 at 3:22
  • @andrewjamesbowen I added a comment to your question as well, but where is your window manager being launched from? I've migrated to sway since answering this question, and sway is launched from my ~/.profile file. I update my $PATH before sway is launched
    – user208716
    Apr 12, 2023 at 2:21
2

Not the best way to fix this, but the only one that worked for me
In ~/.config/i3/config replace

bindsym $mod+d exec --no-startup-id dmenu_run

with

bindsym $mod+d exec --no-startup-id "export PATH=~/.local/bin:$PATH; dmenu_run"

After rm ~/.cache/dmenu_run && i3-msg reload binaries from ~/.local/bin accessible from dmenu

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .