I have changed the emacs-shell mode shell to WSL ubuntu but however, the prompt is not very user-readable. For this reason I would like to execute a script that changes it so that its more readable using:


every time I enter M-x shell At the same time, I would like to keep my prompt as is outside of emacs as it has color coding etc enabled so I want the change to only affect emacs hence my question. Is it possible?


2 Answers 2


I would like to execute a script [...] every time I enter M-x shell

This is supported as standard.

Emacs sends the new shell the contents of the file ~/.emacs_SHELLNAME as input, if it exists, where SHELLNAME is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is ~/.emacs_bash. If this file is not found, Emacs tries with ~/.emacs.d/init_SHELLNAME.sh.

-- C-hig (emacs)Interactive Shell

I agree with @stsquad that testing [ "$TERM" = "dumb" ] makes good sense (as your use-case applies to any dumb terminal, not just in Emacs); but if you particularly wanted an Emacs-specific prompt, you can also do that within your normal shell config code:

When you are setting your normal fancy prompt you can test the environment variable INSIDE_EMACS. For M-x shell the value will be along the lines of 26.1,comint and the comint part tells you that you're in a dumb terminal and should set a simpler prompt.

# Set simpler prompt for M-x shell inside Emacs.
if [ "${INSIDE_EMACS%,comint}" != "$INSIDE_EMACS" ]; then

Note that other values of INSIDE_EMACS are possible in other circumstances. In M-x term (which isn't dumb) I see 26.1,term:0.96, for example.


You can test the TERM environment variable in your bashrc file. For M-x shell it will be "dumb" as opposed to anything else. For ansi-term the TERM environment variable is set to "eterm-color".

  • Thanks for the answer. My problem is that I am unable to have Term run the wsl shell even though strangely I can do it for the shell command by changing explicit-shell variable. If you have managed to do it please advise. Feb 26, 2019 at 20:12
  • 1
    @TeereraiMarange, this answer is not about any particular terminal emulator (I assume "Term" is a terminal emulator). The TERM environment variable will be available in your shell no matter which terminal you are using. e.g. echo $TERM from your shell prompt. You would test it in your shell init code, at the point where you are currently setting your fancy prompt.
    – phils
    Mar 27, 2019 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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