2

I want to create a key binding for the common task: open a new terminal window and open the program ranger in it.

The obvious command would be something like that:

urxvt -e ranger

The important things work right out of the box. But in ranger I want to use a different program called fzf, and this program is not found. The error message zsh:1: command not found: fzf.

Same result with

urxvt -e zsh -c ranger

When I already have an opened terminal and call ranger in it, then fzf can be called without any problems.

I took a look, and the path to the binary of fzf gets added to $PATH in my .zshrc. So my assumption is that this never sources my .zshrc, and it never gets added to the path.


There is an obvious fix for this (call fzf inside ranger using the full path ~/.fzf/bin/fzf), but this problem annoyed me quite a few times already, and I want a nice solution.

How can I open a new terminal, that sources .zshrc and opens the program ranger?


One more observation that I don't understand:

I created a script myranger.sh:

#!/usr/bin/zsh
source ~/.zshrc
ranger

and created the new terminal with:

urxvt -e myranger.sh

The terminal with ranger opens, but fzf is still not in $PATH. What did I miss here?


Btw, this is not zsh or urxvt specific. I also tested this with bash and/or gnome-terminal.

0

2 Answers 2

7

urxvt -e zsh -c ranger is pretty much equivalent to urxvt -e ranger. You're telling urxvt to run zsh, and zsh to run ranger, and that's it. urxvt -e zsh -c ranger does not load .zshrc: zsh only loads it when starting an interactive shell, i.e. a shell that reads user commands, not when starting a shell that runs a script (whether this script is in a file, or passed on the command line with -c).

You can load .zshrc explicitly (urxvt -e zsh -c '. ~/.zshrc; ranger', or use a wrapper script as you did). This isn't a good idea though, because .zshrc is for interactive settings of zsh — key bindings, aliases, etc. Environment variable settings (e.g. PATH) apply to all programs, so they should be done at login time, usually in ~/.profile. Move your PATH setting from .zshrc to .profile where it belongs.

1

Quoting zsh manual:

INVOCATION

-i Force shell to be interactive.

and later

If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile. Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

...

If ZDOTDIR is unset, HOME is used instead.


So, to force sourcing .zshrc at start run

urxvt -e zsh -ci ranger
2
  • Shouldn't that be -ic? Otherwise, wouldn't the command be i ranger? Commented Dec 29, 2017 at 0:55
  • @SolomonUcko doesn't matter, will work both ways.
    – jimmij
    Commented Dec 29, 2017 at 10:27

You must log in to answer this question.

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