Go to: LING2050 home page   Lab pages index   Command reference sheet

How to Configure Your Terminal Environment: Cygwin/X

Cygwin terminal vs. xterm (X terminal window)

  1. We started out by using the cygwin terminal:
    It is perfectly functional. You can even customize its looks, including its font and color scheme (right-click on the cygwin icon, select 'Properties').

  2. Cygwin/X provides a second kind of terminal, however, called 'xterm'. The 'X' part of Cygwin/X refers to this. Cygwin's xterm looks like:
    To launch xterms, you first need to have something called X-Window server running. The shortcut for this program is located in your Windows Start menu: Start > All Programs > Cygwin-X > XWin Server. Click on 'XWin Server': it places an 'X' icon in your task bar, and then launches an xterm window.

  3. Once you have an xterm window, you can configure its looks from the top menu bar ('VT Options, VT Fonts').

  4. Once you have an xterm window, you can launch additional xterm windows by issuing the following command:
    xterm &
    Why &, you ask? Try the command without it, and you will see. :-)

  5. The X-Window system and xterm offer two advantages over cygwin terminals:
    • The ability to launch additional X-Window applications such as xterm and emacs (a text editor) right from your commandline prompt. (With some further configuration, you can even launch any Windows-OS applications as well.)
    • Easy copy and paste. Whatever text you highlight with your mouse within an X-Window terminal gets automatically copied. (No need to press Ctrl-C)! To paste it into another X-Window terminal, you can click your middle mouse button (if you have one); to paste it into a regular Windows-OS window (such as MS Word, MS WordPad or your FireFox browser), you can use Ctrl-V.


Missing .bashrc file? You can copy it over.

  1. Due to some strange glitch, cygwin installation sometimes fails to create a few essential user files. You can verify if this is the case by typing the following command immediately after logging in:
    ls -la
    You should be seeing a result similar to this screen. In particular, these are the three files you will need:
    .bash_profile
    .bashrc
    .inputrc
    You might not have .bash_history yet, but it will soon get automatically created.

  2. What happened was that your setup failed to copy these files over. The original copies are kept in your C:\cygwin\etc\skel\ directory. What you need to do is copy these files over to your home directory. There are two ways:

    • If you are not yet comfortable around unix commands, you can simply use the good-old MS-Windows file copy method. Your cygwin home directory is likely located in C:\cygwin\home\your_user_name.
    • Alternatively, you can copy the files over within cygwin terminal using the cp command. This is the command to use (pay attention to the period!):
      cp /etc/skel/.* ~
    After the file copy operation, you can confirm its success by typing:
    ls -la ~


Defining your own shortcuts in .bashrc

  1. .bashrc lives in your home directory, and it determines the behavior of your command-line environment. This file can be modified to better suit your computing routines and habits. For example, to always display your grep results in color without having to type in --color switch, open the .bashrc file in a text processor (MS Wordpad works) and add this line:
    alias grep='grep --color'
    save and close, and then execute source .bashrc for the change to take immediate effect (or you can log out and log back in). Thanks to this alias definition, you can now simply type grep and get color-coded results.

  2. Here is another alias that is convenient to have in your .bashrc file:
    alias ls='ls -hF --color=tty'
    It might already be included in your file but commented out with the "#" line prefix; if this is the case, simply edit out the "#" symbol. Do not forget to source .bashrc!

  3. You probably noticed that your xterm window lacks a side bar. To enable this automatically, you can include this line in the file. (Note: It only affects additional xterm windows you launch with xterm &.)
    alias xterm='xterm -sb -leftbar'

  4. Editing your user definition files such as .bashrc is a risky business. If the file is messed up somehow, you might find yourself unable to log in. In such cases, you can replace your .bashrc file in your home directory with the original copy of the file within the MS-Windows environment. Navigate into your home directory, delete the file, and follow the instructions above.


Setting your locale

  1. Locale is a set of parameters that defines the user's language, character encoding, region and other special variant preferences. In Cygwin's current 1.7 release, the default locale is set to C.UTF-8, which roughly means "no particular language, UTF-8 (unicode) encoding". You can verify this by typing:
    $ echo $LC_ALL
    C.UTF-8

  2. Yes, unicode is the present (almost) and future (most definitely) standard of character encoding, but it is not yet perfectly integrated into all aspects of computing. For the purpose of this class, in order for our various unix commands to work flawlessly, we will need to fall back to the more venerable encoding standard: ISO-8859-1.

  3. So how to set locale? You again edit the .bashrc file in your home directory and place this line (preferrably towards the beginning):
    export LC_ALL=en_US.ISO-8859-1
    This sets your locale as en_US.ISO-8859-1: US English in ISO-8859-1 encoding.

  4. Now either execute source .bashrc or log out and log back in. Type echo $LC_ALL to verify that your locale has been successfully changed. As always, if something goes wrong with the file and you find yourself unable to log in, you should replace the .bashrc by following the instructions above.