herrage@brchh107.BNR.CA (Robert Herrage) (02/28/91)
I have the following defined in my .profile: alias prompt="PS1=\"--> \`pwd\` <-- hostname> \"" This sets my prompt to put my current directory on one line and my prompt below it on the next line. I also want to have an alias (or something) for "cd" so that when I use "cd" to change directories, my prompt will update accordingly. The problem is that when I alias "cd", ksh doesn't parse for any imbedded aliases. Therefore, alias cd='cd $*;prompt'
asg@sage.cc.purdue.edu (The Grand Master) (02/28/91)
In article <1772@brchh104.bnr.ca> herrage@brchh107.BNR.CA writes: >I have the following defined in my .profile: > > alias prompt="PS1=\"--> \`pwd\` <-- > hostname> \"" Try instead PS1="--> \$PWD <-- Bruce Varney The Grand Master
beckley@cbnewsd.att.com (Owen D. Beckley) (02/28/91)
From article <7079@mentor.cc.purdue.edu>, by asg@sage.cc.purdue.edu (The Grand Master): > In article <1772@brchh104.bnr.ca> herrage@brchh107.BNR.CA writes: >>I have the following defined in my .profile: >> >> alias prompt="PS1=\"--> \`pwd\` <-- >> hostname> \"" > Try instead > PS1="--> \$PWD <-- If you like a one line prompt, try this: PS1='${PWD#${PWD%/*/*/*}/}> ' I puts only the lowest three parts of PWD in the prompt. owen_d_beckley@att.com
nichols@en.ecn.purdue.edu (Scott P Nichols) (03/01/91)
In article <1772@brchh104.bnr.ca> herrage@brchh107.BNR.CA writes: >I have the following defined in my .profile: > > alias prompt="PS1=\"--> \`pwd\` <-- > hostname> \"" > >This sets my prompt to put my current directory on one line >and my prompt below it on the next line. I also want to have >an alias (or something) for "cd" so that when I use "cd" to >change directories, my prompt will update accordingly. The >problem is that when I alias "cd", ksh doesn't parse for any >imbedded aliases. Therefore, > > alias cd='cd $*;prompt' > How about... PS1='\!]$PWD>' ...works for me! Scott -- O- /\ |\ /\/vv\ /vv\ \ __Insight from Oregon...Scott P. Nichols _____/ \ ~~~~~~~~~~~~~~~~ (nichols@en.ecn.purdue.edu)
heiby@mcdchg.chg.mcd.mot.com (Ron Heiby) (03/02/91)
If my records are complete, I posted the this article in December of 1986, while working for AT&T. Then, with modifications in December of 1987, while working for Motorola. Since then, Ksh-88 has been released and I've seen quite a few articles asking to do lots of stuff with the prompt string. So, here it is again, modified for Ksh-88 a bit and enhanced in some other minor ways. If you are still using an older version of Ksh, UPGRADE! Enjoy! A while ago [from the perspective of someone writing in December of 1986], there were several messages posted to Usenet which showed ways to include various information into a Korn Shell PS1 prompt. I thought that a number of these were real clever and incorporated them into my own environment. Now that Motorola Microcomputer Division [now the Motorola Computer Group] is selling the Korn Shell for our Delta Series of 68020-based systems, I thought I'd share this generally. Relatively little here is my own invention, but I can no longer say who had every idea. I did put a lot of work into integrating everything together so that it would all work in a coordinated fashion. The time stamp stuff is from Korn. The "autoload" stuff [originally used] for functions (pshd, popd, etc.) as well as the original versions of those functions is from a Usenet article by Avi E. Gross in 10/84. [This has since been absorbed in slightly different form into standard Ksh-88.] I have made some readability and efficiency enhancements to the originals, as well as merging them into the rest of the stuff here. I pulled out the large blocks of comments in Avi's original to improve the performance in my running copy and keep the original intact elsewhere so I can figure out what's going on. As to the prompt-resetting code, I know there were at least three different people (plus me) who contributed to what is merged together here, but I lost the original Usenet articles. Thanks, whoever you are. I've tried to put this is into a form that you can easily install into your own environment. I mostly did it to see if I could. Since then, it has proved useful enough for me to keep it as my normal environment. One could easily turn up one's nose at all this, if one really likes the "$ " prompt, as this is about as far from that as you can get. The normal prompt when logged in and in your home directory is: host: hh:mm:ss [~] nn> After "cd /usr/src/cmd/vi", it is: host: hh:mm:ss [src/cmd/vi] nn> After "pshd /usr", it is: host: hh:mm:ss 1: [/usr] nn> After "popd", it is back to: host: hh:mm:ss [src/cmd/vi] nn> After invoking a sub-shell (ksh): host: hh:mm:ss [src/cmd/vi] nn>> The "host" is the output of the "uname" command. I added the host name to the prompt to make it more obvious to whom I was "talking" in the face of "cu" and "rlogin" and windowing terminals. The "nn" is the ksh history number. hh:mm:ss is the time. As you can see, up to the last three directories in your current directory are included. If you are in a subdirectory of your home directory, your home directory path counts as a single directory and is represented with a tilde (~). If you are using Shell Layers (shl), the layer name "foo" or number "(n)" is displayed as part of the prompt, too. If the uid of the user is 0 (root), then a pound sign (#) is used instead of a greater-than (>) to indicate nesting of sub-shells. The prompt was split into two lines because the escape sequences to highlight a non-zero return code get counted as printable characters and so fewer characters from the command you are entering are visible in the line. Good luck trying to change any of it without breaking something else. I am currently running ksh "Version 11/16/88e". Even if you don't use this, it makes an interesting exercise to figure out how everything works. After doing so, you'll have a very good understanding of ksh programming. Ron. --------- This goes in your .profile -------- # environment for fancy prompt export PSSHL PS1="!$ " FPATH=~/ksh -------- This goes in your $ENV file --------- # All this good stuff needed for interactive shells only. # Guard it with appropriate tests for better effeciency of startup. # Here's a good example of this: # case "$-" in # *c*) # Stuff for -c, command line shells goes here. # : # ;; # *) # Stuff for for non -c, (interactive) shells. # : # ;; # esac # # Set prompt string portion for Shell Layers layer. TTY=$(tty) if [ "$TTY" != "${TTY#*sxt}" -a "${SHDEPTH:-}" = ">" ] then export PSSHL=$PS1 fi unset TTY # # Set System name string for fancy prompt UNAME=$(uname) # # Set standout strings for fancy prompt : ${SMSO:=$(tput smso)} ${RMSO:=$(tput rmso)} # # Set up for time stamping typeset -RZ2 _x1 _x2 _x3 let SECONDS=$(date '+3600*%H+60*%M+%S') TIME='"${_d[(_x1=(SECONDS/3600)%24)==(_x2=(SECONDS/60)%60)==(_x3=SECONDS%60)]}$_x1:$_x2:$_x3"' # # Define the replacement for the "cd" builtin function ch { if cd ${*:-''} then resetps1 else return 1 fi } alias cd=ch # make it easy to use function resetps1 { typeset _dir=$PWD typeset _dirt=${_dir#$HOME} # directory tail if [ "${_dirt}" != "${_dir}" ] then _dir="~${_dirt}" fi typeset front=${_dir%/*/*/*} : ${front:=x} case ${pushlevel:-0} in 0) PS1="${UNAME}: ${TIME} ${PSSHL:-}${SMSO:-}\${?#0}${RMSO:-}[${_dir#$front/}] !$SHDEPTH ";; *) PS1="${UNAME}: ${TIME} $pushlevel: ${PSSHL:-}${SMSO:-}\${?#0}${RMSO:-}[${_dir#$front/}] !$SHDEPTH ";; esac } # Functions related to push and pop routines alias dirs='echo "\t0: $PWD"' \ popd='echo "You have never pushed any levels.\nYou remain at $PWD."' # # Check for uid 0 (root) id=$(id) id=${id#uid=} id=${id%%\(*} if [ id -eq 0 ] then export SHDEPTH=${SHDEPTH:-}'#' else export SHDEPTH=${SHDEPTH:-}'>' fi # Set special colors case $TERM in mskermc) case $id in 0) color=37 ;; 501) color=31 ;; *) color=35 ;; esac SMSO="[41;33m" RMSO="[44;${color}m[1m" unset color ;; tm229|tm229g) case $id in 0) color=33 ;; 501) color=37 ;; *) color=35 ;; esac SMSO="[41;33m" RMSO="[40;${color}m[1m" unset color ;; *) ;; esac unset id resetps1 -------- This is ~/ksh/pshd, linked to ~/ksh/pshpwd and ~/ksh/poppwd --------- unalias popd dirs integer pushlevel=0 function pshd { dirsave[pushlevel]="$PWD" # save the name of the current dir promptsave[pushlevel]="$PS1" # save the current prompt if [ pushlevel = 0 ] then pushprompt="$PS1" fi ch ${1:-$HOME} 2> /dev/null case $? in 0) # "cd" succeeded. let pushlevel=pushlevel+1 pwd # show the current directory : ${2:+`ls -Fx $3 $4 $5 $6 $7 $8 $9 >/dev/tty`} resetps1 ;; *) # "cd" failed print "Can't change to $1, aborting" return 1 ;; esac } # END of pshd function popd { integer levels=${1:-1} if (( pushlevel-levels>=0 )) then let pushlevel=pushlevel-levels else print "Can't pop that many levels. Your choices were:" dirs print "You are being returned to your original level" let pushlevel=0 fi ch ${dirsave[$pushlevel]} pwd # show the user where they are. : ${2:+`ls -Fx $3 $4 $5 $6 $7 $8 $9 >/dev/tty`} PS1="${promptsave[$pushlevel]}" } function dirs { integer level=$pushlevel integer lowest=$level-${1:-$level} if [ lowest -lt 0 ] then lowest=0 fi print " $level: $PWD" while [ level -gt lowest ] do let level=level-1 print " $level: ${dirsave[$level]}" done unset level lowest } function pshpwd { print $PWD "${@:-}" >~/.current-pwd } function poppwd { print $(<~/.current-pwd) } ---- start of pshd family documentation ---- # In brief, this routine is called in the form of: # . ~/ksh/psh-pop.ksh name arg1 arg2 arg3 ... # and has to do the following: # - Unalias all five related alias names. # - Declare all five function bodies using those names. # - Run the function that invoked this file, using the provided # arguments. # The first time one of these aliases is used, it needs to be "loaded". From # then on, each one represents a loaded function, and runs smoothly. The # advantages are that your .env is about a hundred lines smaller, and these # functions are only defined when used. # The first three routines are used to maintain and examine a directory stack # of traversals through the file system. They are: # pshd [directory] [ls-indicator] [ls-arg] [ls-arg] [ls-arg] # popd [levels] [ls-indicator] [ls-arg] [ls-arg] [ls-arg] # dirs [levels] # These are different than other versions of pshd that have been posted to # the net. Both pshd and popd have an optional first argument that tells # which directory to go to, or how many levels to backtrack. If a second # argument is specified (any string will do) then an "ls -C" is done after # the action is completed. Any additional arguments are passed to ls. For # example, "pshd /usr/spool/uucp l -l -a -t" will change the directory to # /usr/spool/uucp and then do an "ls -C -l -a -t" to show full descriptions # of all files in that directory in the orer that they were last changed. # The "-C" argument is used to force our version of ls to columnate the # output (even if it is going into a pipeline). # The next two routines are used to share information about the current # directory # between two windows on a DMD/BLIT or just to save the value # for later. Only one value is currently supported. They are: # pshpwd [additional text] # poppwd # Poppwd is often used in constructs like "cp *.c `poppwd`" ----------------------------------- end --------------------------- -- Ron Heiby mcdchg!heiby Moderator: mod.newprod & mod.os.unix -- Ron Heiby, heiby@chg.mcd.mot.com Moderator: comp.newprod "Wrong is wrong, even when it helps you." Popeye
lvc@cbnews.att.com (lawrence.v.cipriani) (03/04/91)
In article <57517@mcdchg.chg.mcd.mot.com> heiby@mcdchg.chg.mcd.mot.com (Ron Heiby) writes: ># Define the replacement for the "cd" builtin >function ch { > if cd ${*:-''} > then > resetps1 > else > return 1 > fi >} >alias cd=ch # make it easy to use I suggest the cd in function ch be quoted: function ch { if "cd" ${*:-''} then resetps1 else return 1 fi alias cd=ch so that a second ". $ENV" will not see 'ch' inside of function ch. Why not use "${@:-''}" instead of ${*:-''} ? -- Larry Cipriani, att!cbvox!lvc or lvc@cbvox.att.com "Fight fire with fire, I always say" -- Bugs Bunny
dalessio@motcid.UUCP (Mario D'Alessio) (03/05/91)
herrage@brchh107.BNR.CA (Robert Herrage) writes: >I have the following defined in my .profile: > alias prompt="PS1=\"--> \`pwd\` <-- > hostname> \"" > >This sets my prompt to put my current directory on one line >and my prompt below it on the next line. I also want to have >an alias (or something) for "cd" so that when I use "cd" to >change directories, my prompt will update accordingly. The >problem is that when I alias "cd", ksh doesn't parse for any >imbedded aliases. Therefore, > alias cd='cd $*;prompt' > To change the prompt using the cd command, I use a ksh function and alias combination. Notice the backslash preceeding the cd in the function: function _cd { \cd $* export PS1="${PWD}-> " } alias cd=_cd ****************************************************************** * ************************************************************** * * * * * * * Mario D'Alessio Motorola, Inc. * * * * dalessio@motcid.UUCP Cellular Infrastructure Group * * * * * * * ************************************************************** * ******************************************************************
heiby@mcdchg.chg.mcd.mot.com (Ron Heiby) (03/06/91)
lvc@cbnews.att.com (lawrence.v.cipriani) writes: >I suggest the cd in function ch be quoted: > function ch { > if "cd" ${*:-''} ... >so that a second ". $ENV" will not see 'ch' inside of function ch. Yes, that seems to be a good idea. I never ran into that, because I never do a second ". $ENV". Actually, I almost never do one, allowing ksh to do it for me as it starts up. With the prompt string all this gives you, it's pretty obvious that it has already been done! >Why not use "${@:-''}" instead of ${*:-''} ? Using the at-sign version ensures that if you pass multiple parameters to cd, that the parameters will be seperated by space characters. The asterisk version uses the first character of $IFS as the seperator. I don't see that it really matters all that much. Of course, if you don't have a space in your IFS string for some wierd reason, then using the at-sign here will leave you with your parameters lumped together with space seperators that will not be interpreted to be seperators (since space isn't in $IFS)! I guess that's a pretty good reason to leave this one as is! -- Ron Heiby, heiby@chg.mcd.mot.com Moderator: comp.newprod "Wrong is wrong, even when it helps you." Popeye
asg@sage.cc.purdue.edu (The Grand Master) (03/06/91)
In article <57993@mcdchg.chg.mcd.mot.com> heiby@mcdchg.chg.mcd.mot.com (Ron Heiby) writes: }lvc@cbnews.att.com (lawrence.v.cipriani) writes: }>I suggest the cd in function ch be quoted: } }> function ch { }> if "cd" ${*:-''} }... }>so that a second ". $ENV" will not see 'ch' inside of function ch. WHY DO YOU WANT TO MAKE IT SO HARD????? The $PWD variable changes when you cd. ksh provides for another eval of the prompt string before printing it, so all you have to do is quote the $ in $PWD like this: PS1="\$PWD ->" this will give you a prompt that includes the current directory and is dynamic - and it is alot easier than a whole bunch of kludged functions. Bruce --------- sar.casm \'sa:r-.kaz-*m\ \sa:r-'kas-tik\ \-ti-k(*-)le-\ n [F sarcasme, fr. LL sarcasmos, fr. Gk sarkasmos, fr. sarkazein to tear flesh, bite the lips in rage, sneer, fr. sark-, sarx flesh; akin to Av thwar*s to cut] 1: a cutting, hostile, or contemptuous remark : GIBE 2: the use of caustic or ironic language - sar.cas.tic aj ### ## Courtesy of Bruce Varney ### # aka -> The Grand Master # asg@sage.cc.purdue.edu ### ##### # PUCC ### # ;-) # # ;'> # ##
floyd@ims.alaska.edu (Floyd Davidson) (03/06/91)
In article <7365@mentor.cc.purdue.edu> asg@sage.cc.purdue.edu (The Grand Master) writes: >In article <57993@mcdchg.chg.mcd.mot.com> heiby@mcdchg.chg.mcd.mot.com (Ron Heiby) writes: >}lvc@cbnews.att.com (lawrence.v.cipriani) writes: >}>I suggest the cd in function ch be quoted: >} >}> function ch { >}> if "cd" ${*:-''} >}... >}>so that a second ". $ENV" will not see 'ch' inside of function ch. >WHY DO YOU WANT TO MAKE IT SO HARD????? >The $PWD variable changes when you cd. >ksh provides for another eval of the prompt string before printing it, >so all you have to do is quote the $ in $PWD like this: >PS1="\$PWD ->" >this will give you a prompt that includes the current directory and >is dynamic - and it is alot easier than a whole bunch of >kludged functions. PS1='$PWD ->' Floyd -- Floyd L. Davidson | floyd@ims.alaska.edu | Alascom, Inc. pays me Salcha, AK 99714 | Univ. of Alaska | but not for opinions.
gwc@root.co.uk (Geoff Clare) (03/07/91)
lvc@cbnews.att.com (lawrence.v.cipriani) writes: >Why not use "${@:-''}" instead of ${*:-''} ? Neither of these correctly preserve the argument list. In fact "${@:-''}" will pass two single quotes when there are no arguments, so it's even worse than plain "$@" which just passes an empty string. The only way (as far as I'm aware) to get it right in all cases is: ${1+"$@"} -- Geoff Clare <gwc@root.co.uk> (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273
heiby@mcdchg.chg.mcd.mot.com (Ron Heiby) (03/08/91)
In article <7365@mentor.cc.purdue.edu> asg@sage.cc.purdue.edu (The Grand Master) writes: >WHY DO YOU WANT TO MAKE IT SO HARD????? >The $PWD variable changes when you cd. >ksh provides for another eval of the prompt string before printing it, >so all you have to do is quote the $ in $PWD like this: >PS1="\$PWD ->" >this will give you a prompt that includes the current directory and >is dynamic - and it is alot easier than a whole bunch of >kludged functions. Yup. I suppose that if all you want is the absolute pathname of your current working directory, then all you have to do is something like you suggest. Of course, there are some long pathnames out there. I find on my system one that would give a prompt string (with your suggestion) something like: /src68/usr/src/cmd/sadmin/admin/menu/diagnostics/diskrepair/badtrack -> That doesn't leave much room for typing a command! Also, it doesn't provide any of the other things that have been integrated into the "monster" prompt that many people have found useful. -- Ron Heiby, heiby@chg.mcd.mot.com Moderator: comp.newprod "Wrong is wrong, even when it helps you." Popeye
noraa@cbnewsk.att.com (aaron.l.hoffmeyer) (03/08/91)
In article <7365@mentor.cc.purdue.edu> asg@sage.cc.purdue.edu (The Grand Master) writes: >The $PWD variable changes when you cd. >ksh provides for another eval of the prompt string before printing it, >so all you have to do is quote the $ in $PWD like this: >PS1="\$PWD ->" >this will give you a prompt that includes the current directory and >is dynamic > Bruce OK. That's solved. Now -> I like to have my p[rompt in reverse video (and in distinct colors when I am working on a terminal with those capabilities). Anyway, for the terminal I use the most, this is my PS1 definition: export PS1=`print - "\`tput smso\`\`tput blink\` ${SYSNAME}-> \`tput sgr0\` "` How do I get the \$PWD in my PS1 definition to be printed in reverse video? Aaron L. Hoffmeyer TR@CBNEA.ATT.COM
noraa@cbnewsk.cb.att.com (aaron.l.hoffmeyer) (03/09/91)
Thanks to Ihor Kinal, I've set PS1 so that it prints in reverse video on my terminal. This is what I have in my .profile: export RMSO=`tput rmso` export SMSO=`tput smso` export PS1='${SMSO}${SYSNAME} ${PWD#HOME/}-> ${RMSO} ' Yes, it can get long if the path to where you are at is long, but that doesn't bother me. What I like is that when I am running windows or layers I can immediately tell where I am at in a window. No need for pwd. Also, I can tell which machine I am logged on to in the window or layer (as long as I put the above lines in all my .profiles on the machines that I routinely work on. I know there are many ways to get this same information and have it displayed in X Windows, but I like to be consistent across machines. Anyway, try this out - you might like it. Aaron L. Hoffmeyer TR@CBNEA.ATT.COM
clercqm@nijmeg (Marien de Clercq) (03/13/91)
noraa@cbnewsk.cb.att.com (aaron.l.hoffmeyer) writes: >Thanks to Ihor Kinal, I've set PS1 so that it prints in reverse video on >my terminal. This is what I have in my .profile: > export RMSO=`tput rmso` > export SMSO=`tput smso` > export PS1='${SMSO}${SYSNAME} ${PWD#HOME/}-> ${RMSO} ' I don't know if you use the environment variables RMSO and SMSO again at other places, but if you don't, why bother defining them if you could the same with: PS1=`tput smso`'${SYSNAME} ${PWD#HOME/}-> '`tput rmso` (I don't know why you should export PS1, I never did) -- Marien de Clercq Intergraph European Mfg. bv. Nijmegen - The Netherlands Mail: (..!)uunet!ingr!nijmeg!m_clercq
tif@doorstop.austin.ibm.com (Paul Chamberlain) (03/13/91)
In article <1991Mar12.180408.26450@nijmeg> clercqm@nijmeg (Marien de Clercq) writes: > PS1=`tput smso`'${SYSNAME} ${PWD#HOME/}-> '`tput rmso` This has caused me problems on some terminals since you never know what the escape sequence is gonna be. Sometimes it includes an exclamation point which causes many troubles (seems like a dollar sign might cause some problems too but I haven't had that problem ... yet). Furthermore, I seem to recall having problems when trying to do this in-line so I use: so="`tput smso`" so="`echo $so | sed -e 's/!/!!/g'`" ro="`tput rmso`" ro="`echo $ro | sed -e 's/!/!!/g'`" typeset PS1="$so${HOST}:\${PWD#\${PWD%/*/*/*}/}->$ro " unset so ro Obviously, that does some other things too. I'm not sure why I have the word "typeset" in there. (I even simplified this for posting!) Paul Chamberlain | I do NOT speak for IBM. IBM VNET: PAULCC AT AUSTIN 512/838-9748 | ...!cs.utexas.edu!ibmchs!auschs!doorstop.austin.ibm.com!tif
rlp@druwa.ATT.COM (PrehnRL) (03/14/91)
In article <1991Mar12.180408.26450@nijmeg>, clercqm@nijmeg (Marien de Clercq) writes: > noraa@cbnewsk.cb.att.com (aaron.l.hoffmeyer) writes: > > >Thanks to Ihor Kinal, I've set PS1 so that it prints in reverse video on > >my terminal. This is what I have in my .profile: > > > export RMSO=`tput rmso` > > export SMSO=`tput smso` > > export PS1='${SMSO}${SYSNAME} ${PWD#HOME/}-> ${RMSO} ' > > I don't know if you use the environment variables RMSO and SMSO again at > other places, but if you don't, why bother defining them if you could the > same with: > > PS1=`tput smso`'${SYSNAME} ${PWD#HOME/}-> '`tput rmso` > > Marien de Clercq > I use RMSO SMSO variables for ${PS2} ${PS3} ${PS4} and numerous shell scripts & make files. Setting these variables eliminates 2 calls to tput every time I want something in Stand-out mode. For prompts I normally use "${SMSO}[${SYSNAME} ${LOGNAME}]${RMSO} " with the current directory shown on the status line or window label area. PS[234] are variations of PS1. When executing vi, the status line/label changes to: "${PWD} VI ${*}", upon returning from vi, the current directory is then redisplayed on the status line/label. Similar manipulations are done when executing rlogin, telnet, ftp or su. It makes it a lot easier to deal with multiple windows on several terminals. Robert Prehn +-----------------------------------------------------------+ AT&T Bell Labs | ____ _______ _____ _______ | Room 1F50 | / __ \ |__ __| / _ \ |__ __| | 11900 North Pecos | | <__> | | | \ \ \_\ | | | Denver, Co 80234 | | __ | | | / \ __ | | THE CHOICE| | | | | | | | | (\ / / | | | druwa!rlp | |_| |_| |_| \_____/ |_| | (303) 538-4554 | | +-----------------------------------------------------------+