<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br></div><div>I missed the original email, but here's the bit of my ~/.bashrc that sets the prompt:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div># Pretty prompt</div></div><div><div>smiley() {</div></div><div><div> if [ $? = 0 ]; then</div></div><div><div> printf $1</div></div><div><div> else</div></div><div><div> printf $2</div></div><div><div> fi</div></div><div><div> return $?</div></div><div><div>}</div></div><div><div><br></div></div><div><div>export GIT_PS1_SHOWDIRTSTATE="true"</div></div><div><div>export GIT_PS1_SHOWSTASHSTATE="true"</div></div><div><div>export GIT_PS1_SHOWUNTRACKEDFILES="true"</div></div><div><div>export PS1='$(smiley "\[\033[01;32m\]:)\[\033[00m\]" "\[\033[01;31m\]:(\[\033[00m\]") \[\033[01;34m\]\W\[\033[00m\] \[\033[01;36m\]$(rvm-prompt i v g)\[\033[00m\]$(__git_ps1 " \[\033[01;35m\](%s)\[\033[00m\]") \$ '</div></div></blockquote><div><div><br></div><div>The colour escapes are pretty horrific, but the key bit is that PS1 evaluates `$(smiley ":)" ":(")` every time it's displayed and chooses one of the arguments depending on the last status code.</div><div><br></div><div>I'm sure I stole it from someone else, but I can't remember who to credit, sorry.</div><div><br></div><div>Cheers,</div><div><br></div><div>Graeme.</div><div><br></div><div><div>On 9 Jan 2012, at 14:36, Viktor Tron wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>i guess you simply need something like this. hth<br><br>function exitstatusprompt {<br>EXITSTATUS="$?"<br>#PROMPT=$(rbenv version-name)<br>if [ "${EXITSTATUS}" -eq 0 ]<br> then<br> PS1="${PROMPT} ${GREEN}"<br> else<br> PS1="${PROMPT} ${RED}"<br>fi<br>}<br>PROMPT_COMMAND=exitstatusprompt<br><br><br>On Mon, 09 Jan 2012 14:20:16 -0000, Andrew Stewart <<a href="mailto:boss@airbladesoftware.com">boss@airbladesoftware.com</a>> wrote:<br><br><blockquote type="cite">Hola El Rug,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'm having trouble incorporating the exit status of the last command into my bash prompt. My prompt executes a couple of commands to display the current Ruby version and the current git status, and then I want to use the exit status of the last command to control the colour of the final character (e.g. $).<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">However the prior commands (for the Ruby and git info) make the last-exit-status test useless so I need to save out the value at the start of the prompt. However I cannot seem to make it work.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">For example, this shows the correct exit status:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> PS1="\$? \$(rbenv version-name) $ "<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">But I want to make use of the exit status at the end of the prompt, along these lines:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"> PS1="XXX \$(rbenv version-name) \$( if [ YYY -eq 0 ]; then echo $GREEN; else echo $RED; fi ) $ "<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">where:<br></blockquote><blockquote type="cite">- XXX means save $?<br></blockquote><blockquote type="cite">- YYY means retrieve what XXX saved<br></blockquote><blockquote type="cite">- GREEN and RED are variables defined earlier in my bashrc with Bash's wacky colour codes.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'm sure there's a simple answer but I can't find it!<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thanks in advance,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Andy Stewart<br></blockquote><blockquote type="cite">-----<br></blockquote><blockquote type="cite"><a href="http://airbladesoftware.com">http://airbladesoftware.com</a><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">Chat mailing list<br></blockquote><blockquote type="cite"><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br></blockquote><blockquote type="cite"><a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br></blockquote>_______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>http://lists.lrug.org/listinfo.cgi/chat-lrug.org<br></div></blockquote></div><br><div apple-content-edited="true">
<div><div><div style="font-family: Helvetica, sans-serif; font-size: 12px; "><span style="border-collapse: collapse; font-family: arial; font-size: 13px; white-space: pre-wrap; ">-- </span></div><div style="font-family: Helvetica, sans-serif; font-size: 12px; "><span style="border-collapse: collapse; font-family: arial; font-size: 13px; white-space: pre-wrap; ">Graeme Mathieson</span></div><div style="font-family: Helvetica, sans-serif; font-size: 12px; "><font class="Apple-style-span" face="arial" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px; white-space: pre-wrap; "><br></span></font></div><div style="font-family: Helvetica, sans-serif; font-size: 12px; "><font class="Apple-style-span" face="arial, sans-serif" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 13px; white-space: pre-wrap; ">Follow me on Twitter: <<a href="http://twitter.com/mathie">http://twitter.com/mathie</a>></span></font></div><div style="font-family: Helvetica, sans-serif; font-size: 12px; "><span class="Apple-style-span" style="font-family: arial; font-size: 13px; border-collapse: collapse; white-space: pre-wrap; ">Blog: <<font color="#0000FF"><span style="text-decoration: underline; "><a href="http://woss.name/" target="_blank" style="color: rgb(42, 93, 176); ">http://woss.name/</a></span></font>></span></div><div style="font-family: Helvetica, sans-serif; font-size: 12px; "><span style="border-collapse: collapse; font-family: arial; font-size: 13px; white-space: pre-wrap; ">Telephone: +44 (0)7949 0777 44 </span></div></div></div><div><span style="border-collapse: collapse; font-family: arial; font-size: 13px; white-space: pre-wrap; "><br></span></div><br class="Apple-interchange-newline">
</div>
<br></div></body></html>