purcell / exec-path-from-shell

Make Emacs use the $PATH set up by the user's shell
Other
1.43k stars 82 forks source link

GPG_TTY gives "not a tty" #107

Closed doolio closed 2 years ago

doolio commented 2 years ago

I have the following in my ~/.profile.

export GPG_TTY=$(tty)

I understand this file is only read for login shells and no such shell is executed by my DM/DE lightdm/mate on Debian 11 (stable). I do source this file in ~/.xsessionrc so other environment variables are set correctly. But if I understand correctly that does not start a login shell either so the value of GPG_TTY remains as "not a tty". Now the GnuPG documentation suggests putting this environment variable in one's shell rc file e.g. ~/.bashrc but I've read that is bad practice. If I understand this package correctly it resolves such issues by starting a login shell.

I set exec-path-from-shell-variables to GPG_TTY overriding the default values as without this package Emacs was reading my PATH correctly. However, despite invoking exec-path-from-shell-initialize the value of GPG_TTY remains at "not a tty". I'm using bash and do not have a ~/.bash_profile or ~/.bash_login file so I'm confident ~/.profile would be sourced by a login shell.

Am I missing something or does this package simply not handle this particular environment variable?

Thanks for your time.

purcell commented 2 years ago

If you set the exec-path-from-shell-debug variable to t, then you'll get a bunch of debug output in the *Messages* buffer which will help you see what's happening. There's lots of information above and it's a bit hard for me to deduce what your config is and what's going on, sorry, but this step should help.

doolio commented 2 years ago

Thank you for getting back to me and apologies I was not clear. I've done as you've advised and the pertinent messages from *Messages* are as follows:

Invoking shell /bin/bash with args ("-l" "-i" "-c" "/usr/bin/printf '__RESULT\\000%s\\000__RESULT' \"${GPG_TTY-97f14d8c6ff1407c6344930df1d0985c}\"")
Shell execution took 39ms
Shell printed: "bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
__RESULT^@not a tty^@__RESULT"

It seems others encountered such errors when using fish as their shell - see #49 and #87. Unfortunately neither applies to me as I'm not using fish. Just to confirm: (getenv "SHELL") gives /bin/bash and I've tested this with the default Debian .bashrc and .profile with just my addition of this environment variable and GNUPGHOME (which is set correctly). I did try what you suggested in #49 and removed the "-i" from exec-path-shell-arguments but to no avail though that does remove the bash error.

Invoking shell /bin/bash with args ("-l" "-c" "/usr/bin/printf '__RESULT\\000%s\\000__RESULT' \"${GPG_TTY-71aa883134499e2284667426bfac9112}\"")
Shell execution took 4ms
Shell printed: "__RESULT^@not a tty^@__RESULT"

I hope this is able to provide sufficient information for you. If it helps on another machine where I run Parabola rather than Debian I login via a tty and this environment variable is set as expected but perhaps that is unsurprising.

Thanks for your time.

purcell commented 2 years ago

Yeah, you can see that bash doesn't get as far as printing out the requested environment variables for exec-path-from-shell to parse: something in your startup files is doing something that requires a tty, but none is present when Emacs invokes it. I can't really speculate on what that "something" might be, but you could try bisecting your startup files. Also the "no job control" output indicates that the startup files haven't really been set up with non-interactive use in mind.

doolio commented 2 years ago

I thought as much. That is why I tried with the default .profile and .bashrc provided by Debian. Thanks for your insight. I'll do as you suggest. I'll close to this now as this is not an issue with exec-path-from-shell. Thanks again and have a good day.

purcell commented 2 years ago

All good, happy tinkering!