Path: utzoo!attcan!uunet!husc6!ukma!tut.cis.ohio-state.edu!mandrill!hal!ncoast!allbery From: gwr@linus.UUCP (Gordon W. Ross) Newsgroups: comp.sources.misc Subject: v03i072: Re: v03i070: csh prompt generator Summary: prompt showing $cwd (shortened) Keywords: fast csh prompt Message-ID: <35735@linus.UUCP> Date: 5 Jul 88 17:05:10 GMT Sender: allbery@ncoast.UUCP Reply-To: gwr@linus.UUCP (Gordon W. Ross) Organization: The MITRE Corporation, Bedford, MA. Lines: 40 Approved: allbery@ncoast.UUCP Posting-number: Volume 3, Issue 72 Submitted-by: "Gordon W. Ross"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