Cygwin Config - Bash, Emacs, Smit
I spent a little time a few weeks ago configuring Cygwin into a usable environment for both AIX administration and storage administration. The stimulus for this was a lack of command line history for symcli commands. Our primary Solutions Enabler system at work is a Windows 2003 Server install that happens to have SSHD installed. I haven’t had luck getting the arrow keys working for previous commands via putty, so I figured I’d try getting shell mode for emacs working and use the emacs history functions.
That didn’t work either… for some reason, the enter key refused to work after a ssh session was established through emacs shell mode… though normal SSH connections worked fine. I still haven’t resolved that (and I’m not sure I’ll even bother further), but the configuration I ended up with works much better than my previous setup (plain putty). Since it was fairly tricky to get the system working end-to-end, I figured I’d type it up in case other people were having similar issues. The final result works as good as plain Putty for general SSH functions (except for a wrapping issue), allows for the use of SMIT menus in AIX, and looks much better than the default Cygwin shell. The main issue that I continue to have has to do with long command lines… quite simply, the command starts "wrapping" onto itself and becomes a pain to modify.
First of all, download the Cygwin installer and install any desired components. I made sure to install the current version of emacs, emacs-el, ssh, and ncurses. If you want to be able to use ‘clear’ from bash, ncurses is required. I installed cygwin to c:\utils\cygwin.
Secondly, I modified the /etc/profile to move my home directory away from the system default. To do this, add:
HOME=”/home/techmute”
export HOME
to the line in /etc/profile right before the line “# Here is how HOME is set, in order of priority, when starting from Windows”.
By changing the default home directory, it allows me to more easily transfer configurations from work to home where the usernames and profile locations don’t match. After making that change, close out of Cygwin and relaunch it to seed the home directory with the default configuration files.
At the end of the .bashrc file, add the following text:
case $TERM in
xterm)
PS1=
PS2=”> “
PS4=”+”
PROMPT_COMMAND=’
pcpwd=${PWD/$HOME/\~}
[[ "${#pcpwd}" -gt 25 ]] && pcpwd=”..${pcpwd: -25}”
echo -ne “\033]0;${USER}@${HOSTNAME} ${PWD/$HOME/~}\007″
green=”\033[32m”; orange=”\033[33m”; cyan=”\033[36m”; off=”\033[m”;
PS1=”$green\u$orange@$green\h $cyan${pcpwd}$orange \$ $off”
‘
;;
dumb)
PS1=”\u@\h \w \$ “
PS2=”> “
PS4=”+”
PROMPT_COMMAND=
;;
esac
This configures the command prompt to look differently based off of whether it is a native bash shell or a bash shell spawned from emacs. It prevents “ascii garbage” from showing up when you spawn a shell from emacs. PLEASE NOTE: I’m using the hacked version of putty as my terminal for this, so if you’re using the “default” Cygwin shortcut, it won’t work quite right. Also, I borrowed this from somewhere online… if anyone knows the proper attribution, let me know.
Ngai Kim Hoong has an excellent site on configuring emacs for use with Cygwin. Follow this link and add the portions you’re interested in to your .emacs file. I would definitely include the shell configuration to launch bash instead of sh from emacs.
After this, the majority of the Cygwin configuration is complete. The final steps replace the default Cygwin shell with something that doesn’t suck. First of all, go to Google Code and download puttycyg. This will allow you to run a modified version of putty as a cygwin terminal. Secondly, go to this site and download the igvita desert theme. It is packaged as a registry file containing putty customizations. You’ll likely want to customize it further to suit your needs (I had to modify the columns and rows).
The end result doesn’t looks a ton better than the default Cygwin, but the wrapping issues still bother me daily when using piped commands.