20

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?

Hölderlin
  • 1,160
  • 5
  • 14
  • 34

4 Answers4

15

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
Hölderlin
  • 1,160
  • 5
  • 14
  • 34
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.

ishigoya
  • 151
  • 3
  • 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 06 '19 at 22:53
  • In my case it was not `xinitrc` but `~/.xsession` – Guillermo Sep 17 '20 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 - https://unix.stackexchange.com/questions/739031/sways-dmenu-not-finding-path – andrewjamesbowen Mar 10 '23 at 03: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 – ishigoya Apr 12 '23 at 02:21
0

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