Add .fluxbox/keys.
[dotfiles-framework.git] / bin / diff.sh
1 #!/bin/bash
2 #
3 # Print diffs for each _FILE, ~/.FILE pair
4 #
5 # There are two modes: removed and standard. In standard mode, we show
6 # the transition .file -> ~/.file, which shows the changes changes we
7 # need to apply to dotfiles to create your current local installation.
8 # In remove mode, we list the .files that do not have local ~/.file
9 # analogs (i.e. dotfiles that need to be removed to create your
10 # current local installation).  The --removed option selects removed
11 # mode.
12
13 if [ -z "${DOTFILES_DIR}" ]; then
14     echo "DOTFILES_DIR is not set.  Bailing out."
15     exit 1
16 fi
17
18 MODE='standard'
19
20 # parse options
21 while [ -n "${1}" ]; do
22     case "${1}" in
23         '--removed')
24             MODE='removed'
25             ;;
26         '--local-patch')
27             MODE='local-patch'
28             ;;
29     esac
30     shift
31 done
32
33 if [ "${MODE}" = 'local-patch' ]; then
34     cd "${DOTFILES_DIR}"
35     mkdir -p local-patch || exit 1
36     echo 'save local patches to local-patch/000-local.patch'
37     ./bin/diff.sh > local-patch/000-local.patch || exit 1
38     echo 'save local removes to local-patch/000-local.remove'
39     ./bin/diff.sh --removed > local-patch/000-local.remove || exit 1
40     exit
41 fi
42
43 cd "${DOTFILES_DIR}/src" || exit 1
44
45 # Show the changes we'd apply on installation
46 #
47 # Parameters:
48 # file - The file we're processing '.foo'
49 function handle_file()
50 {
51     FILE="${1}"
52     if [ "${MODE}" = 'removed' ]; then
53         if [ ! -e ~/"${FILE}" ]; then
54             echo "${FILE}"
55         fi
56     else
57         if [ -f ~/"${FILE}" ]; then
58             diff -u "${FILE}" ~/"${FILE}"
59         fi
60     fi
61 }
62
63 # For each file in this directory.
64 FOUND=0
65 while read FILE; do
66     if [ "${FILE}" = '.' ]; then
67         continue
68     fi
69     FILE="${FILE:2}"  # strip the leading './'
70     handle_file "${FILE}"
71     let "FOUND = FOUND + 1"
72 done < <(find .)
73
74 # If we found no .XXX files, print a warning
75 if [ "${FOUND}" -lt 1 ]; then
76     echo 'WARNING: no source dotfiles were found' >&2
77 fi