Sign in
Archive for the ‘Coding’ Category
Published by: ganglio @ 20:29
29
Nov/10
q2

It’s more than a year now since I started using GIT and I can say that is the best versioning system ever invented.
It’s fast, really fast. And clean. I used SVN at the univ and it was a bloody pain. Merging branches was awful and it easily got messed although it was just two of us working on the same project.
Now we are three from 6 different machines and everything is just a piece of cake.
You pull in the morning. Commit your changes every now and then. And push in the evening.
No fuss no pain.
Just nicely simple.

As I’m a console guy, I came up with a nice configuration for my bash prompt that tells me what’s going on with the project.

I thought it would be nice to share it with you. Here it is:

First add the following functions to your .bash_profile or .bashrc or, if you are a really clean guy, to your .bash_functions

  1. function parse_git_branch_and_add_brackets {
  2.   branch=$(git branch –no-color 2> /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* \(.*\)/\1/’)
  3.   repo=$(git config –get "branch.$branch.remote" 2> /dev/null)
  4.   echo " ["$branch"@"$repo"]" | sed -e ‘/^\ \[@\]/d’
  5. }
  6.  
  7. function parse_git_status {
  8.     status=$(echo `git status -s 2> /dev/null | awk ‘{print $1;}’ | sort | uniq -c | sed -e "s/??/U/g" | sed -E "s/([0-9]*)\ ([A-Z])/\1\2/"`)
  9.     status=$(echo "("$status")" | sed -e "/^()$/d")
  10.    
  11.     ahead=$(git status 2> /dev/null | grep ahead | awk ‘{print $9;}’)
  12.     ahead=$(echo "{"$ahead"}" | sed "/^{}$/d")
  13.    
  14.     echo -e "\033[01;32m"$status"\033[01;0m""\033[01;31m"$ahead"\033[01;0m"
  15. }

Then edit your .bashrc (or .bash_profile depending on your distro) and find the line where the variable PS1 is defined. Once found, change it as follows:

  1. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[1;33m\]$(parse_git_branch_and_add_brackets)\[\033[0m\]$(parse_git_status) \$

If you are on a Mac (and I really hope for you that you are :þ) the line is the following:

  1. PS1=\h:\W \u\[\033[1;33m\]$(parse_git_branch_and_add_brackets)\[\033[0m\]\[$(parse_git_status)\] \$

And that’s it.

Now your prompt should look as the following:

GIT powered BASH prompt

The part between square brackets are the branch and the repo. The part between the round brackets is the status of your working folder at the moment. The part between the curly brackets is how many commits you are ahead of the master branch.
In my case the branch is master and the repo is origin. I have one file added but not yet committed (A), one file untracked (U) and one file modified (M). And I’m one commit ahead of the master.

Useful, isn’t it?

[update]
There was a small bug in the parse_git_status function. I added a sort before the uniq so that it properly groups the changes.
[/update]

Published by: ganglio @ 11:24
01
Jun/10
q9

Amazing HTML5 procedural canvas-drawing example.

Completely written in HTML5 & JS it’s a funny toy to play with and a good showcase of the possibilities offered by the new standard.
Looking forward for a wide implementation (along with CSS3 specs).

Harmony

By Mr. Doob via Digital Tools

Published by: ganglio @ 13:01
18
Nov/09
q1

Quick update on the Word Clock Widget.

Now it uses cufón to render the clock using user selected fonts.

The font I’m using is Circled by Roger White.
From my personal tastes point of view I advise to use monospaced fonts, but it’s just my tastes.

As usual, the code is here.

Published by: ganglio @ 14:42
17
Nov/09
q0

As promised I, finally, got some time to complete the widget.

It is based on my Geektools script and uses jQuery and jQuery Timers for automatic update.

Here the code: Word Clock Widget

Have fun!

Published by: ganglio @ 12:40
17
Nov/09
q0

I Finally found some time to fix a couple of bugs in the Word Clock code.

Here the updated one.

Soon I’ll upload a completed (AJAX based) version of the Word Clock plugin.

Published by: ganglio @ 19:10
11
Oct/09
q0

I just finished my desktop wordclock.
It’s a PHP script for GeekTool

The idea came from an article I read on Boing Boing few days ago. I thought why not implement it on my desktop. Unfortunately I don’t remember the original post. If you have any kind of information about it please let me know.

How it appears on my desktop

How it appears on my desktop

Here there’s the code.

UPDATE I finally discovered that the article the idea is from Lifehacker. This article, for sake of precision.