[Updates] A cool .bashrc addition to echo which git branch you are on
Andrew Stone
andrew at stone.com
Wed Dec 11 23:20:43 EST 2013
Actually, if you want the working directory echoed too, like this:
~/Desktop/.../MusicPad[master]$
try:
> =======================
function parse_git_branch ()
{
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1]/"
}
export MYPS='$(echo -n "${PWD/#$HOME/~}" | awk -F "/" '"'"'{if (length($0) > 14) { if (NF>4) print $1 "/" $2 "/.../" $(NF-1) "/" $NF; else if (NF>3) print $1 "/" $2 "/.../" $NF; else print $1 "/.../" $NF; } else print $0;}'"'"')'
PS1='$(eval "echo ${MYPS}")$(parse_git_branch)$ '
On Dec 11, 2013, at 6:41 PM, Andrew Stone <andrew at stone.com> wrote:
> Add this to .bashrc to see what git branch you are in:
>
> -bash-3.2[feature/refactor]$
>
> =======================
>
> function parse_git_branch ()
> {
> git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1]/"
> }
>
> if [[ "x$(whoami)" != xroot ]]; then
> PS1='\s-\v$(parse_git_branch)$ '
> fi
>
>
>
> Andrew Stone
> Twitter / @twittelator
> http://www.stone.com
>
> http://j.mp/twtl8rnu
>
> _______________________________________________
> Updates mailing list
> Updates at cocoaconspiracy.com
> http://lists.cocoaconspiracy.com/mailman/listinfo/updates
Andrew Stone
Twitter / @twittelator
http://www.stone.com
http://j.mp/twtl8rnu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cocoaconspiracy.com/pipermail/updates/attachments/20131211/a6f3ddcd/attachment-0001.html>
More information about the Updates
mailing list