From b999307e695a201f96fad9f7283341e06ff9f11d Mon Sep 17 00:00:00 2001 From: Arctic Ice Studio Date: Wed, 15 Nov 2017 13:29:33 +0100 Subject: [PATCH] Implement diff-so-fancy script for use without Git "diff-so-fancy" (1) has been designed to work within Git controlled directories. To allow to use it to compare files that are not controlled by Git the "--no-index" (2) option of "git-diff" has been used. The script pipes the output to "less" using the options * "-R, --RAW-CONTROL-CHARS" to only display ANSI "color" escape sequences in "raw" form * "-F, --quit-if-one-screen" to automatically exit if the entire file can be displayed on the first screen. * "-X, --no-init" to disable sending the termcap (de)initialization strings to the terminal to avoid unnecessary operations like clearing the screen. * "-x2, --tabs=2" to use two tab stops. References: * https://github.com/so-fancy/diff-so-fancy/issues/220#issuecomment-282530252 (1) https://github.com/so-fancy/diff-so-fancy (2) https://git-scm.com/docs/git-diff#git-diff-emgitdiffem--no-index--options--ltpathgt823082 GH-61 --- snowblocks/bash/bin/dsf | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 snowblocks/bash/bin/dsf diff --git a/snowblocks/bash/bin/dsf b/snowblocks/bash/bin/dsf new file mode 100755 index 0000000..dedf125 --- /dev/null +++ b/snowblocks/bash/bin/dsf @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copyright (c) 2016-2017 Arctic Ice Studio +# Copyright (c) 2016-2017 Sven Greb + +# Project: igloo +# Repository: https://github.com/arcticicestudio/igloo +# License: MIT + +set -euo pipefail + +# Allows to use "diff-so-fancy" to compare files that are not controlled by Git. +# Under the hood it makes use of "git diff" by using the "no-index" option which allows to compare the given two +# paths/files on the filesystem outside a working tree controlled by Git. +# +# @param $1 the path/files to compare +# @param $2 the path/files to be compared +# @see https://github.com/so-fancy/diff-so-fancy/issues/220#issuecomment-282530252 +dsf() { + if [ "$#" -eq 2 ]; then + git diff --no-index --color "$@" | diff-so-fancy | less -RFXx2 + fi +} + +dsf $@