{"id":3934,"date":"2018-04-06T15:04:49","date_gmt":"2018-04-06T22:04:49","guid":{"rendered":"https:\/\/upon2020.com\/blog\/?p=3934"},"modified":"2018-04-13T15:02:58","modified_gmt":"2018-04-13T22:02:58","slug":"my-updated-shell-prompt","status":"publish","type":"post","link":"https:\/\/upon2020.com\/blog\/2018\/04\/my-updated-shell-prompt\/","title":{"rendered":"My updated shell prompt"},"content":{"rendered":"<p>Updated and fixed 04\/13: I had been missing escapes, so command scrollback would get screwed for long lines.<\/p>\n<p><a href=\"http:\/\/www.windley.com\/\">Phil Windley<\/a> asked, so here you are: this is the code in my <code>.bashrc<\/code> that causes my shell prompt to have different colors dependending on whether the previous command succeeded or failed. It also shows Git branch info if I&#8217;m in a directory that is version controlled.<\/p>\n<pre>if [ -f ~\/.git-prompt.sh ]; then\r\n    source ~\/.git-prompt.sh\r\n    export PS1='$(if [[ $? == 0 ]]; then echo \"\\[\\e[32m\\]\"; else echo \"\\[\\e[31m\\]\"; fi )\\h [\\W]$(__git_ps1 \"(%s)\") \\u $ \\[\\e[0m\\]'\r\nfi\r\n<\/pre>\n<p>Where <code>.git-prompt.sh<\/code> is the script from <a href=\"https:\/\/github.com\/git\/git\/blob\/master\/contrib\/completion\/git-prompt.sh\">here<\/a>.<\/p>\n<p>Examples, non-git:<\/p>\n<pre><span style=\"color: green;\">host [~] jernst $<\/span> true\r\n<span style=\"color: green;\">host [~] jernst $<\/span> false\r\n<span style=\"color: red;\">host [~] jernst $<\/span> \r\n<\/pre>\n<p>In a git directory:<\/p>\n<pre><span style=\"color: green;\">host [ubos-docs](develop) jernst $<\/span> true\r\n<span style=\"color: green;\">host [ubos-docs](develop) jernst $<\/span> false\r\n<span style=\"color: red;\">host [ubos-docs](develop) jernst $ \r\n<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Updated and fixed 04\/13: I had been missing escapes, so command scrollback would get screwed for long lines. Phil Windley asked, so here you are: this is the code in my .bashrc that causes my shell prompt to have different colors dependending on whether the previous command succeeded or failed. It also shows Git branch&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"webmentions_disabled":false,"footnotes":""},"categories":[66],"tags":[553,555,554],"class_list":["post-3934","post","type-post","status-publish","format-standard","hentry","category-technical","tag-bash","tag-ps1","tag-shell","kind-article"],"kind":false,"_links":{"self":[{"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/posts\/3934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/comments?post=3934"}],"version-history":[{"count":7,"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/posts\/3934\/revisions"}],"predecessor-version":[{"id":3948,"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/posts\/3934\/revisions\/3948"}],"wp:attachment":[{"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/media?parent=3934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/categories?post=3934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/upon2020.com\/blog\/wp-json\/wp\/v2\/tags?post=3934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}