Move path definitions forward in _bashrc
[dotfiles-framework.git] / diff.sh
1 #!/bin/bash
2 #
3 # Print diffs for each _FILE, ~/.FILE pair
4 #
5 # There are two modes, local and standard. In standard mode, we show the
6 # transition ~/.file -> _file, which shows the changes effected by
7 # `make override`.  In local mode we show the transition _file -> ~/.file,
8 # which shows the changes we need to apply to the .dotfiles to create
9 # your current local installation.  The --local option selects local mode.
10
11 LOCAL="no" # Select diff ordering
12
13 # parse options
14 while [ -n "$1" ]; do
15     case "$1" in
16         "--local")
17         LOCAL="yes"
18         ;;
19     esac
20     shift
21 done
22
23 # Show the changes we'd apply on installation
24 #
25 # handleFile( $file, $dotfile )
26 #
27 # Parameters:
28 # file - The file we're processing '_foo'
29 # dotfile - The file it should be linked to in ~/, e.g. '.foo'
30 function handleFile( )
31 {
32     if [ $LOCAL == "yes" ]; then
33         diff -ru $2 $1
34     else
35         diff -ru $1 $2
36     fi
37 }
38
39 # See if we can find any _files.
40 found=0
41 for i in _*; do
42     if [ -e $i ]; then
43         found=`expr $found + 1`
44     fi
45 done
46
47 # If we found none then exit
48 if [ "$found" -lt 1 ]; then
49     echo "WARNING: No files matching _* were found"
50     exit
51 fi
52
53 # For each file in this directory.
54 for i in _*; do
55     # Create .dotfile version.
56     dotfile=.${i/_/}
57     
58     if [ ! -e ~/$dotfile ]; then
59         echo "~/$dotfile doesn't exist"
60     else
61         # run the diff
62         handleFile $i ~/$dotfile
63     fi
64 done