Tip: Set Terminal Prompt

Discussion in 'Linux' started by rbil, Sep 25, 2008.

  1. rbil

    rbil

    Joined:
    Aug 14, 2008
    Messages:
    730
    Likes Received:
    0
    Location:
    The Wet Coast, Canada
    By default the command prompt in the Terminal in Linpus is using the basename of the current working directory. I like to see tne whole path (the current working directory) displayed in the prompt so I don't forget where I am. Here's how to change the prompt:

    edit .bashrc:

    Code:
    mousepad .bashrc
    After the # .bashrc line, add:

    Code:
    #Set prompt with current working directory
    PS1="\u@\h: \w\$ "
    Save and exit.

    Cheers.
     
    rbil, Sep 25, 2008
    #1
  2. rbil

    scottro

    Joined:
    Aug 31, 2008
    Messages:
    347
    Likes Received:
    0
    We're having fun with these. Actually, in bash 3 that doesn't work quite as well as it used to, I've forgotten what the problem is. (How's that for vagueness--disagree with you and refuse to say what it is that I'm disagreeing with.)
    At any rate, what *I* like is


    PS1="\[\033[1;34m\]\u@\[\033[1;32m\]\h \[\033[1;36m\]\${PWD##*/} $ \[\033[0m\]"

    Which adds all sorts of colors as well. :) However, the point I wanted to make in this case is that I find that rather than using \w, I find that ${PWD##*/} works better for me--ahhh, that's the issue, (I think). Doing \w refers to $HOME as ~.

    I have a page on playing with these at
    http://www.scottro.net/qnd/qnd-prompt.html

    Once again, I think you're doing good things posting these, and please don't take my additions as saying anything's wrong with them. :)
     
    scottro, Sep 25, 2008
    #2
  3. rbil

    rbil

    Joined:
    Aug 14, 2008
    Messages:
    730
    Likes Received:
    0
    Location:
    The Wet Coast, Canada
    No problem. :) To each his own. Personally I like the fact that the prompt displays ~ for home. Then a newbie should learn that cd ~ gets them back home in a hurry. :) As to coloured prompts ... not my cup of tee. Guess my eyeballs are too old for that in a terminal. And as I stated originally, I like a prompt that shows me exactly where I am.

    Cheers.

    PS. For those interested in trying a new prompt, but not committing to it for every session which is what happens if you place it in .bashrc, you can simply copy and paste the PS1= line posted in these messages into a terminal and instantly see how the new prompt will look/work. Close the terminal and reopen a new one and you're back to the standard Linpus prompt.
     
    rbil, Sep 25, 2008
    #3
  4. rbil

    scottro

    Joined:
    Aug 31, 2008
    Messages:
    347
    Likes Received:
    0
    That's actually a bit funny. The reason I tend to go with colored prompts these days is because of my own aging eyes. :)

    (It's also the reason I decided I wanted scottro instead of ~, it's easier to see.)
     
    scottro, Sep 25, 2008
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.