d10dd1d6f405fa7212384ed6ceb95a2e7d361771
[dotfiles-framework.git] / diff.sh
1 #!/bin/bash
2 #
3 # Print diffs for each _FILE / ~/.FILE pair
4
5
6 # Create the diff between a pair of files
7 #
8 # handleFile( $file, $dotfile )
9 #
10 # Parameters:
11 # file - The file we're processing '_foo'
12 # dotfile - The file it should be linked to in ~/, e.g. '.foo'
13 function handleFile( )
14 {
15     diff -ru $1 $2
16 }
17
18 # See if we can find any _files.
19 found=0
20 for i in _*; do
21     if [ -e $i ]; then
22         found=`expr $found + 1`
23     fi
24 done
25
26 # If we found none then exit
27 if [ "$found" -lt 1 ]; then
28     echo "WARNING: No files matching _* were found"
29     exit
30 fi
31
32 # For each file in this directory.
33 for i in _*; do
34     # Create .dotfile version.
35     dotfile=.${i/_/}
36     
37     if [ ! -e ~/$dotfile ]; then
38         echo "~/$dotfile doesn't exist"
39     else
40         # run the diff
41         handleFile $i ~/$dotfile
42     fi
43 done