[Melbourne-pm] Bash prompt red on error

Alfie John alfiejohn at gmail.com
Wed May 12 22:03:57 PDT 2010


What I tend to do is have all text as red to indicate that I'm on a
production box, but Hamish's prompt is nice and not as offensive as a screen
full of red.

Alfie

On Thu, May 13, 2010 at 2:37 PM, Sam Watkins <sam at nipl.net> wrote:

> On Thu, May 13, 2010 at 01:44:33PM +1000, Hamish Carpenter wrote:
> > As briefly discussed last night, I mentioned I'd changed my prompt to
> > be red on error (return code != 0). This helps me detect failed
> > commands and also helps in another case where you type a command then
> > cancel it by pressing ctrl+c. This was what prompted me to change my
> > prompt as someone watching your terminal cannot easily tell that
> > command was canceled, especially if it is a command that would have no
> > output on success (eg rf -f project_directory).
> >
> > add the following to your .bash_profile:
> >
> > # needs PS1 to be previously defined so add nearer the end of your
> > .bashrc/.bash_profile
> > # will turn entire prompt red (31) or green (32)
> > # depending on previous output return code
> > export PS1="\[\e[\`if [ \$? = 0 ]; then echo '0;32m'; else echo
> > '0;31m'; fi\`\]$PS1\[\e[0m\]"
>
> cool, a friend showed me something similar, giving
> ^_^ for a success prompt, and O_o for failure :)
>
>        # SmiliePrompt - from http://x-demon.org/
>        smiley() { if [ $? == 0 ]; then echo '^_^'; else echo '0_o'; fi; }
>        export PS1='$(smiley) '
>
> It's important to know exit status, so I use this all the time.  The shell
> should really do something like this by default, maybe not the cute
> emoticon
> version though.
>
> enjoy!  :)
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20100513/712f4cec/attachment.html>


More information about the Melbourne-pm mailing list