Your Environment Can Make or Break You

It's often no wonder that mere morals shudder at the site of a command prompt and scream bloody murder when asked to drop into the command line. It's a baren and unfamilar place for most people filled with all the potential pitfalls of actually getting work done! But it doesn't have to be that way.

Indeed the basic shell presented by Unix, and Windows for that matter, is pretty bleak, harsh and forboding configured with default settings. But shells and shell languages are wonderfully configureable and customizable as well as extremely powerful. Often error messages come out in command line executions that are never caught by the GUIs and displayed. And you can often get and manipulate a lot of information given the rich set of commands and piping techniques afforded by most modern shells. Nevermind you can easily set up quick loops to itterate through the information in ways that will quite frankly dazzle your friends... well your geek friends at least.

All that said this document is to describe a set of start up scripts that I've developed over the years that I find extremely useful. The environment is easily installable yet quite sophisticated at the same time.

Note: For Windows I use Cygwin as it provides a full, Linux like environment such that most stuff runs the same on Unix, FreeBSD, Solaris, Linux and Windows without change. There are additional Cygwin Tweaks to be described later that make the Windows environment further normalized and make productived.

The Package

For quite some time now I have packaged up my stuff to reside under ~/.rc. This allows me to easily grep for the occurances of things in one convienent place. I've even places my XEmacs customizations under ~/.rc too. All of this is in CVS on my corporate site and I keep things up to date and documented there. You can obtain the package as a tarball clearenv.tar.gz. Unpack the tar image and simply run ~/.rc/setup_rc:

$ cd ~ $ tar -zxf rc.tar.gz $ .rc/setup_rc $

History

Full version history can be viewed here.

I now have separated out client customizations, i.e. startup functionality particular to different clients or employers, into the ~/.rc/client_scripts directory. The start up scripts will source all executable scripts under that directory.

A set of Clearcase functions exist under ~/.rc/clearcase and a set of Multisite scripts under ~/.rc/multisite. By and large these serve to set up the Clearcase environment and mostly change common Clearcase commands from cleartool lsview to simply lsview. Where appropriate additional functionality has been added such as lsview <part of view name> which effectively does a cleartool lsview piped to grep to find views with <part of view name> in their names. An lsview by itself will do cleartool lsview piped to your $PAGER and lsviews will generate a list of views useful in constructs such as:

$ for view in $(lsviews); do > echo "Processing view $view" > # Do some thing with $view > done

Other functions are provided like cm (an alias for cleartool - stands for configuration management), cdiff (do a clearcase diff), clist (list all checkouts), etc. Note this has been named cm because I'm starting to integrate other CM systems such as CVS. So a cdiff does a cleartool diff if we are on a machine that has Clearcase whereas if we are in a diretory that has a CVS directory a cvs diff will be done instead. Similarly clist works for both CM systems too. Further development of this is ongoing.

Finally there are some environment variables that are available for handy reference such as $RGY which points to where the Clearcase registry files are, etc.

Functions

Most shell functions are defined in ~/.rc/functions. Most of these functions deal with setting it up such that the title bar of the terminal contains an indication of whether or not you are in a view or a cvs work area, what portion of the vob or directory you are currently in and whether or not you are root (called Wizard). These functions seek to maintain the proper titlebar such that if you say ssh'ed to another machine the titlebar would change - if you exit that ssh session the titlebar should change back.

Another handy function is sj - stands for Show Job. It's basically a ps -ef | grep -i <str&gr;. How many times to do you that? Why not make it shorter? There is also user and group functions which essentially do ypcat [passwd|group] | grep -i <str>. This allows you to easily search the passwd and group NIS maps (Note I have not implemented this for Windows yet but the thought would be to make it function the same).

bash_login

This whole start up environment is oriented for the bash(1) shell. It used to be ksh(1) but I've moved on to bash. As such the ~/.rc/base_login is where most stuff gets sourced and set up. It also mitigates some of the differences between the various supported OSes as well as sets up aliases, etc.

set_path

This script sets up the PATH from scratch. The idea was if your PATH ever gets hosed you can get it all back with ~/.rc/set_path. There is a list of paths to places where applications may or may not exist. These are fed into a function that appends to the PATH variable but only if the directory actually exists. So while you might see /usr/local/mysql/bin but not have mysql installed, the append_to_path function will recognize that /usr/local/mysql/bin does not exist and not append it to the path.

Cygwin Tweaks

In order to help out the start up scripts I mount the Clearcase view drive (by default M) to /view. Now /view/<viewname> is the same between Unix and Cygwin. Also I mount C:\Program Files -> /apps. Just makes more sense and is easier to type.

Clearcase Functions

General function - scm = cleartool

The scm function calls cleartool (and possibly cvs). It also gets rid of the problem with Clearcase under Windows sending extra carriage returns. If you wish to do a Clearcase cleartool command and it is not short circuted then you can use scm instead. Short circuted commands are basically cleartool command that you don't need to even specify scm for. Examples include lsview, lsstream, pwv, etc.

