Environmental environment

TorgoX on 2005-07-16T04:52:04

Dear Log,

So, at times, I want to make my programs do slightly different things (like having a different default debug level, for example) depending on whether they're running under crontab, or at a shell prompt, or whatever. What I do is set some env vars in my .cshrc. This is not a one-size-fits-all solution, but it works for me:

if ( $?prompt ) then
  # An interactive session of some kind
  setenv SMB_INTERACTIVE 1
  if( ! $?TERM ) then
    # running like under the winscp "terminal"
    setenv SMB_TERMINAL 0
    set history = 0
  else
    setenv SMB_TERMINAL 1
    # Normal toplevel interactive shell
  endif

  if( ! $?TERM ) then
    # We're under a nonterminal (scp, etc)
  else if( $TERM == screen ) then
    # a Screen window
    alias screen 'echo Already under screen.'
  else if($?SSH_TTY) then
    # Normal SSH stuff
  else
    # Not over SSH -- a local terminal? or telnet!?
  endif
else
  # Not an interactive session.
  setenv SMB_TERMINAL 0
  setenv SMB_INTERACTIVE 0
  set history = 0
endif

Sometimes I want a program to be able to tell when it's being run by an emacs process. For that, I just set this in my .emacs.config:

(setenv "UNDER_EMACS" "1")

Like I say, it's not guaranteed to work everywhere forever, but maybe you can use it.