1 #!/bin/bash
 2 
 3 ###################################################################
 4 # Compare every file in the current working directory
 5 # against the same files in another directory.
 6 # Display any differences that are found.
 7 #
 8 # The variable diffDir contains the path to the other
 9 # directory to compare the current working directory against.
10 #
11 # Use-case: Compare untrusted files downloaded from Arch's AUR
12 # against a set of previously inspected files.  Show any changes
13 # that have been made by the maintainer between versions.
14 ###################################################################
15 # made with <3 by ~inthreedee ( https://tilde.town/~inthreedee/ )
16 ###################################################################
17 
18 # enable bash's globstar for recursive searching
19 shopt -s globstar
20 # ${PWD##*/} returns the current working directory name
21 diffDir="$HOME/builds/prev/${PWD##*/}"
22 diffCmd="emacs -diff"
23 
24 # Sanity checks
25 if [ ! -x "$(command -v $diffCmd)" ]; then
26     echo "Invalid diff command: $diffCmd"
27     echo "Aborting."
28 elif [ ! -d "$diffDir" ]; then
29     echo "Comparison directory not found: $diffDir"
30     echo "Aborting."
31 else
32     # Find files recursively and only show those with differences
33     for item in **; do
34         if [ -f "$item" ] && [ -n "$(diff -q $item $diffDir/$item)" ]; then
35             bash -c "$diffCmd $item $diffDir/$item"
36         fi
37     done
38     echo "Done."
39 fi