The ^[]
noise is coming from various terminal control characters in your shell prompt. Try echo $PS1
to see the full sequence, and try e.g. export PS1='$ '
to see that a simpler prompt string removes that particular problem.
For the encoding, you might try making utf-8 your preferred encoding:
(prefer-coding-system 'utf-8)
Setting up the prompt
Emacs sets the INSIDE_EMACS variable so you could create a .bash_profile that sets PS1 only when running in Emacs.
Testing on my machine, the first line of the prompt has the problematic control characters. I created a ~/.bash_profile with this.
if [ -n "$INSIDE_EMACS" ]; then
export PS1='\[\033[32m\]\u@\h \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '
fi
This sets the prompt based on what git-bash was setting by default, but I removed the first line (up to the \n line break). I also removed the $MSYSTEM which puts MINGW64 in the prompt -- I don't need to see that. What remains is the user@host, current directory, and git repo. The control characters set colors which Emacs displays properly for me. (For details on setting up your prompt, refer to the bash manual.)
In Emacs I set the shell to git-bash:
(setq explicit-shell-file-name "C:/git-for-windows/bin/bash.exe")
(setq explicit-bash.exe-args '("--login" "-i"))
With this setup I'm still seeing the initial ioctl error message, but otherwise things work as expected and the encoding is utf-8.