Coder Social home page Coder Social logo

ildar-shaimordanov / colordiff Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 35 KB

Wrapper for diff to colorize its output for better readability

License: MIT License

Shell 100.00%
diff colordiff shell shell-script shell-scripting colorizer highlight highlighter

colordiff's Introduction

colordiff

colordiff is a pure shell script acting as a wrapper for diff. It supports a lot of diff outputs and makes them looking prettier highlighting similar to git diff.

The script analysizes the command line options, select proper colorizing scheme, invokes diff and applies sed with the selected scheme.

Usage

Use colordiff in the same way as well as diff:

colordiff [diff options] [colordiff options] file1 file2

Run the script with no options to learn how to use it -- not a long help page will be displayed.

The tool can be used as a standalone executable script or a shell function sourced from ~/.bashrc or aliased as follows:

# Let's check and use diff itself or git diff
if diff --help 2>/dev/null | grep -q color
then
	# diff 3.4+ allows coloring
	alias diff='diff --color=auto'
elif which git > /dev/null 2>&1
then
	# git is available
	alias diff='git diff --no-index'
fi

# If one of these scripts exists, overwrite the alias for better colorizing
if which ~/bin/colordiff.posix > /dev/null 2>&1
then
	# Let's check and use POSIX-compliant shell script
	alias diff=~/bin/colordiff.posix
elif which ~/bin/colordiff.bash > /dev/null 2>&1
then
	# Let's check and use full-featured Bash script
	alias diff=~/bin/colordiff.bash
elif which colordiff > /dev/null 2>&1
then
	# Let's check and use well-known script from www.colordiff.org
	alias diff=colordiff
fi

colordiff options

  • --color[=WHEN], --colour[=WHEN] - the colorizing method; WHEN stands for never, auto and always (default value, if not specified explicitly).

Environment

  • CDIFF_WHEN - the colorizing method has impact on all runs.
  • CDIFF_COLORS - the colon-separated list of capabilities to colorize the separate parts of the diff output. Colors are defined in the terms of git-config and defaults to meta=40;1;37:frag=36:old=31:new=32:mod=34 (bold white for metainformation or headers, cyan for hunk headers or line numbers, red for deleted lines, green for added lines and blue for modified lines, respectively).

Requirements

The latest version of the script was developed and successfully tested in the following environment:

  • cygwin 1.45, 3.1.7
  • bash 4.2, 4.4
  • busybox 1.33.0
  • sed 4.2, 4.4

See Also

There is another Perl script with the same functionality. It exists in two versions maintained by its authors:

License

MIT License

colordiff's People

Contributors

ildar-shaimordanov avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.