{"id":846,"date":"2012-08-06T21:51:13","date_gmt":"2012-08-07T05:51:13","guid":{"rendered":"http:\/\/blog.portnumber53.com\/?p=846"},"modified":"2012-08-06T21:51:13","modified_gmt":"2012-08-07T05:51:13","slug":"git-branch-in-mac-osx-bash-prompt","status":"publish","type":"post","link":"https:\/\/blog.portnumber53.com\/index.php\/2012\/08\/06\/git-branch-in-mac-osx-bash-prompt\/","title":{"rendered":"Git branch in Mac OSX bash prompt"},"content":{"rendered":"<p>I tried using the same changes for my linux boxes on my macbook air and they didn&#39;t work, so I googled around and stumbled upon using this instead:<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"padding: 0.4em; overflow: auto; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New', Courier, 'Lucida Console', Monaco, 'DejaVu Sans Mono', 'Nimbus Mono L', 'Bitstream Vera Sans Mono'; color: rgb(0, 0, 0); \"><code style=\"margin: 0px; padding: 0px; \">c_cyan=`tput setaf 6`\nc_red=`tput setaf 1`\nc_green=`tput setaf 2`\nc_sgr0=`tput sgr0`\nparse_git_branch (){\n    if git rev-parse --git-dir &gt;\/dev\/null 2&gt;&amp;1\n    then\n        gitver=$(git branch 2&gt;\/dev\/null| sed -n &#39;\/^\\*\/s\/^\\* \/\/p&#39;)\n    else\n        return 0\n    fi\n    echo -e $gitver\n}\nbranch_color (){\n    if git rev-parse --git-dir &gt;\/dev\/null 2&gt;&amp;1\n    then\n        color=&quot;&quot;\n    if git diff --quiet 2&gt;\/dev\/null &gt;&amp;2 \n    then\n        color=&quot;${c_green}&quot;\n    else\n        color=${c_red}\n    fi\n    else\n        return 0\n    fi\n    echo -ne $color\n}\n\n#Branch First\n#PS1=&#39;[\\[$(branch_color)\\]$(parse_git_branch)\\[${c_sgr0}\\]] \\u@\\[${c_red}\\]\\w\\[${c_sgr0}\\]: &#39;\n#Branch Last\nPS1=&#39; \\u@\\[${c_red}\\]\\w\\[${c_sgr0}\\]: [\\[$(branch_color)\\]$(parse_git_branch)\\[${c_sgr0}\\]] &#39;<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>original:&nbsp;http:\/\/asemanfar.com\/Current-Git-Branch-in-Bash-Prompt<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I tried using the same changes for my linux boxes on my macbook air and they didn&#39;t work, so I googled around and stumbled upon using this instead: &nbsp; &nbsp; c_cyan=`tput setaf 6` c_red=`tput setaf 1` c_green=`tput setaf 2` c_sgr0=`tput sgr0` parse_git_branch (){ if git rev-parse &#8211;git-dir &gt;\/dev\/null 2&gt;&amp;1 then&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/blog.portnumber53.com\/index.php\/2012\/08\/06\/git-branch-in-mac-osx-bash-prompt\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[58,63,159,265],"class_list":["post-846","post","type-post","status-publish","format-standard","hentry","category-git","tag-bash-prompt","tag-branch","tag-git","tag-osx"],"_links":{"self":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/comments?post=846"}],"version-history":[{"count":0,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/846\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/media?parent=846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/categories?post=846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/tags?post=846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}