Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!ibmchs!auschs!panews!ibmpa.awdpa.ibm.com!eclarke From: eclarke@ibmpa.awdpa.ibm.com (Eric S. Clarke) Newsgroups: comp.unix.aix Subject: Re: How To: set PS1 to show users "current" directory? Keywords: AIX Message-ID: <1991Apr16.114645@ibmpa.awdpa.ibm.com> Date: 16 Apr 91 18:46:45 GMT References: <1599@msa3b.UUCP> <1991Apr13.025012.13451@shared.uucp> Sender: news@ibmpa.awdpa.ibm.com (news id) Reply-To: eclarke@ibmpa.awdpa.ibm.com (Eric S. Clarke) Organization: IBM Advanced Workstations Division, Palo Alto Lines: 83 In article <1991Apr13.025012.13451@shared.uucp>, davec@shared.uucp (Dave Close) writes: |> In article <1599@msa3b.UUCP> mgphl@msa3b.UUCP (Michael Phillips) |> writes: |> >Trying to set up AIX on a PS/2 & have users that want their command |> >prompt to show their current directory (aka: $P$G in **DOS). |> |> If you are using an xterm, either SVr4 or aixterm, the following |> might |> also be of use. It doesn't make your prompt so verbose and is |> always |> present. |> |> _cd () { |> unalias cd |> cd ${@} |> alias cd=_cd |> if [ "$(whoami)" = "root" ] ; then |> pmt=\# |> else |> pmt=\$ |> fi |> export PS1="^[]0;$(hostname -s):$(whoami) ${PWD}^G${pmt} " |> } |> [ "${TERM}" = "aixterm" -o "${TERM}" = "xterm" ] && { |> alias cd=_cd |> typeset -fx _cd |> if [ "$(whoami)" = "root" ] ; then |> pmt=\# |> else |> pmt=\$ |> fi |> PS1="^[]0;$(hostname -s):$(whoami) ${PWD}^G${pmt} " |> export PS1 |> } |> |> Note, replace the ^[ and ^G with actual escape and bell characters. Here are a couple of things to consider. First, since the Korn shell reevaluates PS1 every time before displaying a new prompt there is no need to alias cd. This can be made as simple as setting the value of PS1. Since this is also probably the same env file that gets executed if you use dialup lines, (That is when X is not useable) check to see if you have an xterm or aixterm. If you don't set the value of PS1 to display on the command line. If you do set similarly to the above example. There are a few differences that I would like to point out. If you change ^[]0 to ^[]1 you can control the icon string and then if you change it to ^[]2 you can control the title string. By puting both of these in your prompt you can seperatly control the name in the title and the icon. The next issue deals with command line editing in the Korn shell. The shell determines where to scroll the command line based on the width of the window less the number of characters in the prompt. This means that if you just put a long PWD path and other misc. stuff in your title bar, the command line starts to scroll long before it reaches the right margin. You can fake out the Korn shell by sending it an ^[[A. This effectively restarts the count on the length of the prompt. So putting it all togeather (Assuming that the various variables are already set: case "${TERM}" in *xterm) export PS1='^[]1;${HOSTNAME}^G^[]2;${USER}@${HOSTNAME}:${PWD}^G^[[A(!) $ ' ;; *) export PS1='${USER}@${HOSTNAME}:${PWD} (!) $ ' esac When this is displayed in your env file everything past ^[[A will be displayed on the next line. As noted above ^[ = escape and ^G = control G (or Bell). If you wish you can change the $ at the end of the prompt to be a variable to indicate that the user is the root user. -- Eric S. Clarke INTERNET: eclarke@ibmpa.awdpa.ibm.com 1510 Page Mill Road UUCP: uunet!ibmsupt!eclarke Palo Alto, CA 94304 IBM VNET: ECLARKE at AUSVMQ 415-855-4458 T/L: 465-4458