Skip to content

Instantly share code, notes, and snippets.

@juandesant
Last active December 18, 2025 20:42
Show Gist options
  • Select an option

  • Save juandesant/ffb074be10035e83c920484d9e39d9b4 to your computer and use it in GitHub Desktop.

Select an option

Save juandesant/ffb074be10035e83c920484d9e39d9b4 to your computer and use it in GitHub Desktop.
Ancillary bash/zsh function to use `ksdiff` (or `diff`, or `opendiff` on the Mac) to compare files
ksdiffstr () {
ksdiff <(echo "$1") <(echo "$2") # Comment or uncomment to use the desired tool
}
diffstr () {
diff <(echo "$1") <(echo "$2") # Comment or uncomment to use the desired tool
}
opendiffstr () {
# Process substitution does not work with opendiff
# Hence, we use `mktemp` to create a couple of temporary files
temp_file_1=$(mktemp -t "$0.txt") || exit 1
echo "$1" > "$temp_file_1"
temp_file_2=$(mktemp -t "$0.txt") || exit 1
echo "$2" > "$temp_file_2"
opendiff "$temp_file_1" "$temp_file_2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment