2

EDIT: I just noticed that when I hit Enter on the ranger (if it is executed with terminator -e ranger) then nano opens while with e it uses my main editor. In contrast, when I use a normal shell to execute ranger and then I hit Enter, my main editor shows up. By normal, I mean if I launch firstly the terminator and then the ranger.

Why is it different?

2 Answers2

2

I saw your previous question , if you want some environment variable to be set before executing any programs , edit /etc/profile (provided you're using bash) , add everything you need. e.g export EDITOR=nano

daisy
  • 54,555
  • Thanks, I am not sure what is the problem, that is why I changed the question. Nevertheless, I have already in the ~/.bashrc file that EDITOR=subl. Should I export it? – Dimitris Leventeas Jun 01 '12 at 10:06
  • @DimitrisLeventeas yes , and you really should put this line in /etc/profile , if you insist to put this in ~/.bashrc , make sure it's the first line , depends on your bashrc , it might not be executed – daisy Jun 01 '12 at 11:57
  • /etc/profile is for all users. ~/.bashrc is the right location to change settings for a single user. – Mikel Jun 01 '12 at 14:41
  • @DimitrisLeventeas Remove the environment variable setting from .bashrc, put it in ~/.profile. – Gilles 'SO- stop being evil' Jun 02 '12 at 00:32
  • @warl0ck Why /etc/profile? Everything that reads it also reads ~/.profile. In .bashrc, it wouldn't make any difference whether it's the first line or not. – Gilles 'SO- stop being evil' Jun 02 '12 at 00:33
  • @Mikel No, ~/.bashrc is not the analog of /etc/profile. /etc/profile corresponds to ~/.profile, they are the place to define environment variables for all users and for yourself respectively. ~/.bashrc is for shell customizations. – Gilles 'SO- stop being evil' Jun 02 '12 at 00:34
  • It's a matter of taste and convention. I put things that should only happen once per login in ~/.profile, and once per shell in ~/.bashrc, but this issue is too complicated to deal with in a comment. I only wanted to point out that /etc/profile would affect all users. – Mikel Jun 02 '12 at 02:58
  • @Gilles perhaps you're strictly right, but the convention (and the default on Debian, Red Hat, etc.) is that .bash_profile sources .bashrc, thus setting environment variables in .bashrc is more flexible. For example, it allows you to set new values every time you start a new shell, which could be useful when starting a different terminal emulator, invoking su, etc. – Mikel Jun 02 '12 at 03:09
  • @Mikel .bash_profile needs to source .bashrc in interactive shells, because bash doesn't read .bashrc in login shells. Setting environment variables in .bashrc is potentially destructive: sometimes you've purposefully set other values (say, a different PATH) in your environment. Not setting your environment variables in your .profile causes, among other things, the problem that triggered this question. – Gilles 'SO- stop being evil' Jun 02 '12 at 13:36
  • @Gilles Yes, I'm aware of that. But if .profile sources .bashrc unconditionally, how can it cause this problem? (I notice in another answer you use case "$-" in *i*) . ~/.bashrc, which might be leading to our disagreement.) – Mikel Jun 02 '12 at 16:40
  • @Mikel Sourcing .bashrc from .profile is a different matter. Comments aren't the place to discuss this, though. If you want to discuss this further, please come to chat. – Gilles 'SO- stop being evil' Jun 02 '12 at 19:23
1

When you run terminator -e ranger, the terminal emulator starts the program ranger directly inside it. When you run terminator and then start ranger in the shell, the terminal emulator runs a shell which runs ranger. The main difference is that your shell's interactive initialization file is sourced (e.g. ~/.bashrc for bash, ~/.zshrc for zsh). If your shell rc file sets some environment variables, you'll get different results depending on whether a program was started through an interactive shell or not. Here, it looks like you're setting EDITOR or VISUAL in your .bashrc. If you don't, you get your system's default, which is nano.

The fix is to set environments variable where they should be set, i.e., in your session initialization file. On most setups, this is ~/.profile. Do not set environment variables in .bashrc, .zshrc or the like. See
Which setup files should be used for setting up environment variables with bash?
Difference between .bashrc and .bash_profile
Correctly setting environment

  • Why not? .bashrc, etc are equally valid IMHO. That's how I do it anyway. If you run with the defaults of many terminal emulators, .bash_profile, etc are only for things you do once per login session, e.g. start ssh-agent, run ssh-add. My point is not to claim I know the One True Way, but to observe that blanket statements saying use .profile don't acknowledge that the alternative is also fine. – Mikel Jun 02 '12 at 03:07
  • @Mikel Please read the threads I link to in my answer. Setting environment variables is one of those once-per-session things, done in .profile (or .bash_profile or .zprofile or .login). Saying that .bashrc is equally valid doesn't acknowledge the numerous problems that it causes, one of which was the very source of this question. – Gilles 'SO- stop being evil' Jun 02 '12 at 13:38
  • Oh, I see the point you're making. If your distribution's graphical login session ignores .profile and .bashrc, then putting environment variables in .bashrc can make a mismatched environment more likely. I'm coming from a different angle: I assume the graphical login session sources .profile (roughly speaking), and that .profile sources .bashrc (or similar). Neither of us has actually established that our assumptions hold in this case AFAICT. – Mikel Jun 02 '12 at 16:37