Skip to content

Instantly share code, notes, and snippets.

@ceving
Created January 14, 2016 16:01
Show Gist options
  • Save ceving/f0ec2ba3020d77918005 to your computer and use it in GitHub Desktop.
Save ceving/f0ec2ba3020d77918005 to your computer and use it in GitHub Desktop.
Colorize Fossil's diff like Git
export bold=$(echo -e "\e[1m")
export black=$(echo -e "\e[30m")
export red=$(echo -e "\e[31m")
export green=$(echo -e "\e[32m")
export yellow=$(echo -e "\e[33m")
export blue=$(echo -e "\e[34m")
export magenta=$(echo -e "\e[35m")
export cyan=$(echo -e "\e[36m")
export reset=$(echo -e "\e[m")
fossil-diff ()
{
fossil diff "$@" |
sed -e "s/^\(+++\)\(.*\)$/$bold\1\2$reset/" \
-e "s/^\(---\)\(.*\)$/$bold\1\2$reset/" \
-e "s/^\(=======\)\(.*\)$/$bold\1\2$reset/" \
-e "s/^\(Index: \)\(.*\)$/$bold\1\2$reset/" \
-e "s/^\(ADDED\)\(.*\)$/$cyan\1$green\2$reset/" \
-e "s/^\(DELETED\|MISSING\)\(.*\)$/$cyan\1$red\2$reset/" \
-e "s/^\(CHANGED\)\(.*\)$/$cyan\1$bold\2$reset/" \
-e "s/^\(@@\)\(.*\)$/$magenta\1\2$reset/" \
-e "s/^\+\(.*\)$/$bold+$reset$green\1$reset/" \
-e "s/^\-\(.*\)$/$bold-$reset$red\1$reset/" |
less -SR
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment