<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">… and I didn't actually read the original email either. Ignore me.<div><br></div><div>I guess the smiley() function could set an environment variable (instead of doing a printf) and you could display the environment variable later on in the prompt. There will be some horrible escaping involved to make the variable get evaluated at the time the prompt is displayed. :)</div><div><br></div><div>Cheers,</div><div><br></div><div>Graeme.</div><div><br><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>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><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></span><br class="Apple-interchange-newline">
</div>
<br></div></body></html>