gwr@linus.UUCP (Gordon W. Ross) (07/06/88)
Posting-number: Volume 3, Issue 72 Submitted-by: "Gordon W. Ross" <gwr@linus.UUCP> Archive-name: quickprompt For users who like a prompt showing the current working directory, here is a csh prompt generator with two important advantages: (1) It never loads a program to create a new prompt, and (2) it shortens the current working directory if its beginning matches the $HOME directory. The reason I avoid loading a program (like expr or awk) is that doing so can produce unacceptable delays after a cd, pushd, or popd. Shortening the prompt allows long commands to still fit on an 80 column terminal. Shortening is performed by a little-know capability of the csh "dirs" command. The "dirs" command prints out the directory stack using full path-names and, if appropriate, names starting with "~/" are shown. This should help in understanding the following csh aliases: # Set prompt generating aliases... # Note: this prompt generator uses only C-shell built-in commands. # Loading programs to build a prompt gives unacceptably slow results. set host = `hostname` # (done only once) # one backslash is used when this file is sourced; # another is used when the alias is interpreted. alias prompt 'set noglob ;\\ set prompt = `dirs` ;\\ set prompt = "${host}.${user}:${prompt[1]}> " ;\\ unset noglob' alias popd 'popd \!* ; prompt' alias pushd 'pushd \!* ; prompt' alias cd 'cd \!* ; prompt' prompt # make it appear as the first prompt # That's all, folks. Have fun! -- Gordon W. Ross MITRE (E025), Burlington Road, Bedford, MA 01730 linus!gwr@mitre-bedford.arpa {decvax,philabs}!linus!gwr.UUCP