Search code examples
bashshellzshmc

Determine if bash/zsh/etc. is running under Midnight Commander


Simple question. I'd like to know how to tell whether the current shell is running as a mc subshell or not. If it is, I'd like to enter a degraded mode without some features mc can't handle.

In particular, I'd like this to

  • Be as portable as possible
  • Not rely on anything outside the shell and basic universal external commands.

Solution

  • Though it's not documented in the man page, a quick experiment shows that mc sets two environment variables: $MC_TMPDIR and $MC_SID. (It also sets $HISTCONTROL, but that's not specific to mc; it affects the behavior of bash, and could have been set by something other than mc.)

    If you don't want to depend on undocumented features, you can always set an environment variable yourself. For example, in bash:

    mc() { MC_IS_RUNNING=1 command mc "$@" ; }
    

    Entering a "degraded mode" is another matter; I'm not sure how you'd do that. I don't know of any way in bash to disable specified features. You could disable selected built-in commands by defining functions that override them. What features do you have in mind?