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.
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 ... fi 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
echo $INSIDE_EMACS ⇒ 26.2,tramp:2.3.4
if [[ -z $INSIDE_EMACS ]]; then eval "$(/nix/store/ni6mmldfii7mljhnism2rn0pwchr2fmz-starship-0.40.1/bin/starship init bash)" fi