# YBlog - A more convenient diff
Keywords: diff, git, colors

French ↓ Menu ↓

# A more convenient diff

Diff is a very useful tool. But it is not so easy to read for us, simple mortal.

This is why, when you use `git` it will use a better formatting and colorize it.

Here is the script I use when I want to use human readable `diff` à la git.

    #!/usr/bin/env zsh

    # Load colors helpers
    autoload -U colors && colors

    function colorize_diff {
        while read line; do
        case ${line[0]} in
        +) print -n $fg[green];;
        -) print -n $fg[red];;
        @) # Display in cyan the @@ positions @@
           if [[ ${line[1]} = '@' ]]; then
               line=$(print $line | perl -pe 's#(\@\@[^\@]*\@\@)(.*)$#'$fg[cyan]'$1'$reset_color'$2#')
           fi;;

        esac
            print -- $line
            print -n $reset_color
            done
    }

    diff -u $* | colorize_diff

RSS · Tweet · FB
These social sharing links preserve your privacy
↑ Top ↑
Published on 2011-08-17
Follow @yogsototh
Yann Esposito©
Done with Vim spacemacs & nanoc Hakyll

ADA: `DdzFFzCqrhtAvdkmATx5Fm8NPJViDy85ZBw13p4XcNzVzvQg8e3vWLXq23JQWFxPEXK6Kvhaxxe7oJt4VMYHxpA2vtCFiP8fziohN6Yp`