“It is sometimes hard to form a mental model of a directory tree when working with the command line. GUI shells tend to provide more visual cues. So, like a lot of Bash users, I used to get around this by printing the current working directory in my shell prompt. However, things can get pretty cramped when dealing with deeply nested directories. A better solution is needed.”
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…
Cramping my style? It’s a tool.
Next thing you know, these Mac people will want aesthetic hammers.
I started at the command prompt, and I’ll probably end at it. Now get off my lawn!
For a normal user:
PS1=’\[\033[01;32m\]\w$\[\033[00m\] ‘
And for root:
PS1=’\[\033[01;31m\]\w#\[\033[00m\] ‘
Works for me, which, after all, is all that matters.
The default prompt in fish only shows the first letter of each directory in your current path after a certain level.
This may sound weird, but it’s usually enough to work out where you are without much effort, and prevents too much wrapping hell
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)
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).
The article is just a short instruction on how to print the pwd after a cd. Exactly how is this OS specific?
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
Add an \n after the \u \h and \w escape sequences. Problem solved.
Why would I want to print the working directory after I use cd? Am I expected to immediately forget the previous command? If I do forget my working directory, running pwd would be more intuitive than scanning the previous text.
pwd and tree work effectively enough for me so I can’t say I’ve ever felt I’ve needed something more elaborate.