I need to have a terminal or my productivity diminishes to the point where I verge on having a mental breakdown, and unfortunately I have to use a windows laptop for work. So I have become very accustomed at working with cygwin and all its little nuances and here are my steps/tips for installing and integrating cygwin with windows.
Move your “My Documents” directory.
Windows likes using “My Documents” as the default location to store everything. And this is typically located at C:\Documents and Settings\__username__\My Documents. And in cygwin your home directory will be something like C:\cygwin\home\__username__. Personally that is one too many places for me to remember, so, I consolidated them into a location located at C:\dev for 2 reasons:
- cygwin doesn’t like spaces in its path, so this path will not have any
- If i choose to remove C:\cygwin, I can without blowing away my important documents
This is pretty simple to do, just use windows explorer and browse to your C:\ drive, then create a new folder named “dev”. Then, if you want, copy all your C:\Documents and Settings\__username__\My Documents files into C:\dev. If you don’t, none of your existing documents will be in the “My Documents” location.
Next using windows explorer browse to your old “My Documents” folder and right click on the folder, select properties. This will open a window with 4 tabs, select the Target tab and change the Target folder to C:\dev and hit the ‘OK’ button to close the window.
We’ll fix the cygwin home directory problem later, so go ahead and install cygwin.
Install cygwin
There are million places on the internet that document how to install and configure cygwin, so I am not going to do that here. But I am assuming you use the default cygwin install location of C:\cygwin and you install X Server and X11 Libraries. If you don’t know where to start, visit http://www.cygwin.com, click the Install or Update now icon and follow the installation instructions.
Mount the C:\ drive
After installation there will be a file named Cygwin.bat located at c:\cygwin\Cygwin.bat, double click the file to start a cygwin terminal.
You can access the C:\ drive in cygwin by going to /cygwin/c, but that is too many characters for me to type and would rather I just type ‘cd /c’ and get there. So you can mount the C:\ drive at /c.
-
> cd /
-
> mkdir c
-
> mount c: /c
-
> cd /c
-
> ls
Configuring your cygwin user
Once you have your c drive mounted you can set up your user account properly. To do this you will need to edit the /etc/passwd file and create a link to the /c/dev (C:\dev) directory you created earlier.
-
> vi /etc/passwd
-
-
# find your user name and change the home directory location to /home/__username__
-
# and save the file.
-
__username__:unused_by_nt/2000/xp:69999:10545:Your Name:/home/__username__:/bin/bash
If your home directory already exists make a back up of it.
-
> cd /home
-
> mv __username__ __username__.old
Finally, create a softlink from /home/__username__ to /c/dev
-
> cd /home
-
> ln -s /c/dev __username__
And I like having quick access to my desktop, so, while you are here create a softlink to your desktop, so that you can there with ‘cd ~/desktop’.
-
> cd /home/__username__
-
> ln -s /c/Documents\ and\ Settings/__username__/Desktop desktop
Configuring X11 and Xterms
Cygwin uses command windows for terminals and I much prefer using xterm and furthermore I want to double click an icon in my taskbar or on my desktop to start the xterm. Luckily if you installed the X11 libraries, cygwin provides a script that does most of that for us. It is located at /usr/X11R6/bin/startxwin.bat.
The only problem is that we need to have the X server running before starting an xterm. So lets create a script that does that. I put mine in /c/dev/bin/mystartx.sh:
-
#!/usr/bin/bash
-
-
if [ `ps -W | grep -i xwin | wc -l` -eq 0 ]; then
-
run /usr/X11R6/bin/Xwin -clipboard -emulate3buttons -multiwindow -silent-dup-error
-
fi
-
-
run xterm -sl 9999 -sb -rightbar -bg black -fg white -cr yellow -ms red
Next we need to execute this script, and to do that we can simply call it from the startxwin.bat script mentioned earlier.
-
> cp /usr/X11R6/bin/startxwin.bat /c/dev/bin/startxwin.bat
-
> vi /c/dev/bin/startxwin.bat
Then comment out the line that says:
-
%RUN% XWin -multiwindow -clipboard -silent-dup-error -emulate3buttons
And add the call the mystartx.sh right below it:
-
bash -c '/c/dev/bin/mystartx.sh'
Next we can add the C:\dev\bin\startxwin.bat to our task bar and add a fancy icon like the X11 one for %SystemDrive%\cygwin\usr\X11R6\bin\XWin.exe. Now if everything worked you should be able to click the new icon and start X server if needed and an xterm each time.
To recap, we now have:
- the main home directory for both windows and cygwin in the same place
- the C:\ drive available at /c
- An icon that will start a xterm, and x server if needed
Now I only need ssh and apache, but that’s a topic for another post.
