I have a script which sets useful git settings and aliases, and I want to end by printing the difference between git config --global --list before and after. I'd like to show the diff in the same format as git diff. I can use diff -u to get almost the same thing without colors, but besides making the diff easier to parse, the colors also render the diff visually familiar to git users.
For other bash commands that take files as inputs, I can use variables instead.
diff -u a.txt b.txt
diff -u <(printf "%s\n" "$x") <(printf "%s\n" "$y")
I should then be able to save the git output to variables before and after, and compare the variables: BEFORE=$(git config --global --list) etc. But git diff does not accept variables as inputs:
git diff --no-index a.txt b.txt # ok
git diff --no-index <(printf "%s\n" "$x") <(printf "%s\n" "$y") # error: Could not access '/proc/2219/fd/63'
Why can't I use variables as inputs here? Is there some way to get git diff to do what I want, or some other command with the same diff format?
git diffis ment to show diffs in your git project, but 2 outputs ofgit configisn't ment to be used withgit diff. You could write both to temp files but then they'll still not be part of the working tree and thus willgit diffnot work as expected.diff --color -u <(printf "%s\n" "$x") <(printf "%s\n" "$y")?diff --color -udoes it, thanks! I looked up this diff man page and I figured color wasn't available since ctrl+f didn't show anything about that.git diff --no-indexdoes work on files even if untracked.