Linked by Shane on Wed 24th Nov 2010 22:40 UTC
General Development "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."
Order by: Score:
Why not set the GUI terminal title?
by Hypnos on Wed 24th Nov 2010 22:58 UTC
Hypnos
Member since:
2008-11-19

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 > .

Reply Score: 1

Delgarde Member since:
2008-08-19

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.


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...

Reply Score: 3

GUI Fury!
by Anonymous Coward on Wed 24th Nov 2010 23:34 UTC
Anonymous Coward
Member since:
2005-07-06

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!

Reply Score: 4

To each his (or her) own
by bosco_bearbank on Thu 25th Nov 2010 00:33 UTC
bosco_bearbank
Member since:
2005-10-12

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.

Reply Score: 1

Fish
by stestagg on Thu 25th Nov 2010 00:40 UTC
stestagg
Member since:
2006-06-03

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

Reply Score: 2

sarahannalien
Member since:
2009-05-07

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 -----

Reply Score: 2

A good PS1 is easier done with ZSH
by Elv13 on Thu 25th Nov 2010 02:15 UTC
Elv13
Member since:
2006-06-12

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)

Reply Score: 4

flynn Member since:
2009-03-19

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).

Reply Score: 1

OS related?
by jal_ on Thu 25th Nov 2010 08:32 UTC
jal_
Member since:
2006-11-02

The article is just a short instruction on how to print the pwd after a cd. Exactly how is this OS specific?

Reply Score: 2

Comment by kvarbanov
by kvarbanov on Thu 25th Nov 2010 09:16 UTC
kvarbanov
Member since:
2008-06-16

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

Reply Score: 1

.
by Icaria on Thu 25th Nov 2010 10:30 UTC
Icaria
Member since:
2010-06-19

Add an \n after the \u \h and \w escape sequences. Problem solved.

Reply Score: 1

The article is stupid.
by nflenz on Fri 26th Nov 2010 02:28 UTC
nflenz
Member since:
2010-11-26

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.

Reply Score: 2

Comment by Laurence
by Laurence on Fri 26th Nov 2010 17:36 UTC
Laurence
Member since:
2007-03-26

pwd and tree work effectively enough for me so I can't say I've ever felt I've needed something more elaborate.

Reply Score: 2