Download and install Cygwin and NT_Emacs. Cygwin provides a library that simulates the Unix system calls under NT. Many Linux programs compile without changes under Cygwin. The binaries run on any Windows machine that contains the Cygwin DLL.
To make Cygin bash or csh be your shell under Emacs, right-click on My Computer -> Properties -> Advanced -> Environment Variables, and set the following variables:
HOME = whatever you would like your home directory to be. I find it handy to make this point to the same directory as My Documents.
SHELL = location of bash.exe or tcsh.exe in your cygwin installation. Location is probably c:\cygwin\bin\bash.exe.
If you don't set HOME then your default home directory will be something like C:\cygwin\home\YOUR_LOGIN_NAME. The SHELL variable can be set in your .emacs file instead, see the example .emacs file below.
Bash users can make the Emacs shell track the working directory properly at all times by adding the following lines to the .bashrc file in your home directory:
PATH="/usr/emacs/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
USER="`id -un`"
PATH=".:$HOME/bin:$PATH"
export USER PATH
MANPATH="${MANPATH}:/usr/man"
export MANPATH
for i in /etc/profile.d/*.sh ; do
if [ -f $i ]; then
. $i
fi
done
export MAKE_MODE=unix
cd "$HOME"
OSTYPE=cygwin
export OSTYPE
# directory tracking
alias cd=cdpwd
function cdpwd {
'cd' "$1"
echo "Working directory is ||$(cygpath -wa .)||"
}
alias pushd=pushdpwd
function pushdpwd {
'pushd' "$1"
echo "Working directory is ||$(cygpath -wa .)||"
}
alias popd=popdpwd
function popdpwd {
'popd'
echo "Working directory is ||$(cygpath -wa .)||"
}
Add the following lines to the .emacs file in your home directory. Note that the setting of exec-path and PATH may vary with your installation.
(defun my-shell-setup ()
"For bash (cygwin 18) under Emacs 20"
(setq comint-scroll-show-maximum-output 'this)
(setq comint-completion-addsuffix t)
(setq comint-eol-on-send t)
(setq comint-file-name-quote-list '(?\ ?\"))
(setq w32-quote-process-args ?\")
(make-variable-buffer-local 'comint-completion-addsuffix)
(setq shell-dirstack-query "cygpath -w `dirs`")
(add-hook 'comint-output-filter-functions 'perfect-track-directory nil t)
(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m nil t)
)
(defun perfect-track-directory (text)
(if (string-match "\\w*Working directory is ||\\([^|]+\\)||" text)
(cd (substring text (match-beginning 1) (match-end 1)))))
(setq shell-mode-hook 'my-shell-setup)
(setq process-coding-system-alist (cons '("bash" . undecided-unix)
process-coding-system-alist))
(setq exec-path (cons "C:/cygwin/bin"
(cons "C:/cygwin/usr/bin" (cons "C:/cygwin/usr/local/bin" exec-path))))
(setenv "PATH" (concat "C:\\cygwin\\bin;C:\\cygwin\\usr\\bin;C:\\cygwin\\usr\\local\\bin"
(getenv "PATH")))
(setq shell-file-name "bash")
(setenv "SHELL" shell-file-name)
(setq explicit-shell-file-name shell-file-name)
(cd "~")