Built-in String Processing?

Kurt Hirchert hirchert at harriett.ncsa.uiuc.edu
Tue Oct 30 03:03:25 AEST 1990


In article <1990Oct27.215051.14085 at midway.uchicago.edu> phd_ivo at gsbacd.uchicago.edu writes:
>*************
>
>I am running a csh with enhancements on my NeXT and on an HP-9000/8xx.
>I have a macro to define my prompt to be the current directory, i.e.
>
>	alias cd                'cd \!* && set prompt="\! ${cwd}> "'
>
>Unfortunately, this gives me a rather long string, which starts with
>'/Users/u/ivo/subdir' etc. I would like to get rid of the first x characters of
>the ${cwd} variable in this macro, i.e. display only 'subdir' ( or even better,
>only if the string starts with '/Users/u/ivo' ). How would I do this?

The following is copied from my .cshrc .  On machines where I work regularly
under other directories, I include other sed substitutions.  The alias for
setprompt doesn't really need to be on three lines; it was organized this way
for purposes of inclusion in one of our local publications where really long
lines did not display well.  (Note that the quoting is set up to evaluate
hostname at the time the alias is defined, but to defer evaluation of of the
pwd/sed pipe until the alias is executed.)

# aliases for changing the prompt to include current directory
alias setprompt	'set prompt="("`pwd |'\
'sed -e "s|^$home|~|"'\
'`") "'\""`hostname` \\!% "\"
alias cd	"cd \!* ; setprompt"
alias chdir	"chdir \!* ; setprompt"
alias pushd	"pushd \!* ; setprompt"
alias popd	"popd \!* ; setprompt"
--
Kurt W. Hirchert     hirchert at ncsa.uiuc.edu
National Center for Supercomputing Applications



More information about the Comp.unix.shell mailing list