It seems INSIDE_EMACS can be used to determine if tramp is used. I know I could use test "$TERM" = "dumb" but if [[ -z $INSIDE_EMACS ]]; then is provided by the home-manager tool.

If I set tramp-verbose I can see that INSIDE_EMACS is defined in some tramp sessions but it's not when my .bashrc is processed. I wonder if INSIDE_EMACS could be set after the shell starts.

Any ideas?

GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.14, cairo version 1.16.0)

Determining a TRAMP session

Sometimes, it is needed to identify whether a shell runs under TRAMP control. The setting of environment variable TERM will help:

if test "$TERM" = "dumb"; then

Another possibility is to check the environment variable INSIDE_EMACS. Like for all subprocesses of Emacs, this is set to the

version of the parent Emacs process, See (emacs)Interactive Shell. TRAMP adds its own package version to this string, which could be used for further tests in an inferior shell. The string of that environment variable looks always like

⇒ 26.2,tramp:2.3.4



if [[ -z $INSIDE_EMACS ]]; then
  eval "$(/nix/store/ni6mmldfii7mljhnism2rn0pwchr2fmz-starship-0.40.1/bin/starship init bash)"

$INSIDE_EMACS is set when the remote shell is called explicitly. However, this is not given when your login shell is called, due to the ssh command. Therefore, if you have bash as login shell, that variable is not set yet at this time.

  • Thank you very much. – brunoqc Apr 24 '20 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.