$PS1 tricks

Back when I switched from Debian to Fedora, the biggest, and hardest to get used to, change was the fact that the bash prompt looked like this:

Not having the full directory in the pathname had always been hard to get used to, but as I learned to delve deeper and deeper into source trees, that became really nice. And then (I think, feel free to correct me) Pinochio at Akademy reminded that that setup has its own set of limitations, and it was more and more clear that having only part of the PWD in the prompt could be an annoyance, particularly as I used pwd to constantly check whether I was in a CMake build dir, or the source dir. Well, not any more.

i

bash’s ability to colorize things suddenly rocks hard.🙂

I found it useful, feel free to hack on it, make it less craptastic… I picked the worst possible I-hate-Bash-Scripting way of doing this, perhaps some gurus can improve on it:

function startbd()

{

if [ "$(pwd|grep build)" = "" ];

then echo ;

else echo -ne '33[1;31m';

fi

}

function endbd()

{

if [ "$(pwd|grep build)" = "" ];

then echo ;

else echo -ne '33[0;34m';

fi

}

PS1="\e[0;34m[\$(date +%k:%M:%S)] [\u@\h \$(startbd)\W\$(endbd)]\\$ \e[m"

=-=-=-=-=
Powered by Blogilo

~ by Ryan Rix on 12 July 2010.

7 Responses to “$PS1 tricks”

  1. Here’s my long-time PS1: http://www.eikehein.com/gentoo/misc/bashprompt.txt

  2. You should try zsh. i.e. http://www.gitready.com/advanced/2009/01/28/zsh-git-status.html

  3. Coming from Gentoo, I always had a colourful promt (a main reason for chosing Gentoo in the first place) and took it with me when I migrated to Debian. My prompt shows the host red if I’m root, green otherwise. Also, my prompt is git-aware, showing the current branch in yellow.

    Root-promt:
    PS1=”\[33[01;31m\]\h\[33[01;34m\] \W\[33[01;33m\]`git branch 2>/dev/null|cut -f2 -d\* -s`\[33[00m\]”

    Normal-user-promt:
    PS1=”\[33[01;32m\]\u@\h\[33[00m\] \[33[01;34m\]\w\[33[01;33m\]`git branch 2>/dev/null|cut -f2 -d\* -s`\[33[00m\]”

  4. You can have a colored console in debian too. Just edit the config files.
    And to display the path use “\w”

  5. Untested:
    startbd() { [[ $PWD =~ build ]] && echo -ne ’33[1;31m’; }
    endbd() { [[ $PWD =~ build ]] && echo -ne ’33[0;34m’; }

    PS1=”\e[0;34m[\$(date +%k:%M:%S)] [\u@\h \$(startbd)\W\$(endbd)]\\$ \e[m”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: