A shell prompt that gives you current path in terminal window title

I know some of you guys do stuff in the terminal from time to time AppleScript related or not.
Thats why I took liberty to post this here.
This prompt shows the current directory in the window bar. I’m very pleased that it still works
with the new terminal -I had for instance to write a real kluge to make resizing work under Tiger.

It makes the terminal windows play really well with Exposé and spaces.

50% of the times I invoke a new terminal window, I do it by the OpenTerminalHere applet which I have installed on finders toolbar.
You can find the OpenTerminaHere applet from here: http://www.entropy.ch/software/applescript/OpenTerminalHere.app.zip

I found the original incantation over at a Linux site a couple of years ago, and I have rewritten it
for my self to make it easy to use. Unfortunately I have since long time forgotten who wrote the original prompt statement to show the path as the window title.

PRERQUSITES:

You have to use bash as your shell which is fairly standard nowadays and remove your normal prompt statement from your ~/.profile or ~/.bashrc or whatever.

Put the file promptsetup below somewhere on your disk - I’ have my “initstuff” in a directory ~/.init so that they are easy to find.

Then remove any old prompt statement from your .profile or .bashrc and
insert this statment in its place:
source ~/.init/promptsetup # ( You must source it!).

While beeing on the commandline later on, you can change prompt by the commands:

prompt PWP : path with a dollar sign.
prompt PWP : path with current time (at that moment, the time is static)
prompt NRP : prompt with command number, great with history.
prompt DS  : prompt with dollar sign,

Have you read this far you now that you can “man bash” for finding the other options, if none of
these doesn’t please you, but be careful when you change the NRP prompt because it is here the
“titling” of the window happens.

-------promptsetup
#! /bin/bash

export promptUsage=“Usage : prompt [-h | -u |-v ]|[ - | PWP | PWT | NRP | DS ]”
function promptHelp()
{
echo "prompt : “$promptUsage”
PWP : Prompt With Path
PWT : Prompt With Time - The time you fired up the shell
NRP : Normal Prompt.
DS : Dollar sign " 1>&2
}

function prompt()
{
case “$1” in
PWP | PWT | NRP | DS)
export OLPS1=“$PS1”
export OLDPROMPTYPE=$PROMPTTYPE
PROMPTTYPE=$1
if [ “$PROMPTTYPE” = “PWP” ]; then
PS1=“\w$”
elif [ “$PROMPTTYPE” = “PWT” ]; then
PS1=“\t:$”
elif [ “$PROMPTTYPE” = “NRP” ]; then
PS1=‘[\e]2;${PWD}\a
\e[1;30m]
!$
[\e[m]’
else
PS1=“$”
fi
export PS1
export PROMPTTYPE ;;
-h)
promptHelp ;;
-u)
echo $promptUsage 1>&2 ;;
-) PROMPTTMP=“$PS1”
export PS1=“$OLPS1”
export OLPS1=“$PROMPTTMP”
PROMPTTYPE_TEMP=$PROMPTTYPE
export PROMPTTYPE=$OLDPROMPTYPE
export OLDPROMPTYPE=$PROMPTTYPE_TEMP;;
*) echo -n “chgPrompt - uriktig parameter”
return 1;;
esac
}

prompt NRP
PROMPTTYPE=NRP

PS2=“>>”
PS3=‘choice nr : ’
PS4=’$0 line $LINENO:’ # Bash3 p 224.
export PATH TERMINFO PS1 PS2 PS3 PROMPTTYPE
--------------------------------------------- EOF promptsetup

Enjoy!

McUsr