1

I have start emacs as daemon through (emacs --daemon). I then launch the client (emacsclient -c) and use its shell mode through (M-x shell RET). However the prompt starts with:

bash-3.2$

I have changed the value of PS1 by export PS1="\w\$ " in .bash_profile. So any idea how to change the value of PS1 in the shell of emacsclient?

Edit: or an equal question is: where does emacsclient get environment variables, e.g. $PATH, $PS1 ...? Knowing this will solve my question.

2

.bash_profile is read only by login shells. Emacs will start a normal interactive shell, which reads from .bashrc.

(this isn't really an Emacs question. The bash manpage covers startup in great detail).

  • Thanks for reply! Now it works after changing .bashrc. Another problem is after opening the shell in Emacs, the path it is in (shown by "pwd") is different from where I launch the emacsclient. Do you know how to solve this issue? Thank you! – ROBOT AI Jan 26 at 2:41
  • emacsclient will start in the same directory as where emacs --daemon was invoked. Either do 'emacsclient -c .' or 'emacsclient -c <filename>' – rpluim Jan 26 at 10:39
  • Hi @rpluim, I understand it should be so. But oddly enough in my case, no matter where I launch 'emacsclient -c', the shell in emacs is always in the root directory, i.e. '/'. Do you know how to solve this issue? Thanks! – ROBOT AI Jan 27 at 15:00
0

It's a pretty Emacs-specific question IMO.

OP, you can check on the variable INSIDE_EMACS to differentiate, like this:

if [[ $INSIDE_EMACS = "" ]]; then
    export CLI_COLOR=1
    export PS1='\e[33m\u\e[m@\e[32m\h\e[m:\e[34m\w\e[m\$ '
else
    # inside Emacs. This can also go inside init_bash.sh if need be. 
    alias ls="ls -FG"
    export TERM=ansi
    # has to match the definition of dirtrack-list (in init.el)
    export PS1='\033[33m\u\033[m@\033[32m\h\033[m:\033[34m\w\033[m\$ \n==> '
fi
  • If the question had been "how can I set PS1 to be different when using M-x shell", then I'd agree with you, but it wasn't. – rpluim Jan 24 at 19:17

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.