Source code
<span style="color:#323232;">#!/usr/bin/env bash
</span><span style="color:#323232;">
</span><span style="color:#323232;"># diffc - diff commands
</span><span style="color:#323232;"># - allows to call as: diffc 'command one' 'command two'
</span><span style="color:#323232;"># instead of: diff <(command one) <(command two)
</span><span style="color:#323232;"># (Just to save typing a few characters. Lol I'm a lazy programmer)
</span><span style="color:#323232;">function diffc () {
</span><span style="color:#323232;"> if [[ "$#" != "2" ]]; then
</span><span style="color:#323232;"> echo "diffc requires two arguments"
</span><span style="color:#323232;"> return 1
</span><span style="color:#323232;"> fi
</span><span style="color:#323232;">
</span><span style="color:#323232;"> local command=$(printf 'diff <( %s ) <( %s )' "$1" "$2")
</span><span style="color:#323232;"> echo $command
</span><span style="color:#323232;"> eval $command
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;"># diffh - diff history
</span><span style="color:#323232;"># - make a diff of the output of the last two commands in the shell history
</span><span style="color:#323232;">function diffh () {
</span><span style="color:#323232;"> # first one is 2nd to last. second is last
</span><span style="color:#323232;"> # remove preceeding spaces
</span><span style="color:#323232;"> local first=$(fc -ln -2 -2)
</span><span style="color:#323232;"> local second=$(fc -ln -1 -1)
</span><span style="color:#323232;">
</span><span style="color:#323232;"> # print and run diff
</span><span style="color:#323232;"> local command=$(printf 'diff <( %s ) <( %s )' "${first}" "${second}")
</span><span style="color:#323232;"> echo $command
</span><span style="color:#323232;"> eval $command
</span><span style="color:#323232;">
</span><span style="color:#323232;"> local error_code=$?
</span><span style="color:#323232;">
</span><span style="color:#323232;"> # replace this 'diffh' entry in history with the command
</span><span style="color:#323232;"> history -s "$(echo $command)"
</span><span style="color:#323232;">
</span><span style="color:#323232;"> return $error_code
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span>