Post a Comment
I don't use OSX -- does Terminal.app not support the escape sequence to set the GUI terminal title? If indeed it does, I think that's a better option for showing long working directory paths.
I use the following bash prompt on my Linux desktop:
export PS1="\[\033]0;\u:<\w>\007\]\n\[\033[01;33m\] > \[\033[00m\]"
This puts all the info into the GUI terminal titlebar, and the only prompt I have in the terminal is a neatly separated > .
Well, yes and no. Having the current directory in the title bar is certainly useful - I'd be lost without it. But having the full path clearly displayed every time you change directory sounds pretty handy too, when looking back over past commands to see what went wrong. I'm inclined to give it a try...
Here's what I've used for the last few years... on Mac OS X... this copy is tweaked a little to privatize... I don't know if this is generally useful for people or not, but in our environment some fairly long subpaths repeat themselves over and over again, so it occurred to me that I could run the path through a script to abbreviate those common paths.
Sarah
----- .bash_profile -----
PS1='$(/Some/place/sarahprompt.py)\n\!\$ '
----- begin sarahprompt.py -----
#!/usr/bin/python -E -S
import os
import time
# Date like: May17
tinydate=time.strftime("%b%d")
# \x1B is escape, \e doesn't work and I don't know why.
# Set title of window or tab
def title(str):
return '\x1B];'+str+'\007';
# Make a colored bar with text in it in the current window
def bar(str):
return "\x1B[2K\x1B[0;1;47m\x1B[0K"+str+"\x1B[0m";
# Get the current directory, and substitute ~ for home dir
current_path=os.environ["PWD"]
home=os.environ["HOME"]
if (current_path.startswith(home)):
current_path="~"+current_path[len(home):]
current_path=current_path.replace("/some/long/tedious/path/","/(abb rev)/")
#... add more replacements here ...
# Last two path elements (works right for less than two, too!
tinypath="/".join(current_path.split("/")[-2:])
# Prompt string sets the title and the bar
prompt=title(tinydate+" "+tinypath)+bar(current_path)
# Print the string (which passes it back to bash for display)
print prompt
----- end sarahprompt.py -----
I done the same in bash before, but it is a lot less flexible
http://img8.imageshack.us/img8/4928/blender89.png
http://img593.imageshack.us/img593/1929/1002669.jpg (I know, I have an high score of ricerness)
http://img8.imageshack.us/img8/4928/blender89.png
http://img593.imageshack.us/img593/1929/1002669.jpg (I know, I have an high score of ricerness)
I have a very similar ZSH prompt. I think we both stole the template from http://aperiodic.net/phil/prompt/
Except in mine I have the time on the left and use the rprompt to display which mode I'm in (I use ZSH in vi-mode).
PS1="[\t][\u@\H:\w:`pwd`]\r\n$ " does a pretty decent job - it displays the time stamp, the current folder, and there's a lot of space for roomy commands after the $ sign. Suse users can replace it with the #, if they want. Lots of options, really. I also use "export HISTTIMEFORMAT="%F %T ", so both look like this :
[11:14:57][user@host:~/docs:/home/user]
$
and
1003 2010-11-25 11:15:13 history



