2014年1月1日 星期三

Showing Git Status In Shell With Emotional Icon

When using the Git version control system, we create a lot of branches. There are already tons of shell profile script to show you which branch you are. I go a step further by showing the git status also. Moreover, I used emotional face icon to represent different states.
For example,
v-.-v is a clean repository.
\_/! means there are changes.
\_/||| means there are staged but not commit changes.
By using these cute emotions, I can quickly know the status of the repo with just a glimpse. The following screenshot shows my terminal with different git status.
Emotional Git status in shell
The following code are the source of the profile bash. The code is also available on Github.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function parse_git_dirty {
    D="$(git status 2> /dev/null | tail -n1 | awk '{ print $1 }' )"
    if [ "$D" = "nothing" ] ; then
        echo -e "v-.-v : "
    elif [ "$D" = "no" ]; then
        echo -e "\_/! : "
    elif [ "$D" = "#" ]; then
        #echo -e "\_/||| \033[0;37m: "
        echo -e "\_/||| : "
    else
        echo "-.-"
    fi 
}
 
function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
}
 
export PS1="\[\033[1;32m\]\t \[\033[1;35m\]\u@\h:\W \$(parse_git_dirty)\$(parse_git_branch)\$ \[\033[0m\]"
The output of any Git repo directory looks like the following.
1
15:20:51 makzan@Mr-Air-Mak:JailBreakers v-.-v : dev_zoom$
To install it in Mac, paste the code in the /.profile file and reopen the terminal to see the changes.

reference : http://42games.net/showing-git-status-in-shell-with-emotional-icon/

沒有留言:

wibiya widget