{"id":216,"date":"2010-08-20T13:51:37","date_gmt":"2010-08-20T11:51:37","guid":{"rendered":"http:\/\/joernhees.de\/blog\/?p=216"},"modified":"2016-09-28T23:47:34","modified_gmt":"2016-09-28T21:47:34","slug":"bash-prompt-return-value","status":"publish","type":"post","link":"https:\/\/joernhees.de\/blog\/2010\/08\/20\/bash-prompt-return-value\/","title":{"rendered":"Bash prompt indicating return value"},"content":{"rendered":"<p>Lately I&#8217;ve fiddled a lot with installing virtuoso on some virtual machines and found myself repeatedly asking bash for the return value of the last command <code>echo $?<\/code>. I remembered <a href=\"http:\/\/g3cko.org\/wordpress\/?p=138\">this blog post<\/a> by Gecko quite a while ago and tuned it a bit to my needs. My user prompt now looks like this (it&#8217;s a slightly modified version of the old gentoo defaults, that I prefer over the ubuntu defaults, which only remind you that you&#8217;re root with a # instead of a $):<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/joernhees.de\/blog\/wp-content\/uploads\/2010\/08\/bashPromptRetValColor.png\"><img loading=\"lazy\" class=\"size-full wp-image-220 aligncenter\" title=\"bash prompt with colors indicating return value of last command\" src=\"https:\/\/joernhees.de\/blog\/wp-content\/uploads\/2010\/08\/bashPromptRetValColor.png\" alt=\"\" width=\"444\" height=\"264\" srcset=\"https:\/\/joernhees.de\/blog\/wp-content\/uploads\/2010\/08\/bashPromptRetValColor.png 444w, https:\/\/joernhees.de\/blog\/wp-content\/uploads\/2010\/08\/bashPromptRetValColor-300x178.png 300w\" sizes=\"(max-width: 444px) 100vw, 444px\" \/><\/a><\/p>\n<p>The code for the user prompt:<\/p>\n<pre><code class=\"bash\">PS1='${debian_chroot:+($debian_chroot)}\\[\\033[01;32m]u@h\\[\\033[00m]:\\[\\033[01;34m]w $(if [[ $? = 0 ]];then echo \"\\[\\033[01;34m]\";else echo \"\\[\\033[01;31m]\";fi)$ \\[\\033[00m]'\n<\/code><\/pre>\n<p>And the root prompt:<\/p>\n<pre><code class=\"bash\">PS1='\\[\\033[01;31m]h\\[\\033[01;34m] W $(if [[ $? = 0 ]];then echo \"\\[\\033[01;34m]\";else echo \"\\[\\033[01;31m]\";fi)$\\[\\033[00m] '\n<\/code><\/pre>\n<p>And a small doc snippet you might want to include with your PS1 in your .bashrc, so you can still understand that cryptic stuff in a few days:<\/p>\n<pre><code class=\"bash\"># h hostname\n# u user\n# w working dir (home == ~)\n# $ a $ if UID == 0 else #\n# A current 24-time: HH:MM\n# \\ a \n# [ begin, ] end of non-printing (control chars)\n#\n# colors: have to be surrounded by: '\\[\\033[' and 'm]' (without the ''. These literally are the left and right bracket!)\n#  color codes are as follows, preceeded by a '0;' (dark) (default) or a '1;' (light)\n#  FG and BG NULL: 00 resets\n#  FG: 30 + ... 0: black, 1: red, 2: green, 3: yellow, 4: blue, 5: violet, 6: cyan, 7: white\n#  BG: 40 + ... same\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Lately I&#8217;ve fiddled a lot with installing virtuoso on some virtual machines and found myself repeatedly asking bash for the return value of the last command echo $?. I remembered this blog post by Gecko quite a while ago and tuned it a bit to my needs. My user prompt now looks like this (it&#8217;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[2],"tags":[12,129,172,183],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pYA5n-3u","jetpack-related-posts":[{"id":360,"url":"https:\/\/joernhees.de\/blog\/2011\/09\/16\/mac-os-x-harddisk-high-load-cycle-counts\/","url_meta":{"origin":216,"position":0},"title":"Mac OS X Harddisk high Load Cycle Counts","date":"2011-09-16","format":false,"excerpt":"Mac OS X's default power management settings might wear your hard drive down unnecessarily. This post provides a lot of background information and how to change these settings.","rel":"","context":"In \"193\"","img":{"alt_text":"","src":"https:\/\/i2.wp.com\/joernhees.de\/blog\/wp-content\/uploads\/2011\/09\/RampLoadUnloadDynamics.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":277,"url":"https:\/\/joernhees.de\/blog\/2010\/10\/31\/setting-up-a-local-dbpedia-mirror-with-virtuoso\/","url_meta":{"origin":216,"position":1},"title":"Setting up a local DBpedia mirror with Virtuoso","date":"2010-10-31","format":false,"excerpt":"So you're the guy who is allowed to setup a local DBpedia mirror for your work group? OK, today is your lucky day and you're in the right place. I hope you'll be able to benefit from my hours of trials and errors ;)","rel":"","context":"In &quot;Coding&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":566,"url":"https:\/\/joernhees.de\/blog\/2014\/02\/25\/scientific-python-on-mac-os-x-10-9-with-homebrew\/","url_meta":{"origin":216,"position":2},"title":"Scientific Python on Mac OS X 10.9+ with homebrew","date":"2014-02-25","format":false,"excerpt":"Scientific python setup guide for Mac OS X 10.9 Mavericks with homebrew","rel":"","context":"In &quot;Coding&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":731,"url":"https:\/\/joernhees.de\/blog\/2015\/11\/23\/setting-up-a-linked-data-mirror-from-rdf-dumps-dbpedia-2015-04-freebase-wikidata-linkedgeodata-with-virtuoso-7-2-1-and-docker-optional\/","url_meta":{"origin":216,"position":3},"title":"Setting up a Linked Data mirror from RDF dumps (DBpedia 2015-04, Freebase, Wikidata, LinkedGeoData, ...) with Virtuoso 7.2.1 and Docker (optional)","date":"2015-11-23","format":false,"excerpt":"So you're the guy who is allowed to setup a local DBpedia mirror or more generally a local Linked Data mirror for your work group? OK, today is your lucky day and you're in the right place. I hope you'll be able to benefit from my many hours of trials\u2026","rel":"","context":"In &quot;Coding&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":81,"url":"https:\/\/joernhees.de\/blog\/2010\/07\/19\/min-heap-in-python\/","url_meta":{"origin":216,"position":4},"title":"Min-Heap in Python","date":"2010-07-19","format":false,"excerpt":"I recently wanted to implement a small event system where events can have different priorities. So for example the event with highest priority (lowest value) should be handled first. Python comes with a heapq module which can transform a list into a heap in a way that it stays a\u2026","rel":"","context":"In &quot;Coding&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":643,"url":"https:\/\/joernhees.de\/blog\/2015\/01\/28\/dbpedia-2014-stats-top-subjects-predicates-and-objects\/","url_meta":{"origin":216,"position":5},"title":"DBpedia 2014 Stats - Top Subjects, Predicates and Objects","date":"2015-01-28","format":false,"excerpt":"Ever wondered what the top subjects \/ predicates \/ objects are in DBpedia? I recently came across this problem while trying to draw a random sample of nodes from DBpedia which follow a given degree distribution for my PhD. Turns out this is actually more difficult than i expected. Mostly\u2026","rel":"","context":"In &quot;Coding&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/posts\/216"}],"collection":[{"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":2,"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":805,"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/posts\/216\/revisions\/805"}],"wp:attachment":[{"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joernhees.de\/blog\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}