9

I've been playing with es the last couple of days, and it (like rc) has the quirk/feature that it only runs its startup script (.esrc) on login. The usual way to run code in each interactive session is to put that code in the %prompt function.

Of course, there's no %prompt function if es -l has never been run.

So, the question: how do you set the login environment when you come in via gdm or similar, which only source .profile (or .xprofile, .xsession, etc.)? The best I've come up with is:

if [ -f "$HOME/.esrc" ]; then
    eval "`es -l <<-x
        sh <<<'export -p'
    x`"
fi

Which seems... horrifying. Any better approaches?

5
  • I gather that es is not your login shell. What about setting alias es='es -l' in .bashrc? Commented Aug 22, 2012 at 8:39
  • es is my login shell. Sorry if I didn't make that clear. But login shells aren't run in X sessions before terminals are launched, at least as far as I know. Commented Aug 22, 2012 at 8:43
  • I use bash, not es. But when I open a new terminal window, it runs bash as a login shell. Commented Aug 22, 2012 at 9:32
  • At least with most X terminals, this is an option that is disabled by default (as it should be, IMO). So yes, it is a workaround, but there's no reason this stuff should be run multiple times when it could be run once. Commented Aug 22, 2012 at 9:34
  • Hmm, not sure I agree with your edit, Gilles. Why do you think this only applies to es? (and not *csh or rc or ...?) And why remove gdm and lightdm, since they're the ones that control the environment? Commented Aug 23, 2012 at 0:10

2 Answers 2

1

Since no one has a real answer, here's my horrible hack. Some shells (*rxvt for example) have settings that allow to force a login shell. So, in your .Xdefaults, you can add something akin to

urxvt256c-ml:loginShell: true

Which means that all urxvt256c-ml terminal you launch will have a login shell by default.

Does that help at all?

2
  • Well, being an annoying person (see comments above?), I'll say I already knew about this. It's a toss-up whether this or my slightly disturbing code is a better option; one lacks conceptual elegance (I'm claiming that I log in for every terminal, when I create 100s over a single real login?), the other lacks implementation elegance (but I really feel the environment should be set up on login). Commented Aug 23, 2012 at 10:14
  • Ah, I see what you mean now. Personally, I consider a terminal to be a the unit of login not the X11 environment so it makes sense to me to be logged in three times if I have three terminals open. I'll leave the answer here just in case it is useful for others -- let's see how many down votes is attracts. ^_~ Commented Aug 23, 2012 at 10:17
0

Answering my own question all these years later, gnome-session now appears to do some magic which extracts environment variables from the login shell and tells dbus about them, and .profile is not run:

https://gitlab.gnome.org/GNOME/gnome-session/-/blob/ef9f3039bdb48e008cd59e46aac442811bc40f09/gnome-session/gsm-util.c#L545

Unfortunately, it also refuses to export things it doesn't like, which (in 2023) includes long strings due to:

https://gitlab.gnome.org/GNOME/glib/-/issues/2824

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.