Note: The ct command has been aliased to the scm command.

Clearcase commands, using either the scm function of the familiar scm function, also provide full command line completion! This means that if you do scm lsview ad and then type tab, bash will complete your ad string to expand to all of the views that start with the letters "ad". In other words, bash completion for Clearcase commands means that hitting tab in scm commands will complete the command line much like file name completion currently works in bash, except it's smart in that if the context of the scm command calls for a view name here then bash completes view names. If the context of a scm command calls for a vob name then completion will complete vob names, or baselines or labels, etc. Even options are completed (type scm lsview - then tab) or even command names themselves (type scm <space> then tab twice and you'll be given a list of all Clearcase commands!

ci

The ci short circut stands for check in. This will use your ~/.clearcase_profile to specify the -nc if that is your default. So then the common action of check in goes from cleartool checkin -> ci

co

Same as ci but stands for checkout.

unco

Undo checkout

Setview

This is the regular setview command for Unix. Setview is not supported under Windows but we fake it by doing a startview then mounting /view/<viewname> to /vobs and start a new bash shell. We are attempting to emulate the setview of Unix but we can't fully because in Unix you are chrooted and /view is what is called a super root. when we exit the setview under Windows we then umount /vobs. The problem here is that we can only have one view set on the system because the /vobs mount point contains that view's name. So if terminal 1 setview view1 and terminal 2 setview view2, terminal 1 would see things as of the last mount of /vob which is view2. Further if either terminal exists the mount is unmounted and the other terminal now has no current working directory. This is a known bug and... I'm working on it!

startview

Stgarts a view then cd's the /view/<viewname>

endview

Does cm endview

killview

Does endview with -server

mkview

Short circut of cm mkview

makeview (experimental)

Attempts to create or reuse a view. It takes one parameter - the stream. The stream you say? Yes! This is UCM. It takes the stream name and attempts create a view on that stream. First it checks to see if that view has already been made and if so it does a setview. If not it attempts to make the view. If it's unsuccessful it tries to do an lsstream by first lopping off a few characters of the stream name and searching for that hoping that the stream name you provided was "close".

Note: The view tag composed will be ${USER}_$STREAM.

rmview

Short circut for cm rmview

lsview

Lists views. If no parameters are given then it does an cm lsview -short | $PAGER. This lists all viewnames and pages it. If you give it one parameter then it pipes the output to grep, grepping for that string case insensitive. If you give it more parameters it just short circuts to cm lsview <parms>.

myviews

Lists views that have $USER in them assuming they are UCM oriented and getting the headline of UCM activity set in the view, if any. Note that this is a little slow to talk to UCM to get the headlines. If you just want to see what views are yours (i.e. have your userid in their names) then do lsview $USER.

llview

One of the "ll" commands. When you see ll think "list long". This does a cm lsview -l.

lsviews

Easy way to get a list of all views (remember lsview by itself will use $PAGER). Useful for loops.

lsvob

Short circut for cm lsvob. Functions like lsview (pages, searches, etc).

llvob

Long vob listing

setcs

Short circut for cm setsc

edcs

Short circut for cm edsc

catcs

Short circut for cm catsc

pwv

Prints the current view (-short)

rmtag

Short circut for cm rmtag

mktag

Short circut for cm mktag

describe

Short circut for cm describe

vtree

Display version tree (cm lsvtree -g)

merge

Short circut for cm merge

cdiff

Performs graphical diff for Clearcase or with two non-Clearcase files or does a cvs diff if in CVS mode.

space

Short circut of cm space

register

Short circut of cm register

unregister

Short circut of cm unregister

hostinfo

Short circut of cm hostinfo

lstrig

Lists the trigger type if two parms are given (trtype and pvob) otherwise alias for cm lstype -kind trtype | $PAGER.

lltrig

Lists long the trigger type if two parms are given (trtype and pvob) otherwise alias for cm lstype -long -kind trtype | $PAGER.

lsbr

Lists lbtype's

lsstream

Lists all streams to $PAGER to alias for cm lsstream if parameters are specified.

llstream

Lists long all streams to $PAGER to alias for cm lsstream -lif parameters are specified.

rebase

Short circut for cm rebase.

deliver

Short circut for cm deliver.

lsbl

Short circut for cm lsbl.

lsproject

Lists all projects to your $PAGER or alias for cm lsproject.

llproject

Lists long all projects to your $PAGER or alias for cm lsproject -long.

lsstgloc

Lists all stglocs to your $PAGER or alias for cm lsstgloc.

llstgloc

Lists long all stglocs to your $PAGER or alias for cm lsstgloc -long.

lsstream

Lists all streams to your $PAGER or alias for cm lsstream.

llstream

Lists long all streams to your $PAGER or alias for cm lsstream -long.

lsact

Lists all activities to your $PAGER or alias for cm lsactivity.

llact

Lists long all activities to your $PAGER or alias for cm lsactivity -long.

setact

Short circut for cm setactivity

clist

Lists all currently checked out elements or locally modified cvs entries.

ciwork

Check in all checked out work.