broadman@paul.rutgers.edu (Alan Broadman) (11/16/89)
I have a (hopefully) simple question. How can you get the UNIX prompt to always reflect the path to the current directory. Such a prompt would change with each 'cd ' command. In MS-DOS this is done by the command : 'prompt $P'. I think this would be most helpful, as otherwise, the prompt string is quite useless. Allen Broadman Broadman@paul.rutgers.edu
rostamia@umbc5.umbc.edu (Rouben Rostamian) (11/16/89)
In article <Nov.16.00.56.12.1989.9985@paul.rutgers.edu> broadman@paul.rutgers.edu (Alan Broadman) writes: | |I have a (hopefully) simple question. How can you get the UNIX prompt |to always reflect the path to the current directory. Such a prompt |would change with each 'cd ' command. In MS-DOS this is done by the |command : 'prompt $P'. I think this would be most helpful, as |otherwise, the prompt string is quite useless. | Oh boy! Are your in trouble! Get out your flame-retardant suit. Hint: Also read the monthly posting of frequently asked question.
ckd@bu-pub.bu.edu (Christopher Davis) (11/16/89)
>>>>> On 16 Nov 89 05:56:13 GMT, broadman@paul.rutgers.edu (Alan Broadman) >>>>> said: Alan> I have a (hopefully) simple question. How can you get the UNIX prompt Alan> to always reflect the path to the current directory. Such a prompt Alan> would change with each 'cd ' command. In MS-DOS this is done by the Alan> command : 'prompt $P'. I think this would be most helpful, as Alan> otherwise, the prompt string is quite useless. Depends--what shell are you using? If you're using tcsh (or can chsh to it, or can get your sysadmin to put it up, etc) you can just do what I do: set prompt="%t ckd@%m : %~ %% " which results in something like: 7:47am ckd@bucsf : ~/bin % the %m being the short hostname (hey, you use multiple machines, you start to need these memory joggers when you get old) and the %~ being the magic part that puts the current working directory in there (properly ~-abbreviated when I'm in my own directory tree). See man tcsh, again assuming you can get it set up--it's got other nice stuff, such as emacs-like command line editing (as well as some vi-like editing, I hear, but I wouldn't know... :-), tab completion of commands and filenames, et. al. If you can't get tcsh, let me dig out this unghodly set of aliases I stole from someone (who stole them from someone, who stole them from someone, unto their forefathers before them, yea, verily...) that put the hostname and trailing directory component into the prompt. They wouldn't be hard to hack to put the full cwd in. -- Christopher Davis, BU SMG '90 <ckd@bu-pub.bu.edu> <smghy6c@buacca.bitnet> "Technology is dominated by those who manage what they do not understand."
woodgate@pyrltd.UUCP (John Woodgate) (11/16/89)
In article <Nov.16.00.56.12.1989.9985@paul.rutgers.edu> broadman@paul.rutgers.edu (Alan Broadman) writes: >How can you get the UNIX prompt to always reflect the path to the >current directory. Try this (from my .cshrc) set prompt="$cwd> " alias cd 'cd \!* ; set prompt="$cwd> "' John Woodgate * Any resemblance between the above * -mm------- Pyramid Technology Ltd. * views and those of employer, my * ---mmmm----- ..ukc!pyrltd!woodgate * wife, or my kids, is pure chance * -----mmmmmm--- Tel : +44 252 373035 * and never likely to be repeated. * -------mmmmmmmm-
yakker@ucrmath.UCR.EDU (matt robinson) (11/17/89)
==>In article <Nov.16.00.56.12.1989.9985@paul.rutgers.edu> ==>broadman@paul.rutgers.edu (Alan Broadman) writes: ==>How can you get the UNIX prompt to always reflect the path to the ==>current directory. This is our school's method (Recipe #3,402) :-) It also includes the path, username, and current history (for csh.) Hope this helps. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< # Setting the Prompt and Changing Directories. set hostname = `hostname` set username = `whoami` set fromname = `who am i | awk '{print $1}' | sed 's/^.*\\\!//'` if ("$fromname" != "$username") then set username="$username"' ('"$fromname"')' endif alias heyyou 'set prompt = "$hostname : $username : `pwd`\\ \! >"' set prompt = "$hostname : $username : `pwd`\ \! >" a cd 'cd \!*;heyyou' a pushd 'pushd \!*;heyyou' a popd 'popd;heyyou' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< P.S. You should have read the newusers newsgroup before posting this... Makes life easier on all of us. -----------------------*------------------------------------------------------ yakker@ucrmath.ucr.edu | Matt Robinson, University of California at Riverside ..!ucsd!ucrmath!yakker | Department of Mathematics and Computer Science -----------------------*------------------------------------------------------
ctne_ltd@uhura.cc.rochester.edu (Chris Newbold) (11/18/89)
In article <Nov.16.00.56.12.1989.9985@paul.rutgers.edu> broadman@paul.rutgers.edu (Alan Broadman) writes: > >I have a (hopefully) simple question. How can you get the UNIX prompt >to always reflect the path to the current directory. Such a prompt >would change with each 'cd ' command. In MS-DOS this is done by the >command : 'prompt $P'. I think this would be most helpful, as >otherwise, the prompt string is quite useless. I tried to do the same thing, too. Under Unix, however, it's a little cludgy. The problem I encounted when trying to insert the cwd variable into the prompt string was that csh would always evaluate it *before* assigning the prompt variable, resulting in a prompt that would display the current directory at the time of startup. The only way I found to get around it was to use an alias to change directories and then change the prompt. Try this: alias cd 'chdir \!*; set prompt = "$cwd % "' Hope this helps. -- >>>> Chris Newbold <<<< * "If you fool around with a thing for very long you * University of Rochester * will screw it up." * Disclaimer: "All warranties expire upon payment of invoice." ctne_ltd@uhura.cc.rochester.edu * uhura.cc.rochester.edu!ctne_ltd@uunet
jak@sactoh0.UUCP (Jay A. Konigsberg) (11/18/89)
In article <Nov.16.00.56.12.1989.9985@paul.rutgers.edu> broadman@paul.rutgers.edu (Alan Broadman) writes: > >I have a (hopefully) simple question. How can you get the UNIX prompt >to always reflect the path to the current directory. You can't change the ' cd ' command itself because it is a Bourne shell built-in! However, the task can still be done. All that is required is that the PS1 and PS2 variables are set in the current shell layer. The script shown is placed in my .profile and works fine. One word of warning though, commands that give you a new shell, like newgrp, will wipe it out till your next login. Also, get in the habit of using "cdd" instead of "cd". #### SHOULD BE THE LAST LINES IN THE .profile #### # cdd - cd with a current directory in the prompt echo "Enter: \" cdd = \" to return to a $ prompt" cdd() { if [ "$1" = "=" ]; then PS1="$ "; PS2="> " else cd $1 PS1="`pwd` $ "; PS2="`pwd` > " fi } cdd -- ------------------------------------------------------------- Jay @ SAC-UNIX, Sacramento, Ca. UUCP=...pacbell!sactoh0!jak
chip@ateng.com (Chip Salzenberg) (11/21/89)
According to rmg@ultra.com (Rich Geiger): >Somehow > /usr/baziotes/projs/releases/source/lint/obj/debug/notes/private % >as a prompt is somewhat irritating. Doesn't leave much space for >typing a command, either! Right. That's why I've got the last two components of the path in my prompt. Using tcsh: alias precmd 'set _h=${cwd:h}; set prompt="%m {${_h:t}/${cwd:t}} % "' -- You may redistribute this article only to those who may freely do likewise. Chip Salzenberg at A T Engineering; <chip@ateng.com> or <uunet!ateng!chip> "Did I ever tell you the Jim Gladding story about the binoculars?"