#!/usr/bin/env zsh emulate -LR zsh # Wrapper to GNU widff, with colored output. # Written in 2022 by Vincent Lefevre . # Released to the public domain. # Features: # * Default setup, easy to change. # * The wdiff -d option is implied when there are no arguments. # * When there are differences (generally expected in this context), # the exit status 1 is changed to 0 (meaning no errors). # CWDIFF_W: color parameters for delete region (in the -w wdiff option) # CWDIFF_Y: color parameters for insert region (in the -y wdiff option) # # Default: bright white over red/darker-green background, # assuming a 256-color terminal, i.e. # CWDIFF_W='97;41' # CWDIFF_Y='97;48;5;28' # # For a 16-color terminal, the following could be used: # CWDIFF_W='97;41' # CWDIFF_Y='97;42' # # If this is not readable, try back over bright red/green background: # CWDIFF_W='30;101' # CWDIFF_Y='30;102' # # The actual result depends on the terminal and its configuration. # : ${CWDIFF_W:=97;41} : ${CWDIFF_Y:=97;48;5;28} wdiff -n -w $'\033['"${CWDIFF_W}m" -x $'\033[0m' \ -y $'\033['"${CWDIFF_Y}m" -z $'\033[0m' "${@:--d}" return $(( $? == 1 ? 0 : $? )) # $Id: cwdiff 150117 2022-07-13 13:34:00Z vinc17/zira $