Cosmetics.
[scripts.git] / clean.sh
1 #!/bin/bash
2
3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify  #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation.                         #
7 #                                                                       #
8 # This program is distributed in the hope that it will be useful, but   #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of            #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
11 # General Public License for more details.                              #
12 #                                                                       #
13 # You should have received a copy of the GNU General Public License     #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.  #
15 #                                                                       #
16 # Written by and Copyright (C) Francois Fleuret                         #
17 # Contact <francois@fleuret.org> for comments & bug reports             #
18 #########################################################################
19
20 TRASH=$(mktemp -d /tmp/trash.XXXXXX)
21
22 # "pdf:fig" "pdf:png" "pdf:pgm"
23
24 for i in "nav:tex" "snm:tex" "toc:tex" "blg:tex" \
25          "idx:tex" "ilg:tex" "ind:tex" "lof:tex" "lot:tex" "lou:tex" \
26          "dvi:tex" "log:tex" "aux:tex" "bbl:tex" \
27          "ps:tex" "pdf:tex" "out:tex" "tpt:tex" "brf:tex" "vrb:tex" \
28          "eps:fig" "eps:png" "eps:pgm" \
29          "o:cc" "o:c" ; do
30     PRODUCED=$(echo $i | cut -f 1 -d:)
31     SOURCE=$(echo $i | cut -f 2 -d :)
32     for f in *.$PRODUCED; do
33         ORIGINAL=${f/.$PRODUCED/.$SOURCE}
34         if [ -f "${ORIGINAL}" ]; then
35             if [ "${f}" -nt "${ORIGINAL}" ]; then
36                 echo "Moving file $f to ${TRASH} ($ORIGINAL exists)"
37                 mv $f ${TRASH}
38             else
39                 echo "File $f is older than $ORIGINAL. Keeping both."
40             fi
41         fi
42     done
43 done
44
45 for i in "mozilla.ps" "a.out"; do
46     if [ -f "$i" ]; then
47         echo "move $i to ${TRASH}"
48         mv $i ${TRASH}
49     fi
50 done
51
52 for f in $(find -type f -executable); do
53     if [ -f ${f}.cc ] || [ -f ${f}.c ]; then
54         echo "Moving $f to ${TRASH} (source code exists)"
55         mv $f ${TRASH}
56     fi
57 done