Posts

Showing posts from 2014

Bash prompt with colors, and git branch

So, you're working on several machines at the same time, travelling from directories to directories, and using git with multiple branches. And, like me, you can't remember where you are, which git branch you're in, because you have half a dozen or more terminals open on your screen.

Here is a little trick you can do with bash, change the prompt.
First of all, you have to download this nice little script called git-prompt.sh and save it in your home directory as .git-prompt.sh

Then, edit your .bashrc and add the line


source ~/.git-prompt.sh

wherever you want. It can be near the beginning for example. If you don't have .bashrc, search for .bash_profileinstead.

Then search for the definition of the variable PS1 . And replace its line by the following:


export PS1='\h:\[\e[33m\]\W\[\e[0m\]$(__git_ps1 " (%s)")\$ '
If you can't find it, just add the line wherever you want but in any case, after the source command from above.

The variable PS1 defines your …

Boost Spirit and C++ 11

It's a little trick again to know about. This time it's about Boost Spirit and C++ 11. Boost Spirit is a C++ library to generate a parser, writing directly C++ code, unlike other parser generators like yacc, bison or ANTLR which have their own language. It's cool, very templated and produce fast code. And fun to use !
 If you want to compile the examples in the tutorial (like this one: http://www.boost.org/doc/libs/1_55_0/libs/spirit/example/qi/mini_xml3.cpp) with C++ 11, you will have a BIG error message, like hundreds of undecipherable lines of templates instantiation errors that are absolutely impossible to read if you're not a world expert, basically the author of the Spirit library.
First time I tried, I ended up with 100+ Kb of error messages ! I tried with different versions of my GCC compiler and clang++ from the LLVM project without any success.
After googling a lot, I finally found a nice little post describing the simple solution to make it work. At the beg…